1
1
use crate :: session:: { self , DataTypeKind } ;
2
- use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable , ReprOptions } ;
2
+ use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable , ReprOptions , subst :: SubstsRef } ;
3
3
4
4
use syntax:: ast:: { self , Ident , IntTy , UintTy } ;
5
5
use syntax:: attr;
@@ -15,7 +15,6 @@ use std::ops::Bound;
15
15
use crate :: hir;
16
16
use crate :: ich:: StableHashingContext ;
17
17
use crate :: mir:: { GeneratorLayout , GeneratorSavedLocal } ;
18
- use crate :: ty:: GeneratorSubsts ;
19
18
use crate :: ty:: subst:: Subst ;
20
19
use rustc_index:: bit_set:: BitSet ;
21
20
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
@@ -671,7 +670,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
671
670
tcx. intern_layout ( unit)
672
671
}
673
672
674
- ty:: Generator ( def_id, substs, _) => self . generator_layout ( ty, def_id, & substs) ?,
673
+ ty:: Generator ( def_id, substs, _) => self . generator_layout ( ty, def_id, substs) ?,
675
674
676
675
ty:: Closure ( def_id, ref substs) => {
677
676
let tys = substs. as_closure ( ) . upvar_tys ( def_id, tcx) ;
@@ -1406,22 +1405,22 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1406
1405
& self ,
1407
1406
ty : Ty < ' tcx > ,
1408
1407
def_id : hir:: def_id:: DefId ,
1409
- substs : & GeneratorSubsts < ' tcx > ,
1408
+ substs : SubstsRef < ' tcx > ,
1410
1409
) -> Result < & ' tcx LayoutDetails , LayoutError < ' tcx > > {
1411
1410
use SavedLocalEligibility :: * ;
1412
1411
let tcx = self . tcx ;
1413
1412
1414
- let subst_field = |ty : Ty < ' tcx > | { ty. subst ( tcx, substs. substs ) } ;
1413
+ let subst_field = |ty : Ty < ' tcx > | { ty. subst ( tcx, substs) } ;
1415
1414
1416
1415
let info = tcx. generator_layout ( def_id) ;
1417
1416
let ( ineligible_locals, assignments) = self . generator_saved_local_eligibility ( & info) ;
1418
1417
1419
1418
// Build a prefix layout, including "promoting" all ineligible
1420
1419
// locals as part of the prefix. We compute the layout of all of
1421
1420
// these fields at once to get optimal packing.
1422
- let discr_index = substs. prefix_tys ( def_id, tcx) . count ( ) ;
1421
+ let discr_index = substs. as_generator ( ) . prefix_tys ( def_id, tcx) . count ( ) ;
1423
1422
// FIXME(eddyb) set the correct vaidity range for the discriminant.
1424
- let discr_layout = self . layout_of ( substs. discr_ty ( tcx) ) ?;
1423
+ let discr_layout = self . layout_of ( substs. as_generator ( ) . discr_ty ( tcx) ) ?;
1425
1424
let discr = match & discr_layout. abi {
1426
1425
Abi :: Scalar ( s) => s. clone ( ) ,
1427
1426
_ => bug ! ( ) ,
@@ -1430,7 +1429,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1430
1429
. map ( |local| subst_field ( info. field_tys [ local] ) )
1431
1430
. map ( |ty| tcx. mk_maybe_uninit ( ty) )
1432
1431
. map ( |ty| self . layout_of ( ty) ) ;
1433
- let prefix_layouts = substs. prefix_tys ( def_id, tcx)
1432
+ let prefix_layouts = substs. as_generator ( ) . prefix_tys ( def_id, tcx)
1434
1433
. map ( |ty| self . layout_of ( ty) )
1435
1434
. chain ( iter:: once ( Ok ( discr_layout) ) )
1436
1435
. chain ( promoted_layouts)
@@ -2153,15 +2152,15 @@ where
2153
2152
ty:: Generator ( def_id, ref substs, _) => {
2154
2153
match this. variants {
2155
2154
Variants :: Single { index } => {
2156
- substs. state_tys ( def_id, tcx)
2155
+ substs. as_generator ( ) . state_tys ( def_id, tcx)
2157
2156
. nth ( index. as_usize ( ) ) . unwrap ( )
2158
2157
. nth ( i) . unwrap ( )
2159
2158
}
2160
2159
Variants :: Multiple { ref discr, discr_index, .. } => {
2161
2160
if i == discr_index {
2162
2161
return discr_layout ( discr) ;
2163
2162
}
2164
- substs. prefix_tys ( def_id, tcx) . nth ( i) . unwrap ( )
2163
+ substs. as_generator ( ) . prefix_tys ( def_id, tcx) . nth ( i) . unwrap ( )
2165
2164
}
2166
2165
}
2167
2166
}
0 commit comments