Skip to content

Commit 9453d9b

Browse files
committed
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

+2-2
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

+24-36
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-
}

src/librustc/traits/error_reporting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
3131
use ty::error::ExpectedFound;
3232
use ty::fast_reject;
3333
use ty::fold::TypeFolder;
34-
use ty::subst::{Subst, TypeSpace};
34+
use ty::subst::Subst;
3535
use util::nodemap::{FnvHashMap, FnvHashSet};
3636

3737
use std::cmp;
@@ -232,8 +232,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
232232
if let Ok(..) = self.can_equate(&trait_self_ty, &impl_self_ty) {
233233
self_match_impls.push(def_id);
234234

235-
if trait_ref.substs.types.get_slice(TypeSpace)[1..].iter()
236-
.zip(&impl_trait_ref.substs.types.get_slice(TypeSpace)[1..])
235+
if trait_ref.substs.types[1..].iter()
236+
.zip(&impl_trait_ref.substs.types[1..])
237237
.all(|(u,v)| self.fuzzy_match_tys(u, v))
238238
{
239239
fuzzy_match_impls.push(def_id);

src/librustc/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a, 'gcx, 'tcx> DeferredObligation<'tcx> {
142142
// Auto trait obligations on `impl Trait`.
143143
if tcx.trait_has_default_impl(predicate.def_id()) {
144144
let substs = predicate.skip_binder().trait_ref.substs;
145-
if substs.types.as_full_slice().len() == 1 && substs.regions.is_empty() {
145+
if substs.types.len() == 1 && substs.regions.is_empty() {
146146
if let ty::TyAnon(..) = predicate.skip_binder().self_ty().sty {
147147
return true;
148148
}

src/librustc/traits/select.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use super::util;
3636
use hir::def_id::DefId;
3737
use infer;
3838
use infer::{InferCtxt, InferOk, TypeFreshener, TypeOrigin};
39-
use ty::subst::{Subst, Substs, TypeSpace};
39+
use ty::subst::{Subst, Substs};
4040
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
4141
use traits;
4242
use ty::fast_reject;
@@ -1936,7 +1936,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19361936

19371937
// for `PhantomData<T>`, we pass `T`
19381938
ty::TyStruct(def, substs) if def.is_phantom_data() => {
1939-
substs.types.as_full_slice().to_vec()
1939+
substs.types.to_vec()
19401940
}
19411941

19421942
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
@@ -2585,11 +2585,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25852585
} else {
25862586
return Err(Unimplemented);
25872587
};
2588-
let mut ty_params = BitVector::new(substs_a.types.len(TypeSpace));
2588+
let mut ty_params = BitVector::new(substs_a.types.len());
25892589
let mut found = false;
25902590
for ty in field.walk() {
25912591
if let ty::TyParam(p) = ty.sty {
2592-
assert!(p.space == TypeSpace);
25932592
ty_params.insert(p.idx as usize);
25942593
found = true;
25952594
}
@@ -2602,13 +2601,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26022601
// TyError and ensure they do not affect any other fields.
26032602
// This could be checked after type collection for any struct
26042603
// with a potentially unsized trailing field.
2605-
let types = substs_a.types.map_enumerated(|(_, i, ty)| {
2604+
let types = substs_a.types.iter().enumerate().map(|(i, ty)| {
26062605
if ty_params.contains(i) {
26072606
tcx.types.err
26082607
} else {
26092608
ty
26102609
}
2611-
});
2610+
}).collect();
26122611
let substs = Substs::new(tcx, types, substs_a.regions.clone());
26132612
for &ty in fields.split_last().unwrap().1 {
26142613
if ty.subst(tcx, substs).references_error() {
@@ -2622,13 +2621,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26222621

26232622
// Check that the source structure with the target's
26242623
// type parameters is a subtype of the target.
2625-
let types = substs_a.types.map_enumerated(|(_, i, ty)| {
2624+
let types = substs_a.types.iter().enumerate().map(|(i, ty)| {
26262625
if ty_params.contains(i) {
2627-
*substs_b.types.get(TypeSpace, i)
2626+
substs_b.types[i]
26282627
} else {
26292628
ty
26302629
}
2631-
});
2630+
}).collect();
26322631
let substs = Substs::new(tcx, types, substs_a.regions.clone());
26332632
let new_struct = tcx.mk_struct(def, substs);
26342633
let origin = TypeOrigin::Misc(obligation.cause.span);

src/librustc/traits/specialize/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ pub struct OverlapError {
4444
/// When we have selected one impl, but are actually using item definitions from
4545
/// a parent impl providing a default, we need a way to translate between the
4646
/// type parameters of the two impls. Here the `source_impl` is the one we've
47-
/// selected, and `source_substs` is a substitution of its generics (and
48-
/// possibly some relevant `FnSpace` variables as well). And `target_node` is
49-
/// the impl/trait we're actually going to get the definition from. The resulting
50-
/// substitution will map from `target_node`'s generics to `source_impl`'s
51-
/// generics as instantiated by `source_subst`.
47+
/// selected, and `source_substs` is a substitution of its generics.
48+
/// And `target_node` is the impl/trait we're actually going to get the
49+
/// definition from. The resulting substitution will map from `target_node`'s
50+
/// generics to `source_impl`'s generics as instantiated by `source_subst`.
5251
///
5352
/// For example, consider the following scenario:
5453
///

src/librustc/ty/context.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use middle::free_region::FreeRegionMap;
2323
use middle::region::RegionMaps;
2424
use middle::resolve_lifetime;
2525
use middle::stability;
26-
use ty::subst::{self, Substs};
26+
use ty::subst::Substs;
2727
use traits;
2828
use ty::{self, TraitRef, Ty, TypeAndMut};
2929
use ty::{TyS, TypeVariants};
@@ -1346,18 +1346,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13461346
}
13471347

13481348
pub fn mk_param(self,
1349-
space: subst::ParamSpace,
13501349
index: u32,
13511350
name: Name) -> Ty<'tcx> {
1352-
self.mk_ty(TyParam(ParamTy { space: space, idx: index, name: name }))
1351+
self.mk_ty(TyParam(ParamTy { idx: index, name: name }))
13531352
}
13541353

13551354
pub fn mk_self_type(self) -> Ty<'tcx> {
1356-
self.mk_param(subst::TypeSpace, 0, keywords::SelfType.name())
1355+
self.mk_param(0, keywords::SelfType.name())
13571356
}
13581357

13591358
pub fn mk_param_from_def(self, def: &ty::TypeParameterDef) -> Ty<'tcx> {
1360-
self.mk_param(def.space, def.index, def.name)
1359+
self.mk_param(def.index, def.name)
13611360
}
13621361

13631362
pub fn mk_anon(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {

src/librustc/ty/flags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ impl FlagComputation {
208208
}
209209

210210
fn add_substs(&mut self, substs: &Substs) {
211-
self.add_tys(substs.types.as_full_slice());
212-
for &r in substs.regions.as_full_slice() {
211+
self.add_tys(&substs.types);
212+
for &r in &substs.regions {
213213
self.add_region(r);
214214
}
215215
}

0 commit comments

Comments
 (0)