pub fn get_method_sig<'tcx>(
tcx: TyCtxt<'tcx>,
typing_env: TypingEnv<'tcx>,
def_id: RDefId,
method_args: Option<GenericArgsRef<'tcx>>,
) -> PolyFnSig<'tcx>Expand description
The signature of a method impl may be a subtype of the one expected from the trait decl, as in the example below. For correctness, we must be able to map from the method generics declared in the trait to the actual method generics. Because this would require type inference, we instead simply return the declared signature. This will cause issues if it is possible to use such a more-specific implementation with its more-specific type, but we have a few other issues with lifetime-generic function pointers anyway so this is unlikely to cause problems.
ⓘ
trait MyCompare<Other>: Sized {
fn compare(self, other: Other) -> bool;
}
impl<'a> MyCompare<&'a ()> for &'a () {
// This implementation is more general because it works for non-`'a` refs. Note that only
// late-bound vars may differ in this way.
// `<&'a () as MyCompare<&'a ()>>::compare` has type `fn<'b>(&'a (), &'b ()) -> bool`,
// but type `fn(&'a (), &'a ()) -> bool` was expected from the trait declaration.
fn compare<'b>(self, _other: &'b ()) -> bool {
true
}
}