Skip to content

Commit afc0bb9

Browse files
committed
clean up GeneratorSubsts
1 parent ef9fe10 commit afc0bb9

File tree

20 files changed

+58
-71
lines changed

20 files changed

+58
-71
lines changed

src/librustc/ty/sty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
512512
/// variant indices.
513513
#[inline]
514514
pub fn discriminants(
515-
&'tcx self,
515+
self,
516516
def_id: DefId,
517517
tcx: TyCtxt<'tcx>,
518518
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
@@ -524,7 +524,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
524524
/// Calls `f` with a reference to the name of the enumerator for the given
525525
/// variant `v`.
526526
#[inline]
527-
pub fn variant_name(&self, v: VariantIdx) -> Cow<'static, str> {
527+
pub fn variant_name(self, v: VariantIdx) -> Cow<'static, str> {
528528
match v.as_usize() {
529529
Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME),
530530
Self::RETURNED => Cow::from(Self::RETURNED_NAME),
@@ -570,7 +570,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
570570
#[derive(Debug, Copy, Clone)]
571571
pub enum UpvarSubsts<'tcx> {
572572
Closure(SubstsRef<'tcx>),
573-
Generator(GeneratorSubsts<'tcx>),
573+
Generator(SubstsRef<'tcx>),
574574
}
575575

576576
impl<'tcx> UpvarSubsts<'tcx> {
@@ -582,7 +582,7 @@ impl<'tcx> UpvarSubsts<'tcx> {
582582
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
583583
let upvar_kinds = match self {
584584
UpvarSubsts::Closure(substs) => substs.as_closure().split(def_id, tcx).upvar_kinds,
585-
UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds,
585+
UpvarSubsts::Generator(substs) => substs.as_generator().split(def_id, tcx).upvar_kinds,
586586
};
587587
upvar_kinds.iter().map(|t| {
588588
if let GenericArgKind::Type(ty) = t.unpack() {

src/librustc/ty/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
198198
/// Closure substitutions have a particular structure controlled by the
199199
/// compiler that encodes information like the signature and generator kind;
200200
/// see `ty::GeneratorSubsts` struct for more comments.
201-
pub fn as_generator(&'a self) -> GeneratorSubsts<'a> {
201+
pub fn as_generator(&'tcx self) -> GeneratorSubsts<'tcx> {
202202
GeneratorSubsts { substs: self }
203203
}
204204

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc::ty::Instance;
3030
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
3131
use rustc::ty::layout::{self, Align, Integer, IntegerExt, LayoutOf,
3232
PrimitiveExt, Size, TyLayout, VariantIdx};
33-
use rustc::ty::subst::GenericArgKind;
33+
use rustc::ty::subst::{GenericArgKind, SubstsRef};
3434
use rustc::session::config::{self, DebugInfo};
3535
use rustc::util::nodemap::FxHashMap;
3636
use rustc_fs_util::path_to_c_string;
@@ -692,9 +692,10 @@ pub fn type_metadata(
692692
Some(containing_scope)).finalize(cx)
693693
}
694694
ty::Generator(def_id, substs, _) => {
695-
let upvar_tys : Vec<_> = substs.prefix_tys(def_id, cx.tcx).map(|t| {
696-
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t)
697-
}).collect();
695+
let upvar_tys : Vec<_> = substs
696+
.as_generator().prefix_tys(def_id, cx.tcx).map(|t| {
697+
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t)
698+
}).collect();
698699
prepare_enum_metadata(cx,
699700
t,
700701
def_id,
@@ -1338,7 +1339,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13381339
ty::Adt(adt, _) => VariantInfo::Adt(&adt.variants[index]),
13391340
ty::Generator(def_id, substs, _) => {
13401341
let generator_layout = cx.tcx.generator_layout(*def_id);
1341-
VariantInfo::Generator(*substs, generator_layout, index)
1342+
VariantInfo::Generator(substs, generator_layout, index)
13421343
}
13431344
_ => bug!(),
13441345
}
@@ -1611,15 +1612,15 @@ enum EnumDiscriminantInfo<'ll> {
16111612
#[derive(Copy, Clone)]
16121613
enum VariantInfo<'tcx> {
16131614
Adt(&'tcx ty::VariantDef),
1614-
Generator(ty::GeneratorSubsts<'tcx>, &'tcx GeneratorLayout<'tcx>, VariantIdx),
1615+
Generator(SubstsRef<'tcx>, &'tcx GeneratorLayout<'tcx>, VariantIdx),
16151616
}
16161617

16171618
impl<'tcx> VariantInfo<'tcx> {
16181619
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
16191620
match self {
16201621
VariantInfo::Adt(variant) => f(&variant.ident.as_str()),
16211622
VariantInfo::Generator(substs, _, variant_index) =>
1622-
f(&substs.variant_name(*variant_index)),
1623+
f(&substs.as_generator().variant_name(*variant_index)),
16231624
}
16241625
}
16251626

@@ -1763,9 +1764,10 @@ fn prepare_enum_metadata(
17631764
})
17641765
.collect(),
17651766
ty::Generator(_, substs, _) => substs
1767+
.as_generator()
17661768
.variant_range(enum_def_id, cx.tcx)
17671769
.map(|variant_index| {
1768-
let name = SmallCStr::new(&substs.variant_name(variant_index));
1770+
let name = SmallCStr::new(&substs.as_generator().variant_name(variant_index));
17691771
unsafe {
17701772
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
17711773
DIB(cx),

src/librustc_codegen_llvm/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn uncached_llvm_type<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
6565
if let (&ty::Generator(_, substs, _), &layout::Variants::Single { index })
6666
= (&layout.ty.kind, &layout.variants)
6767
{
68-
write!(&mut name, "::{}", substs.variant_name(index)).unwrap();
68+
write!(&mut name, "::{}", substs.as_generator().variant_name(index)).unwrap();
6969
}
7070
Some(name)
7171
}

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
636636
ty::Generator(def_id, substs, _) => (def_id, substs),
637637
_ => bug!("generator layout without generator substs"),
638638
};
639-
let state_tys = gen_substs.state_tys(def_id, tcx);
639+
let state_tys = gen_substs.as_generator().state_tys(def_id, tcx);
640640

641641
generator_layout.variant_fields.iter()
642642
.zip(state_tys)

src/librustc_codegen_utils/symbol_names/legacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
225225
ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
226226
ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
227227
ty::Closure(def_id, substs) |
228-
ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
228+
ty::Generator(def_id, substs, _) => {
229229
self.print_def_path(def_id, substs)
230230
}
231231
_ => self.pretty_print_type(ty),

src/librustc_codegen_utils/symbol_names/v0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
415415
ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
416416
ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
417417
ty::Closure(def_id, substs) |
418-
ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
418+
ty::Generator(def_id, substs, _) => {
419419
self = self.print_def_path(def_id, substs)?;
420420
}
421421
ty::Foreign(def_id) => {

src/librustc_mir/borrow_check/nll/constraint_generation.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::mir::{
1212
SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, UserTypeProjection,
1313
};
1414
use rustc::ty::fold::TypeFoldable;
15-
use rustc::ty::{self, GeneratorSubsts, RegionVid, Ty};
15+
use rustc::ty::{self, RegionVid, Ty};
1616
use rustc::ty::subst::SubstsRef;
1717

1818
pub(super) fn generate_constraints<'cx, 'tcx>(
@@ -91,13 +91,6 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
9191
self.super_ty(ty);
9292
}
9393

94-
/// We sometimes have `generator_substs` within an rvalue, or within a
95-
/// call. Make them live at the location where they appear.
96-
fn visit_generator_substs(&mut self, substs: &GeneratorSubsts<'tcx>, location: Location) {
97-
self.add_regular_live_constraint(*substs, location);
98-
self.super_generator_substs(substs);
99-
}
100-
10194
fn visit_statement(
10295
&mut self,
10396
statement: &Statement<'tcx>,

src/librustc_mir/borrow_check/nll/renumber.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::ty::subst::SubstsRef;
2-
use rustc::ty::{self, GeneratorSubsts, Ty, TypeFoldable};
2+
use rustc::ty::{self, Ty, TypeFoldable};
33
use rustc::mir::{Location, Body, Promoted};
44
use rustc::mir::visit::{MutVisitor, TyContext};
55
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
@@ -82,18 +82,4 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
8282
fn visit_const(&mut self, constant: &mut &'tcx ty::Const<'tcx>, _location: Location) {
8383
*constant = self.renumber_regions(&*constant);
8484
}
85-
86-
fn visit_generator_substs(&mut self,
87-
substs: &mut GeneratorSubsts<'tcx>,
88-
location: Location) {
89-
debug!(
90-
"visit_generator_substs(substs={:?}, location={:?})",
91-
substs,
92-
location,
93-
);
94-
95-
*substs = self.renumber_regions(substs);
96-
97-
debug!("visit_generator_substs: substs={:?}", substs);
98-
}
9985
}

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
759759
PlaceTy { ty, variant_index: Some(variant_index) } => match ty.kind {
760760
ty::Adt(adt_def, substs) => (&adt_def.variants[variant_index], substs),
761761
ty::Generator(def_id, substs, _) => {
762-
let mut variants = substs.state_tys(def_id, tcx);
762+
let mut variants = substs.as_generator().state_tys(def_id, tcx);
763763
let mut variant = match variants.nth(variant_index.into()) {
764764
Some(v) => v,
765765
None => {
766766
bug!("variant_index of generator out of range: {:?}/{:?}",
767767
variant_index,
768-
substs.state_tys(def_id, tcx).count())
768+
substs.as_generator().state_tys(def_id, tcx).count())
769769
}
770770
};
771771
return match variant.nth(field.index()) {
@@ -791,10 +791,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
791791
ty::Generator(def_id, substs, _) => {
792792
// Only prefix fields (upvars and current state) are
793793
// accessible without a variant index.
794-
return match substs.prefix_tys(def_id, tcx).nth(field.index()) {
794+
return match substs.as_generator().prefix_tys(def_id, tcx).nth(field.index()) {
795795
Some(ty) => Ok(ty),
796796
None => Err(FieldAccessError::OutOfRange {
797-
field_count: substs.prefix_tys(def_id, tcx).count(),
797+
field_count: substs.as_generator().prefix_tys(def_id, tcx).count(),
798798
}),
799799
}
800800
}
@@ -1963,10 +1963,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19631963
// It doesn't make sense to look at a field beyond the prefix;
19641964
// these require a variant index, and are not initialized in
19651965
// aggregate rvalues.
1966-
match substs.prefix_tys(def_id, tcx).nth(field_index) {
1966+
match substs.as_generator().prefix_tys(def_id, tcx).nth(field_index) {
19671967
Some(ty) => Ok(ty),
19681968
None => Err(FieldAccessError::OutOfRange {
1969-
field_count: substs.prefix_tys(def_id, tcx).count(),
1969+
field_count: substs.as_generator().prefix_tys(def_id, tcx).count(),
19701970
}),
19711971
}
19721972
}
@@ -2541,7 +2541,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25412541
// these extra requirements are basically like where
25422542
// clauses on the struct.
25432543
AggregateKind::Closure(def_id, substs)
2544-
| AggregateKind::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
2544+
| AggregateKind::Generator(def_id, substs, _) => {
25452545
self.prove_closure_bounds(tcx, *def_id, substs, location)
25462546
}
25472547

0 commit comments

Comments
 (0)