Skip to content

Commit 9453d9b

Browse files
committedAug 17, 2016
rustc: remove ParamSpace from Substs.
1 parent 6f5e455 commit 9453d9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+462
-857
lines changed
 

‎src/librustc/middle/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hir::{self, pat_util, PatKind};
1818
use hir::intravisit::{self, Visitor};
1919

2020
use middle::privacy;
21-
use ty::{self, subst, TyCtxt};
21+
use ty::{self, TyCtxt};
2222
use hir::def::Def;
2323
use hir::def_id::{DefId};
2424
use lint;
@@ -95,7 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9595
Def::AssociatedTy(..) | Def::Method(_) | Def::AssociatedConst(_)
9696
if self.tcx.trait_of_item(def.def_id()).is_some() => {
9797
if let Some(substs) = self.tcx.tables.borrow().item_substs.get(&id) {
98-
match substs.substs.types.get(subst::TypeSpace, 0).sty {
98+
match substs.substs.types[0].sty {
9999
TyEnum(tyid, _) | TyStruct(tyid, _) => {
100100
self.check_def_id(tyid.did)
101101
}

‎src/librustc/middle/resolve_lifetime.rs

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ use session::Session;
2424
use hir::def::{Def, DefMap};
2525
use hir::def_id::DefId;
2626
use middle::region;
27-
use ty::subst;
2827
use ty;
29-
use std::fmt;
3028
use std::mem::replace;
3129
use syntax::ast;
3230
use syntax::parse::token::keywords;
@@ -41,8 +39,7 @@ use hir::intravisit::{self, Visitor, FnKind};
4139
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
4240
pub enum DefRegion {
4341
DefStaticRegion,
44-
DefEarlyBoundRegion(/* space */ subst::ParamSpace,
45-
/* index */ u32,
42+
DefEarlyBoundRegion(/* index */ u32,
4643
/* lifetime decl */ ast::NodeId),
4744
DefLateBoundRegion(ty::DebruijnIndex,
4845
/* lifetime decl */ ast::NodeId),
@@ -90,10 +87,11 @@ struct LifetimeContext<'a, 'tcx: 'a> {
9087
labels_in_fn: Vec<(ast::Name, Span)>,
9188
}
9289

90+
#[derive(PartialEq, Debug)]
9391
enum ScopeChain<'a> {
94-
/// EarlyScope(i, ['a, 'b, ...], s) extends s with early-bound
95-
/// lifetimes, assigning indexes 'a => i, 'b => i+1, ... etc.
96-
EarlyScope(subst::ParamSpace, &'a [hir::LifetimeDef], Scope<'a>),
92+
/// EarlyScope(['a, 'b, ...], s) extends s with early-bound
93+
/// lifetimes.
94+
EarlyScope(&'a [hir::LifetimeDef], Scope<'a>),
9795
/// LateScope(['a, 'b, ...], s) extends s with late-bound
9896
/// lifetimes introduced by the declaration binder_id.
9997
LateScope(&'a [hir::LifetimeDef], Scope<'a>),
@@ -159,8 +157,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for LifetimeContext<'a, 'tcx> {
159157
hir::ItemImpl(_, _, ref generics, _, _, _) => {
160158
// These kinds of items have only early bound lifetime parameters.
161159
let lifetimes = &generics.lifetimes;
162-
let early_scope = EarlyScope(subst::TypeSpace, lifetimes, &ROOT_SCOPE);
163-
this.with(early_scope, |old_scope, this| {
160+
this.with(EarlyScope(lifetimes, &ROOT_SCOPE), |old_scope, this| {
164161
this.check_lifetime_defs(old_scope, lifetimes);
165162
intravisit::walk_item(this, item);
166163
});
@@ -181,11 +178,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for LifetimeContext<'a, 'tcx> {
181178
self.with(RootScope, |_, this| {
182179
match item.node {
183180
hir::ForeignItemFn(ref decl, ref generics) => {
184-
this.visit_early_late(item.id,
185-
subst::FnSpace,
186-
decl,
187-
generics,
188-
|this| {
181+
this.visit_early_late(item.id, decl, generics, |this| {
189182
intravisit::walk_foreign_item(this, item);
190183
})
191184
}
@@ -203,14 +196,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for LifetimeContext<'a, 'tcx> {
203196
b: &'v hir::Block, s: Span, fn_id: ast::NodeId) {
204197
match fk {
205198
FnKind::ItemFn(_, generics, _, _, _, _, _) => {
206-
self.visit_early_late(fn_id, subst::FnSpace, decl, generics, |this| {
199+
self.visit_early_late(fn_id,decl, generics, |this| {
207200
this.add_scope_and_walk_fn(fk, decl, b, s, fn_id)
208201
})
209202
}
210203
FnKind::Method(_, sig, _, _) => {
211204
self.visit_early_late(
212205
fn_id,
213-
subst::FnSpace,
214206
decl,
215207
&sig.generics,
216208
|this| this.add_scope_and_walk_fn(fk, decl, b, s, fn_id));
@@ -263,7 +255,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for LifetimeContext<'a, 'tcx> {
263255

264256
if let hir::MethodTraitItem(ref sig, None) = trait_item.node {
265257
self.visit_early_late(
266-
trait_item.id, subst::FnSpace,
258+
trait_item.id,
267259
&sig.decl, &sig.generics,
268260
|this| intravisit::walk_trait_item(this, trait_item))
269261
} else {
@@ -469,7 +461,7 @@ fn extract_labels(ctxt: &mut LifetimeContext, b: &hir::Block) {
469461
FnScope { s, .. } => { scope = s; }
470462
RootScope => { return; }
471463

472-
EarlyScope(_, lifetimes, s) |
464+
EarlyScope(lifetimes, s) |
473465
LateScope(lifetimes, s) => {
474466
for lifetime_def in lifetimes {
475467
// FIXME (#24278): non-hygienic comparison
@@ -557,7 +549,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
557549
/// ordering is not important there.
558550
fn visit_early_late<F>(&mut self,
559551
fn_id: ast::NodeId,
560-
early_space: subst::ParamSpace,
561552
decl: &hir::FnDecl,
562553
generics: &hir::Generics,
563554
walk: F) where
@@ -576,7 +567,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
576567
.partition(|l| self.map.late_bound.contains_key(&l.lifetime.id));
577568

578569
let this = self;
579-
this.with(EarlyScope(early_space, &early, this.scope), move |old_scope, this| {
570+
this.with(EarlyScope(&early, this.scope), move |old_scope, this| {
580571
this.with(LateScope(&late, this.scope), move |_, this| {
581572
this.check_lifetime_defs(old_scope, &generics.lifetimes);
582573
walk(this);
@@ -606,11 +597,19 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
606597
break;
607598
}
608599

609-
EarlyScope(space, lifetimes, s) => {
600+
EarlyScope(lifetimes, s) => {
610601
match search_lifetimes(lifetimes, lifetime_ref) {
611-
Some((index, lifetime_def)) => {
602+
Some((mut index, lifetime_def)) => {
603+
// Adjust for nested early scopes, e.g. in methods.
604+
let mut parent = s;
605+
while let EarlyScope(lifetimes, s) = *parent {
606+
index += lifetimes.len() as u32;
607+
parent = s;
608+
}
609+
assert_eq!(*parent, RootScope);
610+
612611
let decl_id = lifetime_def.id;
613-
let def = DefEarlyBoundRegion(space, index, decl_id);
612+
let def = DefEarlyBoundRegion(index, decl_id);
614613
self.insert_lifetime(lifetime_ref, def);
615614
return;
616615
}
@@ -672,7 +671,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
672671
break;
673672
}
674673

675-
EarlyScope(_, lifetimes, s) |
674+
EarlyScope(lifetimes, s) |
676675
LateScope(lifetimes, s) => {
677676
search_result = search_lifetimes(lifetimes, lifetime_ref);
678677
if search_result.is_some() {
@@ -768,7 +767,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
768767
return;
769768
}
770769

771-
EarlyScope(_, lifetimes, s) |
770+
EarlyScope(lifetimes, s) |
772771
LateScope(lifetimes, s) => {
773772
if let Some((_, lifetime_def)) = search_lifetimes(lifetimes, lifetime) {
774773
signal_shadowing_problem(
@@ -963,14 +962,3 @@ fn insert_late_bound_lifetimes(map: &mut NamedRegionMap,
963962
}
964963
}
965964
}
966-
967-
impl<'a> fmt::Debug for ScopeChain<'a> {
968-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
969-
match *self {
970-
EarlyScope(space, defs, _) => write!(fmt, "EarlyScope({:?}, {:?})", space, defs),
971-
LateScope(defs, _) => write!(fmt, "LateScope({:?})", defs),
972-
FnScope { fn_id, body_id, s: _ } => write!(fmt, "FnScope({:?}, {:?})", fn_id, body_id),
973-
RootScope => write!(fmt, "RootScope"),
974-
}
975-
}
976-
}

0 commit comments

Comments
 (0)
Please sign in to comment.