@@ -855,7 +855,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
855855 "assemble_candidates_from_object_ty" ,
856856 ) ;
857857
858- if !self . tcx ( ) . trait_def ( obligation. predicate . def_id ( ) ) . implement_via_object {
858+ let tcx = self . tcx ( ) ;
859+ if !tcx. trait_def ( obligation. predicate . def_id ( ) ) . implement_via_object {
859860 return ;
860861 }
861862
@@ -876,9 +877,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
876877
877878 if let Some ( principal) = data. principal ( ) {
878879 if !self . infcx . tcx . features ( ) . dyn_compatible_for_dispatch ( ) {
879- principal. with_self_ty ( self . tcx ( ) , self_ty)
880- } else if self . tcx ( ) . is_dyn_compatible ( principal. def_id ( ) ) {
881- principal. with_self_ty ( self . tcx ( ) , self_ty)
880+ principal. with_self_ty ( tcx, self_ty)
881+ } else if tcx. is_dyn_compatible ( principal. def_id ( ) ) {
882+ principal. with_self_ty ( tcx, self_ty)
882883 } else {
883884 return ;
884885 }
@@ -902,7 +903,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
902903 // correct trait, but also the correct type parameters.
903904 // For example, we may be trying to upcast `Foo` to `Bar<i32>`,
904905 // but `Foo` is declared as `trait Foo: Bar<u32>`.
905- let candidate_supertraits = util:: supertraits ( self . tcx ( ) , principal_trait_ref)
906+ let candidate_supertraits = util:: supertraits ( tcx, principal_trait_ref)
906907 . enumerate ( )
907908 . filter ( |& ( _, upcast_trait_ref) | {
908909 self . infcx . probe ( |_| {
@@ -914,6 +915,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
914915 . is_ok ( )
915916 } )
916917 } )
918+ . filter ( |( _, trait_ref) | {
919+ !tcx. trait_has_impl_which_may_shadow_dyn ( trait_ref. def_id ( ) )
920+ } )
917921 . map ( |( idx, _) | ObjectCandidate ( idx) ) ;
918922
919923 candidates. vec . extend ( candidate_supertraits) ;
0 commit comments