Skip to content

Commit c1cfd58

Browse files
committed
rustc: remove SelfSpace from ParamSpace.
1 parent 4158673 commit c1cfd58

Some content is hidden

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

41 files changed

+276
-357
lines changed

src/librustc/hir/def.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12-
use ty::subst::ParamSpace;
1312
use util::nodemap::NodeMap;
1413
use syntax::ast;
1514
use hir;
@@ -31,7 +30,7 @@ pub enum Def {
3130
AssociatedTy(DefId /* trait */, DefId),
3231
Trait(DefId),
3332
PrimTy(hir::PrimTy),
34-
TyParam(ParamSpace, u32, DefId, ast::Name),
33+
TyParam(DefId),
3534
Upvar(DefId, // def id of closed over local
3635
ast::NodeId, // node id of closed over local
3736
usize, // index in the freevars list of the closure
@@ -122,7 +121,7 @@ impl Def {
122121
match *self {
123122
Def::Fn(id) | Def::Mod(id) | Def::ForeignMod(id) | Def::Static(id, _) |
124123
Def::Variant(_, id) | Def::Enum(id) | Def::TyAlias(id) | Def::AssociatedTy(_, id) |
125-
Def::TyParam(_, _, id, _) | Def::Struct(id) | Def::Trait(id) |
124+
Def::TyParam(id) | Def::Struct(id) | Def::Trait(id) |
126125
Def::Method(id) | Def::Const(id) | Def::AssociatedConst(id) |
127126
Def::Local(id, _) | Def::Upvar(id, _, _, _) => {
128127
id

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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::SelfSpace, 0).sty {
98+
match substs.substs.types.get(subst::TypeSpace, 0).sty {
9999
TyEnum(tyid, _) | TyStruct(tyid, _) => {
100100
self.check_def_id(tyid.did)
101101
}

src/librustc/traits/coherence.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use super::{SelectionContext, Obligation, ObligationCause};
1414

1515
use middle::cstore::LOCAL_CRATE;
1616
use hir::def_id::DefId;
17-
use ty::subst::TypeSpace;
1817
use ty::{self, Ty, TyCtxt};
1918
use infer::{InferCtxt, TypeOrigin};
2019
use syntax_pos::DUMMY_SP;
@@ -160,12 +159,9 @@ fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt,
160159

161160
// First, create an ordered iterator over all the type parameters to the trait, with the self
162161
// type appearing first.
163-
let input_tys = Some(trait_ref.self_ty());
164-
let input_tys = input_tys.iter().chain(trait_ref.substs.types.get_slice(TypeSpace));
165-
166162
// Find the first input type that either references a type parameter OR
167163
// some local type.
168-
for input_ty in input_tys {
164+
for input_ty in trait_ref.input_types() {
169165
if ty_is_local(tcx, input_ty, infer_is_local) {
170166
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);
171167

src/librustc/traits/error_reporting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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).iter()
236-
.zip(impl_trait_ref.substs.types.get_slice(TypeSpace))
235+
if trait_ref.substs.types.get_slice(TypeSpace)[1..].iter()
236+
.zip(&impl_trait_ref.substs.types.get_slice(TypeSpace)[1..])
237237
.all(|(u,v)| self.fuzzy_match_tys(u, v))
238238
{
239239
fuzzy_match_impls.push(def_id);

src/librustc/traits/object_safety.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use super::elaborate_predicates;
2121

2222
use hir::def_id::DefId;
23-
use ty::subst::{self, SelfSpace, TypeSpace};
23+
use ty::subst;
2424
use traits;
2525
use ty::{self, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
2626
use std::rc::Rc;
@@ -146,10 +146,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
146146
match predicate {
147147
ty::Predicate::Trait(ref data) => {
148148
// In the case of a trait predicate, we can skip the "self" type.
149-
data.0.trait_ref.substs.types.get_slice(TypeSpace)
150-
.iter()
151-
.cloned()
152-
.any(|t| t.has_self_ty())
149+
data.0.trait_ref.input_types()[1..].iter().any(|t| t.has_self_ty())
153150
}
154151
ty::Predicate::Projection(..) |
155152
ty::Predicate::WellFormed(..) |
@@ -325,7 +322,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
325322
ty.maybe_walk(|ty| {
326323
match ty.sty {
327324
ty::TyParam(ref param_ty) => {
328-
if param_ty.space == SelfSpace {
325+
if param_ty.is_self() {
329326
error = true;
330327
}
331328

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13531353
}
13541354

13551355
pub fn mk_self_type(self) -> Ty<'tcx> {
1356-
self.mk_param(subst::SelfSpace, 0, keywords::SelfType.name())
1356+
self.mk_param(subst::TypeSpace, 0, keywords::SelfType.name())
13571357
}
13581358

13591359
pub fn mk_param_from_def(self, def: &ty::TypeParameterDef) -> Ty<'tcx> {

src/librustc/ty/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12-
use ty::subst;
1312
use infer::type_variable;
1413
use ty::{self, BoundRegion, Region, Ty, TyCtxt};
1514

@@ -258,7 +257,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
258257
ty::TyInfer(ty::FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
259258
ty::TyProjection(_) => "associated type".to_string(),
260259
ty::TyParam(ref p) => {
261-
if p.space == subst::SelfSpace {
260+
if p.is_self() {
262261
"Self".to_string()
263262
} else {
264263
"type parameter".to_string()

src/librustc/ty/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use ty::subst::{self, Substs};
11+
use ty::subst::Substs;
1212
use ty::{self, Ty, TypeFlags, TypeFoldable};
1313

1414
pub struct FlagComputation {
@@ -77,7 +77,7 @@ impl FlagComputation {
7777

7878
&ty::TyParam(ref p) => {
7979
self.add_flags(TypeFlags::HAS_LOCAL_NAMES);
80-
if p.space == subst::SelfSpace {
80+
if p.is_self() {
8181
self.add_flags(TypeFlags::HAS_SELF);
8282
} else {
8383
self.add_flags(TypeFlags::HAS_PARAMS);

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ impl<'tcx> TraitRef<'tcx> {
12251225
}
12261226

12271227
pub fn self_ty(&self) -> Ty<'tcx> {
1228-
*self.substs.types.get(subst::SelfSpace, 0)
1228+
*self.substs.types.get(subst::TypeSpace, 0)
12291229
}
12301230

12311231
pub fn input_types(&self) -> &[Ty<'tcx>] {

src/librustc/ty/sty.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub struct TraitObject<'tcx> {
305305
///
306306
/// This would be represented by a trait-reference where the def-id is the
307307
/// def-id for the trait `Foo` and the substs defines `T` as parameter 0 in the
308-
/// `SelfSpace` and `U` as parameter 0 in the `TypeSpace`.
308+
/// `TypeSpace` and `U` as parameter 1 in the `TypeSpace`.
309309
///
310310
/// Trait references also appear in object types like `Foo<U>`, but in
311311
/// that case the `Self` parameter is absent from the substitutions.
@@ -512,7 +512,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
512512
}
513513

514514
pub fn for_self() -> ParamTy {
515-
ParamTy::new(subst::SelfSpace, 0, keywords::SelfType.name())
515+
ParamTy::new(subst::TypeSpace, 0, keywords::SelfType.name())
516516
}
517517

518518
pub fn for_def(def: &ty::TypeParameterDef) -> ParamTy {
@@ -524,7 +524,13 @@ impl<'a, 'gcx, 'tcx> ParamTy {
524524
}
525525

526526
pub fn is_self(&self) -> bool {
527-
self.space == subst::SelfSpace && self.idx == 0
527+
if self.name == keywords::SelfType.name() {
528+
assert_eq!(self.space, subst::TypeSpace);
529+
assert_eq!(self.idx, 0);
530+
true
531+
} else {
532+
false
533+
}
528534
}
529535
}
530536

@@ -954,7 +960,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
954960

955961
pub fn is_self(&self) -> bool {
956962
match self.sty {
957-
TyParam(ref p) => p.space == subst::SelfSpace,
963+
TyParam(ref p) => p.is_self(),
958964
_ => false
959965
}
960966
}

0 commit comments

Comments
 (0)