Conversation
| let trait_method_substs = ty::List::identity_for_item(tcx, trait_method_def_id); | ||
| let trait_method_substs = | ||
| impl_method_substs.rebase_onto(tcx, trait_def_id, trait_method_substs); | ||
| let call_trait_substs = |
There was a problem hiding this comment.
@zgrannan I think you changed this last? Any chance you remember why if so? I'm not sure if the version using rebase_onto was already introduced in v2 at any point otherwise. V1 uses the version I reverted to.
(The issue was that resolving a trait method call resulted in reporting [Self/#0] as the trait substs instead of [Impl] (the implementor of the trait) as expected.)
There was a problem hiding this comment.
My recollection is that the V1 logic did not do the correct substitution. For example, if we have:
trait Trait<T> {
fn f<U>(self)
}
impl<X,Y> Trait<X> for Impl<X, Y> {
fn f<U>(self){}
}
impl Impl<u8, u32> {
fn baz<U>(self){
self.f()
}
}and we called this method with the def id / substs for the call to self.f() in baz, then we'd have
the identity of Trait::f is [Self, T, U]
the args for the call are [Impl<u8,u32>,u8,u32,U]
the identity of Trait::f is [Self, T, U]
this method would be expected to return the substitution [Impl<u8, u32>, u8, U], corresponding to Self=Impl<u8,u32>, T = u8, U=U
However, with the current logic I think the output would try to instantiate
[Self, T, U] with the substs [Impl<u8,u32>,u8,u32,U]. I'm not sure if that works due to the arity mismatch but even ignoring that the result would I think be [Impl<u8,u32>, u8, u32].
My understanding is that rebase_onto implements what find_trait_method_substs is intended to do: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/type.GenericArgs.html#method.rebase_onto
21e3688 to
a7c4fb4
Compare
For each trait:
For each trait impl:
If using generic encoding:
If monomorphising (which gets us better error tracking):