File tree Expand file tree Collapse file tree 2 files changed +42
-7
lines changed Expand file tree Collapse file tree 2 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -1941,6 +1941,33 @@ fn dyn_trait() {
19411941 "# ,
19421942 900 ,
19431943 ) ;
1944+ check_number (
1945+ r#"
1946+ //- minicore: coerce_unsized, index, slice
1947+ trait A {
1948+ fn x(&self) -> i32;
1949+ }
1950+
1951+ trait B: A {}
1952+
1953+ impl A for i32 {
1954+ fn x(&self) -> i32 {
1955+ 5
1956+ }
1957+ }
1958+
1959+ impl B for i32 {
1960+
1961+ }
1962+
1963+ const fn f(x: &dyn B) -> i32 {
1964+ x.x()
1965+ }
1966+
1967+ const GOAL: i32 = f(&2i32);
1968+ "# ,
1969+ 5 ,
1970+ ) ;
19441971}
19451972
19461973#[ test]
Original file line number Diff line number Diff line change @@ -665,13 +665,21 @@ pub fn is_dyn_method(
665665 } ;
666666 let self_ty = trait_ref. self_type_parameter ( Interner ) ;
667667 if let TyKind :: Dyn ( d) = self_ty. kind ( Interner ) {
668- let is_my_trait_in_bounds =
669- d. bounds . skip_binders ( ) . as_slice ( Interner ) . iter ( ) . any ( |it| match it. skip_binders ( ) {
670- // rustc doesn't accept `impl Foo<2> for dyn Foo<5>`, so if the trait id is equal, no matter
671- // what the generics are, we are sure that the method is come from the vtable.
672- WhereClause :: Implemented ( tr) => tr. trait_id == trait_ref. trait_id ,
673- _ => false ,
674- } ) ;
668+ let is_my_trait_in_bounds = d
669+ . bounds
670+ . skip_binders ( )
671+ . as_slice ( Interner )
672+ . iter ( )
673+ . map ( |it| it. skip_binders ( ) )
674+ . flat_map ( |it| match it {
675+ WhereClause :: Implemented ( tr) => {
676+ all_super_traits ( db. upcast ( ) , from_chalk_trait_id ( tr. trait_id ) )
677+ }
678+ _ => smallvec ! [ ] ,
679+ } )
680+ // rustc doesn't accept `impl Foo<2> for dyn Foo<5>`, so if the trait id is equal, no matter
681+ // what the generics are, we are sure that the method is come from the vtable.
682+ . any ( |x| x == trait_id) ;
675683 if is_my_trait_in_bounds {
676684 return Some ( fn_params) ;
677685 }
You can’t perform that action at this time.
0 commit comments