@@ -665,64 +665,63 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
665
665
666
666
self . infcx . probe ( |_snapshot| {
667
667
let poly_trait_predicate = self . infcx . resolve_vars_if_possible ( obligation. predicate ) ;
668
- let placeholder_trait_predicate =
669
- self . infcx . enter_forall_and_leak_universe ( poly_trait_predicate) ;
670
-
671
- let self_ty = placeholder_trait_predicate. self_ty ( ) ;
672
- let principal_trait_ref = match self_ty. kind ( ) {
673
- ty:: Dynamic ( data, ..) => {
674
- if data. auto_traits ( ) . any ( |did| did == obligation. predicate . def_id ( ) ) {
675
- debug ! (
676
- "assemble_candidates_from_object_ty: matched builtin bound, \
668
+ self . infcx . enter_forall ( poly_trait_predicate, |placeholder_trait_predicate| {
669
+ let self_ty = placeholder_trait_predicate. self_ty ( ) ;
670
+ let principal_trait_ref = match self_ty. kind ( ) {
671
+ ty:: Dynamic ( data, ..) => {
672
+ if data. auto_traits ( ) . any ( |did| did == obligation. predicate . def_id ( ) ) {
673
+ debug ! (
674
+ "assemble_candidates_from_object_ty: matched builtin bound, \
677
675
pushing candidate"
678
- ) ;
679
- candidates. vec . push ( BuiltinObjectCandidate ) ;
680
- return ;
681
- }
676
+ ) ;
677
+ candidates. vec . push ( BuiltinObjectCandidate ) ;
678
+ return ;
679
+ }
682
680
683
- if let Some ( principal) = data. principal ( ) {
684
- if !self . infcx . tcx . features ( ) . object_safe_for_dispatch {
685
- principal. with_self_ty ( self . tcx ( ) , self_ty)
686
- } else if self . tcx ( ) . check_is_object_safe ( principal. def_id ( ) ) {
687
- principal. with_self_ty ( self . tcx ( ) , self_ty)
681
+ if let Some ( principal) = data. principal ( ) {
682
+ if !self . infcx . tcx . features ( ) . object_safe_for_dispatch {
683
+ principal. with_self_ty ( self . tcx ( ) , self_ty)
684
+ } else if self . tcx ( ) . check_is_object_safe ( principal. def_id ( ) ) {
685
+ principal. with_self_ty ( self . tcx ( ) , self_ty)
686
+ } else {
687
+ return ;
688
+ }
688
689
} else {
690
+ // Only auto trait bounds exist.
689
691
return ;
690
692
}
691
- } else {
692
- // Only auto trait bounds exist.
693
+ }
694
+ ty:: Infer ( ty:: TyVar ( _) ) => {
695
+ debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
696
+ candidates. ambiguous = true ; // could wind up being an object type
693
697
return ;
694
698
}
695
- }
696
- ty:: Infer ( ty:: TyVar ( _) ) => {
697
- debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
698
- candidates. ambiguous = true ; // could wind up being an object type
699
- return ;
700
- }
701
- _ => return ,
702
- } ;
703
-
704
- debug ! ( ?principal_trait_ref, "assemble_candidates_from_object_ty" ) ;
705
-
706
- // Count only those upcast versions that match the trait-ref
707
- // we are looking for. Specifically, do not only check for the
708
- // correct trait, but also the correct type parameters.
709
- // For example, we may be trying to upcast `Foo` to `Bar<i32>`,
710
- // but `Foo` is declared as `trait Foo: Bar<u32>`.
711
- let candidate_supertraits = util:: supertraits ( self . tcx ( ) , principal_trait_ref)
712
- . enumerate ( )
713
- . filter ( |& ( _, upcast_trait_ref) | {
714
- self . infcx . probe ( |_| {
715
- self . match_normalize_trait_ref (
716
- obligation,
717
- upcast_trait_ref,
718
- placeholder_trait_predicate. trait_ref ,
719
- )
720
- . is_ok ( )
699
+ _ => return ,
700
+ } ;
701
+
702
+ debug ! ( ?principal_trait_ref, "assemble_candidates_from_object_ty" ) ;
703
+
704
+ // Count only those upcast versions that match the trait-ref
705
+ // we are looking for. Specifically, do not only check for the
706
+ // correct trait, but also the correct type parameters.
707
+ // For example, we may be trying to upcast `Foo` to `Bar<i32>`,
708
+ // but `Foo` is declared as `trait Foo: Bar<u32>`.
709
+ let candidate_supertraits = util:: supertraits ( self . tcx ( ) , principal_trait_ref)
710
+ . enumerate ( )
711
+ . filter ( |& ( _, upcast_trait_ref) | {
712
+ self . infcx . probe ( |_| {
713
+ self . match_normalize_trait_ref (
714
+ obligation,
715
+ upcast_trait_ref,
716
+ placeholder_trait_predicate. trait_ref ,
717
+ )
718
+ . is_ok ( )
719
+ } )
721
720
} )
722
- } )
723
- . map ( |( idx, _) | ObjectCandidate ( idx) ) ;
721
+ . map ( |( idx, _) | ObjectCandidate ( idx) ) ;
724
722
725
- candidates. vec . extend ( candidate_supertraits) ;
723
+ candidates. vec . extend ( candidate_supertraits) ;
724
+ } )
726
725
} )
727
726
}
728
727
0 commit comments