@@ -1276,7 +1276,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12761276
12771277 // FIXME(generic_associated_types): Compare the whole projections
12781278 let data_poly_trait_ref = projection_ty. map_bound ( |proj| proj. trait_ref ( self . tcx ( ) ) ) ;
1279- let obligation_poly_trait_ref = obligation_trait_ref . to_poly_trait_ref ( ) ;
1279+ let obligation_poly_trait_ref = ty :: Binder :: dummy ( * obligation_trait_ref ) ;
12801280 self . infcx
12811281 . at ( & obligation. cause , obligation. param_env )
12821282 . sup ( obligation_poly_trait_ref, data_poly_trait_ref)
@@ -1648,8 +1648,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16481648 /// Bar<i32> where struct Bar<T> { x: T, y: u32 } -> [i32, u32]
16491649 /// Zed<i32> where enum Zed { A(T), B(u32) } -> [i32, u32]
16501650 /// ```
1651- fn constituent_types_for_ty ( & self , t : Ty < ' tcx > ) -> Vec < Ty < ' tcx > > {
1652- match * t. kind ( ) {
1651+ fn constituent_types_for_ty ( & self , t : ty :: Binder < Ty < ' tcx > > ) -> ty :: Binder < Vec < Ty < ' tcx > > > {
1652+ match * t. skip_binder ( ) . kind ( ) {
16531653 ty:: Uint ( _)
16541654 | ty:: Int ( _)
16551655 | ty:: Bool
@@ -1660,7 +1660,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16601660 | ty:: Error ( _)
16611661 | ty:: Infer ( ty:: IntVar ( _) | ty:: FloatVar ( _) )
16621662 | ty:: Never
1663- | ty:: Char => Vec :: new ( ) ,
1663+ | ty:: Char => ty :: Binder :: dummy ( Vec :: new ( ) ) ,
16641664
16651665 ty:: Placeholder ( ..)
16661666 | ty:: Dynamic ( ..)
@@ -1673,44 +1673,44 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16731673 }
16741674
16751675 ty:: RawPtr ( ty:: TypeAndMut { ty : element_ty, .. } ) | ty:: Ref ( _, element_ty, _) => {
1676- vec ! [ element_ty]
1676+ t . rebind ( vec ! [ element_ty] )
16771677 }
16781678
1679- ty:: Array ( element_ty, _) | ty:: Slice ( element_ty) => vec ! [ element_ty] ,
1679+ ty:: Array ( element_ty, _) | ty:: Slice ( element_ty) => t . rebind ( vec ! [ element_ty] ) ,
16801680
16811681 ty:: Tuple ( ref tys) => {
16821682 // (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
1683- tys. iter ( ) . map ( |k| k. expect_ty ( ) ) . collect ( )
1683+ t . rebind ( tys. iter ( ) . map ( |k| k. expect_ty ( ) ) . collect ( ) )
16841684 }
16851685
16861686 ty:: Closure ( _, ref substs) => {
16871687 let ty = self . infcx . shallow_resolve ( substs. as_closure ( ) . tupled_upvars_ty ( ) ) ;
1688- vec ! [ ty]
1688+ t . rebind ( vec ! [ ty] )
16891689 }
16901690
16911691 ty:: Generator ( _, ref substs, _) => {
16921692 let ty = self . infcx . shallow_resolve ( substs. as_generator ( ) . tupled_upvars_ty ( ) ) ;
16931693 let witness = substs. as_generator ( ) . witness ( ) ;
1694- vec ! [ ty] . into_iter ( ) . chain ( iter:: once ( witness) ) . collect ( )
1694+ t . rebind ( vec ! [ ty] . into_iter ( ) . chain ( iter:: once ( witness) ) . collect ( ) )
16951695 }
16961696
16971697 ty:: GeneratorWitness ( types) => {
1698- // This is sound because no regions in the witness can refer to
1699- // the binder outside the witness. So we'll effectivly reuse
1700- // the implicit binder around the witness.
1701- types. skip_binder ( ) . to_vec ( )
1698+ debug_assert ! ( !types. has_escaping_bound_vars( ) ) ;
1699+ types. map_bound ( |types| types. to_vec ( ) )
17021700 }
17031701
17041702 // For `PhantomData<T>`, we pass `T`.
1705- ty:: Adt ( def, substs) if def. is_phantom_data ( ) => substs. types ( ) . collect ( ) ,
1703+ ty:: Adt ( def, substs) if def. is_phantom_data ( ) => t . rebind ( substs. types ( ) . collect ( ) ) ,
17061704
1707- ty:: Adt ( def, substs) => def. all_fields ( ) . map ( |f| f. ty ( self . tcx ( ) , substs) ) . collect ( ) ,
1705+ ty:: Adt ( def, substs) => {
1706+ t. rebind ( def. all_fields ( ) . map ( |f| f. ty ( self . tcx ( ) , substs) ) . collect ( ) )
1707+ }
17081708
17091709 ty:: Opaque ( def_id, substs) => {
17101710 // We can resolve the `impl Trait` to its concrete type,
17111711 // which enforces a DAG between the functions requiring
17121712 // the auto trait bounds in question.
1713- vec ! [ self . tcx( ) . type_of( def_id) . subst( self . tcx( ) , substs) ]
1713+ t . rebind ( vec ! [ self . tcx( ) . type_of( def_id) . subst( self . tcx( ) , substs) ] )
17141714 }
17151715 }
17161716 }
@@ -1738,10 +1738,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17381738 // 3. Re-bind the regions back to `for<'a> &'a i32 : Copy`
17391739
17401740 types
1741+ . as_ref ( )
17411742 . skip_binder ( ) // binder moved -\
17421743 . iter ( )
17431744 . flat_map ( |ty| {
1744- let ty: ty:: Binder < Ty < ' tcx > > = ty :: Binder :: bind ( ty) ; // <----/
1745+ let ty: ty:: Binder < Ty < ' tcx > > = types . rebind ( ty) ; // <----/
17451746
17461747 self . infcx . commit_unconditionally ( |_| {
17471748 let placeholder_ty = self . infcx . replace_bound_vars_with_placeholders ( ty) ;
0 commit comments