Skip to content

Commit fa7a87b

Browse files
committed
generate GeneratorSubsts from SubstsRef
1 parent 2d87bac commit fa7a87b

File tree

12 files changed

+31
-32
lines changed

12 files changed

+31
-32
lines changed

src/librustc/infer/opaque_types/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,12 @@ where
733733
// Skip lifetime parameters of the enclosing item(s)
734734
// Also skip the witness type, because that has no free regions.
735735

736-
for upvar_ty in substs.upvar_tys(def_id, self.tcx) {
736+
for upvar_ty in substs.as_generator().upvar_tys(def_id, self.tcx) {
737737
upvar_ty.visit_with(self);
738738
}
739739

740-
substs.return_ty(def_id, self.tcx).visit_with(self);
741-
substs.yield_ty(def_id, self.tcx).visit_with(self);
740+
substs.as_generator().return_ty(def_id, self.tcx).visit_with(self);
741+
substs.as_generator().yield_ty(def_id, self.tcx).visit_with(self);
742742
}
743743
_ => {
744744
ty.super_visit_with(self);
@@ -902,7 +902,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
902902
ty::Generator(def_id, substs, movability) => {
903903
let generics = self.tcx.generics_of(def_id);
904904
let substs =
905-
self.tcx.mk_substs(substs.substs.iter().enumerate().map(|(index, &kind)| {
905+
self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| {
906906
if index < generics.parent_count {
907907
// Accommodate missing regions in the parent kinds...
908908
self.fold_kind_mapping_missing_regions_to_empty(kind)

src/librustc/mir/tcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'tcx> Rvalue<'tcx> {
197197
let ty = place.ty(local_decls, tcx).ty;
198198
match ty.kind {
199199
ty::Adt(adt_def, _) => adt_def.repr.discr_type().to_ty(tcx),
200-
ty::Generator(_, substs, _) => substs.discr_ty(tcx),
200+
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
201201
_ => {
202202
// This can only be `0`, for now, so `u8` will suffice.
203203
tcx.types.u8

src/librustc/traits/select.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,8 +2761,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27612761
.collect(),
27622762

27632763
ty::Generator(def_id, ref substs, _) => {
2764-
let witness = substs.witness(def_id, self.tcx());
2764+
let witness = substs.as_generator().witness(def_id, self.tcx());
27652765
substs
2766+
.as_generator()
27662767
.upvar_tys(def_id, self.tcx())
27672768
.chain(iter::once(witness))
27682769
.collect()
@@ -3324,8 +3325,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33243325
)?);
33253326

33263327
Ok(VtableGeneratorData {
3327-
generator_def_id: generator_def_id,
3328-
substs: substs.clone(),
3328+
generator_def_id,
3329+
substs,
33293330
nested: obligations,
33303331
})
33313332
}
@@ -3911,9 +3912,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
39113912
&mut self,
39123913
obligation: &TraitObligation<'tcx>,
39133914
closure_def_id: DefId,
3914-
substs: ty::GeneratorSubsts<'tcx>,
3915+
substs: SubstsRef<'tcx>,
39153916
) -> ty::PolyTraitRef<'tcx> {
3916-
let gen_sig = substs.poly_sig(closure_def_id, self.tcx());
3917+
let gen_sig = substs.as_generator().poly_sig(closure_def_id, self.tcx());
39173918

39183919
// (1) Feels icky to skip the binder here, but OTOH we know
39193920
// that the self-type is an generator type and hence is

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,7 @@ impl<'tcx> TyCtxt<'tcx> {
25102510
#[inline]
25112511
pub fn mk_generator(self,
25122512
id: DefId,
2513-
generator_substs: GeneratorSubsts<'tcx>,
2513+
generator_substs: SubstsRef<'tcx>,
25142514
movability: hir::GeneratorMovability)
25152515
-> Ty<'tcx> {
25162516
self.mk_ty(Generator(id, generator_substs, movability))

src/librustc/ty/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl FlagComputation {
9494
&ty::Generator(_, ref substs, _) => {
9595
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
9696
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
97-
self.add_substs(&substs.substs);
97+
self.add_substs(substs);
9898
}
9999

100100
&ty::GeneratorWitness(ref ts) => {

src/librustc/ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> Instance<'tcx> {
7171
))
7272
}
7373
ty::Generator(def_id, substs, _) => {
74-
let sig = substs.poly_sig(def_id, tcx);
74+
let sig = substs.as_generator().poly_sig(def_id, tcx);
7575

7676
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
7777
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);

src/librustc/ty/layout.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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};
33

44
use syntax::ast::{self, Ident, IntTy, UintTy};
55
use syntax::attr;
@@ -15,7 +15,6 @@ use std::ops::Bound;
1515
use crate::hir;
1616
use crate::ich::StableHashingContext;
1717
use crate::mir::{GeneratorLayout, GeneratorSavedLocal};
18-
use crate::ty::GeneratorSubsts;
1918
use crate::ty::subst::Subst;
2019
use rustc_index::bit_set::BitSet;
2120
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -671,7 +670,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
671670
tcx.intern_layout(unit)
672671
}
673672

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)?,
675674

676675
ty::Closure(def_id, ref substs) => {
677676
let tys = substs.as_closure().upvar_tys(def_id, tcx);
@@ -1406,7 +1405,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14061405
&self,
14071406
ty: Ty<'tcx>,
14081407
def_id: hir::def_id::DefId,
1409-
substs: &GeneratorSubsts<'tcx>,
1408+
substs: SubstsRef<'tcx>,
14101409
) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
14111410
use SavedLocalEligibility::*;
14121411
let tcx = self.tcx;
@@ -1419,9 +1418,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14191418
// Build a prefix layout, including "promoting" all ineligible
14201419
// locals as part of the prefix. We compute the layout of all of
14211420
// 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();
14231422
// 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))?;
14251424
let discr = match &discr_layout.abi {
14261425
Abi::Scalar(s) => s.clone(),
14271426
_ => bug!(),
@@ -2153,15 +2152,15 @@ where
21532152
ty::Generator(def_id, ref substs, _) => {
21542153
match this.variants {
21552154
Variants::Single { index } => {
2156-
substs.state_tys(def_id, tcx)
2155+
substs.as_generator().state_tys(def_id, tcx)
21572156
.nth(index.as_usize()).unwrap()
21582157
.nth(i).unwrap()
21592158
}
21602159
Variants::Multiple { ref discr, discr_index, .. } => {
21612160
if i == discr_index {
21622161
return discr_layout(discr);
21632162
}
2164-
substs.prefix_tys(def_id, tcx).nth(i).unwrap()
2163+
substs.as_generator().prefix_tys(def_id, tcx).nth(i).unwrap()
21652164
}
21662165
}
21672166
}

src/librustc/ty/outlives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'tcx> TyCtxt<'tcx> {
6969

7070
ty::Generator(def_id, ref substs, _) => {
7171
// Same as the closure case
72-
for upvar_ty in substs.upvar_tys(def_id, *self) {
72+
for upvar_ty in substs.as_generator().upvar_tys(def_id, *self) {
7373
self.compute_components(upvar_ty, out);
7474
}
7575

src/librustc/ty/print/obsolete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl DefPathBasedNames<'tcx> {
154154
self.push_type_name(sig.output(), output, debug);
155155
}
156156
}
157-
ty::Generator(def_id, GeneratorSubsts { substs }, _)
157+
ty::Generator(def_id, substs, _)
158158
| ty::Closure(def_id, substs) => {
159159
self.push_def_path(def_id, output);
160160
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));

src/librustc/ty/print/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ pub trait PrettyPrinter<'tcx>:
605605
}
606606
ty::Str => p!(write("str")),
607607
ty::Generator(did, substs, movability) => {
608-
let upvar_tys = substs.upvar_tys(did, self.tcx());
609-
let witness = substs.witness(did, self.tcx());
608+
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
609+
let witness = substs.as_generator().witness(did, self.tcx());
610610
if movability == hir::GeneratorMovability::Movable {
611611
p!(write("[generator"));
612612
} else {

src/librustc/ty/sty.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,8 @@ impl<'tcx> TyS<'tcx> {
21092109
pub fn variant_range(&self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
21102110
match self.kind {
21112111
TyKind::Adt(adt, _) => Some(adt.variant_range()),
2112-
TyKind::Generator(def_id, substs, _) => Some(substs.variant_range(def_id, tcx)),
2112+
TyKind::Generator(def_id, substs, _) =>
2113+
Some(substs.assert_generator().variant_range(def_id, tcx)),
21132114
_ => None,
21142115
}
21152116
}
@@ -2126,7 +2127,7 @@ impl<'tcx> TyS<'tcx> {
21262127
match self.kind {
21272128
TyKind::Adt(adt, _) => Some(adt.discriminant_for_variant(tcx, variant_index)),
21282129
TyKind::Generator(def_id, substs, _) =>
2129-
Some(substs.discriminant_for_variant(def_id, tcx, variant_index)),
2130+
Some(substs.as_generator().discriminant_for_variant(def_id, tcx, variant_index)),
21302131
_ => None,
21312132
}
21322133
}
@@ -2149,7 +2150,7 @@ impl<'tcx> TyS<'tcx> {
21492150
out.extend(substs.regions())
21502151
}
21512152
Closure(_, ref substs ) |
2152-
Generator(_, GeneratorSubsts { ref substs }, _) => {
2153+
Generator(_, ref substs, _) => {
21532154
out.extend(substs.regions())
21542155
}
21552156
Projection(ref data) | UnnormalizedProjection(ref data) => {

src/librustc/ty/walk.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
110110
ty::Adt(_, substs) | ty::Opaque(_, substs) => {
111111
stack.extend(substs.types().rev());
112112
}
113-
ty::Closure(_, ref substs) => {
113+
ty::Closure(_, ref substs)
114+
| ty::Generator(_, ref substs, _) => {
114115
stack.extend(substs.types().rev());
115116
}
116-
ty::Generator(_, ref substs, _) => {
117-
stack.extend(substs.substs.types().rev());
118-
}
119117
ty::GeneratorWitness(ts) => {
120118
stack.extend(ts.skip_binder().iter().cloned().rev());
121119
}

0 commit comments

Comments
 (0)