You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#126699 - Bryanskiy:delegation-coercion, r=petrochenkov
Delegation: support coercion for target expression
(solves rust-lang#118212 (comment))
The implementation consist of 3 parts. Firstly, method call is generated instead of fully qualified call in AST->HIR lowering if there were no generic arguments or `Qpath` were provided. These restrictions are imposed due to the loss of information after desugaring. For example in
```rust
trait Trait {
fn foo(&self) {}
}
reuse <u8 as Trait>::foo;
```
We would like to generate such a code:
```rust
fn foo<u8: Trait>(x: &u8) {
x.foo(x)
}
```
however, the signature is inherited during HIR analysis where `u8` was discarded.
Secondly, traits found in the callee path are also added to `trait_map`. This is done to avoid the side effects of converting body into method calls:
```rust
mod inner {
pub trait Trait {
fn foo(&self) {}
}
}
reuse inner::Trait::foo; // Ok, `Trait` is in scope for implicit method call.
```
Finally, applicable candidates are filtered with pre-resolved method during method lookup.
P.S In the future, we would like to avoid restrictions on the callee path by `Self` autoref/autoderef in fully qualified calls, but at the moment it didn't work out.
r? `@petrochenkov`
0 commit comments