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
"lookup is done based on the type each implementation is for"
674
+
similar to method resolution, we look at all impls applicable
675
+
for Type. Where "all impls applicable" is a mess, consider
676
+
the following
677
+
678
+
```rust
679
+
structFoo;
680
+
implFoo {
681
+
fninherent_func() {}
682
+
}
683
+
684
+
traitTrait:Sized {
685
+
fntrait_method() ->Self {
686
+
todo!();
687
+
}
688
+
}
689
+
implTraitforFoo {}
690
+
691
+
fnmain() {
692
+
//<_>::inherent_func(); // ERROR: unable to get the assoc item
693
+
//<_>::trait_method(); // ERROR: chose trait method, unable to infer the self type
694
+
let_:Foo= <_>::trait_method(); // OK
695
+
}
696
+
```
697
+
698
+
- we only consider trait items for <_> but also consider - and prefer - inherent impls if the self type is not an infer var
699
+
- There would be no way to refer to inherent associated items otherwise, we lack a disambiguation syntax in their favor
700
+
701
+
```rust
702
+
structFoo;
703
+
implFoo {
704
+
fnoverlap(x:Foo) {
705
+
println!("inherent");
706
+
}
707
+
}
708
+
709
+
traitTrait:Sized {
710
+
fnoverlap(x:Self) {
711
+
println!("trait");
712
+
}
713
+
}
714
+
implTraitforFoo {}
715
+
716
+
fnmain() {
717
+
<_>::overlap(Foo); // trait
718
+
<Foo>::overlap(Foo); // inherent
719
+
}
720
+
```
721
+
722
+
- as types and traits are in the same namespace, their disambiguation is only relevant for inherent methods of trait objects without dyn i think
723
+
- candidate preference is a mess, the trait candidate for dyn Trait gets treated as an inherent candidate instead of a trait candidate wrt to candidate preference
0 commit comments