Skip to content

Commit 7739f17

Browse files
authored
Rollup merge of #65100 - csmoe:generator, r=nikomatsakis
Replace GeneratorSubsts with SubstsRef Closes #42340 r? @nikomatsakis
2 parents f14d374 + afc0bb9 commit 7739f17

File tree

35 files changed

+110
-126
lines changed

35 files changed

+110
-126
lines changed

src/librustc/infer/opaque_types/mod.rs

Lines changed: 5 additions & 5 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)
@@ -912,7 +912,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
912912
}
913913
}));
914914

915-
self.tcx.mk_generator(def_id, ty::GeneratorSubsts { substs }, movability)
915+
self.tcx.mk_generator(def_id, substs, movability)
916916
}
917917

918918
ty::Param(..) => {

src/librustc/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::ty::layout::VariantIdx;
1515
use crate::ty::print::{FmtPrinter, Printer};
1616
use crate::ty::subst::{Subst, SubstsRef};
1717
use crate::ty::{
18-
self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt,
18+
self, AdtDef, CanonicalUserTypeAnnotations, Region, Ty, TyCtxt,
1919
UserTypeAnnotationIndex,
2020
};
2121

@@ -2189,7 +2189,7 @@ pub enum AggregateKind<'tcx> {
21892189
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
21902190

21912191
Closure(DefId, SubstsRef<'tcx>),
2192-
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
2192+
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
21932193
}
21942194

21952195
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]

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/mir/visit.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ty::subst::SubstsRef;
2-
use crate::ty::{CanonicalUserTypeAnnotation, GeneratorSubsts, Ty};
2+
use crate::ty::{CanonicalUserTypeAnnotation, Ty};
33
use crate::mir::*;
44
use syntax_pos::Span;
55

@@ -230,12 +230,6 @@ macro_rules! make_mir_visitor {
230230
self.super_substs(substs);
231231
}
232232

233-
fn visit_generator_substs(&mut self,
234-
substs: & $($mutability)? GeneratorSubsts<'tcx>,
235-
_: Location) {
236-
self.super_generator_substs(substs);
237-
}
238-
239233
fn visit_local_decl(&mut self,
240234
local: Local,
241235
local_decl: & $($mutability)? LocalDecl<'tcx>) {
@@ -628,7 +622,7 @@ macro_rules! make_mir_visitor {
628622
generator_substs,
629623
_movability,
630624
) => {
631-
self.visit_generator_substs(generator_substs, location);
625+
self.visit_substs(generator_substs, location);
632626
}
633627
}
634628

@@ -846,10 +840,6 @@ macro_rules! make_mir_visitor {
846840
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
847841
}
848842

849-
fn super_generator_substs(&mut self,
850-
_substs: & $($mutability)? GeneratorSubsts<'tcx>) {
851-
}
852-
853843
// Convenience methods
854844

855845
fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {

src/librustc/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ pub struct VtableImplData<'tcx, N> {
610610
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
611611
pub struct VtableGeneratorData<'tcx, N> {
612612
pub generator_def_id: DefId,
613-
pub substs: ty::GeneratorSubsts<'tcx>,
613+
pub substs: SubstsRef<'tcx>,
614614
/// Nested obligations. This can be non-empty if the generator
615615
/// signature contains associated types.
616616
pub nested: Vec<N>

src/librustc/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
12591259
obligation: &ProjectionTyObligation<'tcx>,
12601260
vtable: VtableGeneratorData<'tcx, PredicateObligation<'tcx>>,
12611261
) -> Progress<'tcx> {
1262-
let gen_sig = vtable.substs.poly_sig(vtable.generator_def_id, selcx.tcx());
1262+
let gen_sig = vtable.substs.as_generator().poly_sig(vtable.generator_def_id, selcx.tcx());
12631263
let Normalized {
12641264
value: gen_sig,
12651265
obligations

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::traits;
2929
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
3030
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
3131
use crate::ty::{TyS, TyKind, List};
32-
use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, Region, Const};
32+
use crate::ty::{AdtKind, AdtDef, Region, Const};
3333
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
3434
use crate::ty::RegionKind;
3535
use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid};
@@ -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: 2 additions & 2 deletions
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);
@@ -395,7 +395,7 @@ fn resolve_associated_item<'tcx>(
395395
traits::VtableGenerator(generator_data) => {
396396
Some(Instance {
397397
def: ty::InstanceDef::Item(generator_data.generator_def_id),
398-
substs: generator_data.substs.substs
398+
substs: generator_data.substs
399399
})
400400
}
401401
traits::VtableClosure(closure_data) => {

0 commit comments

Comments
 (0)