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