Auto merge of #15317 - HKalbasi:mir, r=HKalbasi
Lookup super traits in `is_dyn_method`
This commit is contained in:
commit
be82869dd5
@ -1941,6 +1941,33 @@ fn bar(&self) -> i32 { 700 }
|
|||||||
"#,
|
"#,
|
||||||
900,
|
900,
|
||||||
);
|
);
|
||||||
|
check_number(
|
||||||
|
r#"
|
||||||
|
//- minicore: coerce_unsized, index, slice
|
||||||
|
trait A {
|
||||||
|
fn x(&self) -> i32;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait B: A {}
|
||||||
|
|
||||||
|
impl A for i32 {
|
||||||
|
fn x(&self) -> i32 {
|
||||||
|
5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl B for i32 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn f(x: &dyn B) -> i32 {
|
||||||
|
x.x()
|
||||||
|
}
|
||||||
|
|
||||||
|
const GOAL: i32 = f(&2i32);
|
||||||
|
"#,
|
||||||
|
5,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -665,13 +665,21 @@ pub fn is_dyn_method(
|
|||||||
};
|
};
|
||||||
let self_ty = trait_ref.self_type_parameter(Interner);
|
let self_ty = trait_ref.self_type_parameter(Interner);
|
||||||
if let TyKind::Dyn(d) = self_ty.kind(Interner) {
|
if let TyKind::Dyn(d) = self_ty.kind(Interner) {
|
||||||
let is_my_trait_in_bounds =
|
let is_my_trait_in_bounds = d
|
||||||
d.bounds.skip_binders().as_slice(Interner).iter().any(|it| match it.skip_binders() {
|
.bounds
|
||||||
// rustc doesn't accept `impl Foo<2> for dyn Foo<5>`, so if the trait id is equal, no matter
|
.skip_binders()
|
||||||
// what the generics are, we are sure that the method is come from the vtable.
|
.as_slice(Interner)
|
||||||
WhereClause::Implemented(tr) => tr.trait_id == trait_ref.trait_id,
|
.iter()
|
||||||
_ => false,
|
.map(|it| it.skip_binders())
|
||||||
});
|
.flat_map(|it| match it {
|
||||||
|
WhereClause::Implemented(tr) => {
|
||||||
|
all_super_traits(db.upcast(), from_chalk_trait_id(tr.trait_id))
|
||||||
|
}
|
||||||
|
_ => smallvec![],
|
||||||
|
})
|
||||||
|
// rustc doesn't accept `impl Foo<2> for dyn Foo<5>`, so if the trait id is equal, no matter
|
||||||
|
// what the generics are, we are sure that the method is come from the vtable.
|
||||||
|
.any(|x| x == trait_id);
|
||||||
if is_my_trait_in_bounds {
|
if is_my_trait_in_bounds {
|
||||||
return Some(fn_params);
|
return Some(fn_params);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user