@@ -728,64 +728,63 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
728728
729729 self . infcx . probe ( |_snapshot| {
730730 let poly_trait_predicate = self . infcx . resolve_vars_if_possible ( obligation. predicate ) ;
731- let placeholder_trait_predicate =
732- self . infcx . enter_forall_and_leak_universe ( poly_trait_predicate) ;
733-
734- let self_ty = placeholder_trait_predicate. self_ty ( ) ;
735- let principal_trait_ref = match self_ty. kind ( ) {
736- ty:: Dynamic ( data, ..) => {
737- if data. auto_traits ( ) . any ( |did| did == obligation. predicate . def_id ( ) ) {
738- debug ! (
739- "assemble_candidates_from_object_ty: matched builtin bound, \
731+ self . infcx . enter_forall ( poly_trait_predicate, |placeholder_trait_predicate| {
732+ let self_ty = placeholder_trait_predicate. self_ty ( ) ;
733+ let principal_trait_ref = match self_ty. kind ( ) {
734+ ty:: Dynamic ( data, ..) => {
735+ if data. auto_traits ( ) . any ( |did| did == obligation. predicate . def_id ( ) ) {
736+ debug ! (
737+ "assemble_candidates_from_object_ty: matched builtin bound, \
740738 pushing candidate"
741- ) ;
742- candidates. vec . push ( BuiltinObjectCandidate ) ;
743- return ;
744- }
739+ ) ;
740+ candidates. vec . push ( BuiltinObjectCandidate ) ;
741+ return ;
742+ }
745743
746- if let Some ( principal) = data. principal ( ) {
747- if !self . infcx . tcx . features ( ) . object_safe_for_dispatch {
748- principal. with_self_ty ( self . tcx ( ) , self_ty)
749- } else if self . tcx ( ) . check_is_object_safe ( principal. def_id ( ) ) {
750- principal. with_self_ty ( self . tcx ( ) , self_ty)
744+ if let Some ( principal) = data. principal ( ) {
745+ if !self . infcx . tcx . features ( ) . object_safe_for_dispatch {
746+ principal. with_self_ty ( self . tcx ( ) , self_ty)
747+ } else if self . tcx ( ) . check_is_object_safe ( principal. def_id ( ) ) {
748+ principal. with_self_ty ( self . tcx ( ) , self_ty)
749+ } else {
750+ return ;
751+ }
751752 } else {
753+ // Only auto trait bounds exist.
752754 return ;
753755 }
754- } else {
755- // Only auto trait bounds exist.
756+ }
757+ ty:: Infer ( ty:: TyVar ( _) ) => {
758+ debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
759+ candidates. ambiguous = true ; // could wind up being an object type
756760 return ;
757761 }
758- }
759- ty:: Infer ( ty:: TyVar ( _) ) => {
760- debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
761- candidates. ambiguous = true ; // could wind up being an object type
762- return ;
763- }
764- _ => return ,
765- } ;
766-
767- debug ! ( ?principal_trait_ref, "assemble_candidates_from_object_ty" ) ;
768-
769- // Count only those upcast versions that match the trait-ref
770- // we are looking for. Specifically, do not only check for the
771- // correct trait, but also the correct type parameters.
772- // For example, we may be trying to upcast `Foo` to `Bar<i32>`,
773- // but `Foo` is declared as `trait Foo: Bar<u32>`.
774- let candidate_supertraits = util:: supertraits ( self . tcx ( ) , principal_trait_ref)
775- . enumerate ( )
776- . filter ( |& ( _, upcast_trait_ref) | {
777- self . infcx . probe ( |_| {
778- self . match_normalize_trait_ref (
779- obligation,
780- upcast_trait_ref,
781- placeholder_trait_predicate. trait_ref ,
782- )
783- . is_ok ( )
762+ _ => return ,
763+ } ;
764+
765+ debug ! ( ?principal_trait_ref, "assemble_candidates_from_object_ty" ) ;
766+
767+ // Count only those upcast versions that match the trait-ref
768+ // we are looking for. Specifically, do not only check for the
769+ // correct trait, but also the correct type parameters.
770+ // For example, we may be trying to upcast `Foo` to `Bar<i32>`,
771+ // but `Foo` is declared as `trait Foo: Bar<u32>`.
772+ let candidate_supertraits = util:: supertraits ( self . tcx ( ) , principal_trait_ref)
773+ . enumerate ( )
774+ . filter ( |& ( _, upcast_trait_ref) | {
775+ self . infcx . probe ( |_| {
776+ self . match_normalize_trait_ref (
777+ obligation,
778+ upcast_trait_ref,
779+ placeholder_trait_predicate. trait_ref ,
780+ )
781+ . is_ok ( )
782+ } )
784783 } )
785- } )
786- . map ( |( idx, _) | ObjectCandidate ( idx) ) ;
784+ . map ( |( idx, _) | ObjectCandidate ( idx) ) ;
787785
788- candidates. vec . extend ( candidate_supertraits) ;
786+ candidates. vec . extend ( candidate_supertraits) ;
787+ } )
789788 } )
790789 }
791790
0 commit comments