@@ -1276,7 +1276,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1276
1276
1277
1277
// FIXME(generic_associated_types): Compare the whole projections
1278
1278
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 ) ;
1280
1280
self . infcx
1281
1281
. at ( & obligation. cause , obligation. param_env )
1282
1282
. sup ( obligation_poly_trait_ref, data_poly_trait_ref)
@@ -1648,8 +1648,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1648
1648
/// Bar<i32> where struct Bar<T> { x: T, y: u32 } -> [i32, u32]
1649
1649
/// Zed<i32> where enum Zed { A(T), B(u32) } -> [i32, u32]
1650
1650
/// ```
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 ( ) {
1653
1653
ty:: Uint ( _)
1654
1654
| ty:: Int ( _)
1655
1655
| ty:: Bool
@@ -1660,7 +1660,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1660
1660
| ty:: Error ( _)
1661
1661
| ty:: Infer ( ty:: IntVar ( _) | ty:: FloatVar ( _) )
1662
1662
| ty:: Never
1663
- | ty:: Char => Vec :: new ( ) ,
1663
+ | ty:: Char => ty :: Binder :: dummy ( Vec :: new ( ) ) ,
1664
1664
1665
1665
ty:: Placeholder ( ..)
1666
1666
| ty:: Dynamic ( ..)
@@ -1673,44 +1673,44 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1673
1673
}
1674
1674
1675
1675
ty:: RawPtr ( ty:: TypeAndMut { ty : element_ty, .. } ) | ty:: Ref ( _, element_ty, _) => {
1676
- vec ! [ element_ty]
1676
+ t . rebind ( vec ! [ element_ty] )
1677
1677
}
1678
1678
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] ) ,
1680
1680
1681
1681
ty:: Tuple ( ref tys) => {
1682
1682
// (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 ( ) )
1684
1684
}
1685
1685
1686
1686
ty:: Closure ( _, ref substs) => {
1687
1687
let ty = self . infcx . shallow_resolve ( substs. as_closure ( ) . tupled_upvars_ty ( ) ) ;
1688
- vec ! [ ty]
1688
+ t . rebind ( vec ! [ ty] )
1689
1689
}
1690
1690
1691
1691
ty:: Generator ( _, ref substs, _) => {
1692
1692
let ty = self . infcx . shallow_resolve ( substs. as_generator ( ) . tupled_upvars_ty ( ) ) ;
1693
1693
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 ( ) )
1695
1695
}
1696
1696
1697
1697
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 ( ) )
1702
1700
}
1703
1701
1704
1702
// 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 ( ) ) ,
1706
1704
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
+ }
1708
1708
1709
1709
ty:: Opaque ( def_id, substs) => {
1710
1710
// We can resolve the `impl Trait` to its concrete type,
1711
1711
// which enforces a DAG between the functions requiring
1712
1712
// 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) ] )
1714
1714
}
1715
1715
}
1716
1716
}
@@ -1738,10 +1738,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1738
1738
// 3. Re-bind the regions back to `for<'a> &'a i32 : Copy`
1739
1739
1740
1740
types
1741
+ . as_ref ( )
1741
1742
. skip_binder ( ) // binder moved -\
1742
1743
. iter ( )
1743
1744
. flat_map ( |ty| {
1744
- let ty: ty:: Binder < Ty < ' tcx > > = ty :: Binder :: bind ( ty) ; // <----/
1745
+ let ty: ty:: Binder < Ty < ' tcx > > = types . rebind ( ty) ; // <----/
1745
1746
1746
1747
self . infcx . commit_unconditionally ( |_| {
1747
1748
let placeholder_ty = self . infcx . replace_bound_vars_with_placeholders ( ty) ;
0 commit comments