Skip to content

Commit 5222fa5

Browse files
committed
rustc: use accessors for Substs::{types,regions}.
1 parent eaf71f8 commit 5222fa5

Some content is hidden

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

43 files changed

+250
-229
lines changed

src/librustc/middle/dead.rs

+1-1
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[0].sty {
98+
match substs.substs.type_at(0).sty {
9999
TyEnum(tyid, _) | TyStruct(tyid, _) => {
100100
self.check_def_id(tyid.did)
101101
}

src/librustc/traits/error_reporting.rs

+3-4
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[1..].iter()
236-
.zip(&impl_trait_ref.substs.types[1..])
235+
if trait_ref.substs.types().skip(1)
236+
.zip(impl_trait_ref.substs.types().skip(1))
237237
.all(|(u,v)| self.fuzzy_match_tys(u, v))
238238
{
239239
fuzzy_match_impls.push(def_id);
@@ -738,8 +738,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
738738
ty::Predicate::Trait(ref data) => {
739739
let trait_ref = data.to_poly_trait_ref();
740740
let self_ty = trait_ref.self_ty();
741-
let all_types = &trait_ref.substs().types;
742-
if all_types.references_error() {
741+
if predicate.references_error() {
743742
} else {
744743
// Typically, this ambiguity should only happen if
745744
// there are unresolved type inference variables

src/librustc/traits/fulfill.rs

+1-2
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.len() == 1 && substs.regions.is_empty() {
145+
if substs.types().count() == 1 && substs.regions().next().is_none() {
146146
if let ty::TyAnon(..) = predicate.skip_binder().self_ty().sty {
147147
return true;
148148
}
@@ -440,7 +440,6 @@ fn trait_ref_type_vars<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 't
440440
{
441441
t.skip_binder() // ok b/c this check doesn't care about regions
442442
.input_types()
443-
.iter()
444443
.map(|t| selcx.infcx().resolve_type_vars_if_possible(t))
445444
.filter(|t| t.has_infer_types())
446445
.flat_map(|t| t.walk())

src/librustc/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
145145
match predicate {
146146
ty::Predicate::Trait(ref data) => {
147147
// In the case of a trait predicate, we can skip the "self" type.
148-
data.0.trait_ref.input_types()[1..].iter().any(|t| t.has_self_ty())
148+
data.skip_binder().input_types().skip(1).any(|t| t.has_self_ty())
149149
}
150150
ty::Predicate::Projection(..) |
151151
ty::Predicate::WellFormed(..) |

src/librustc/traits/select.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
644644
// This suffices to allow chains like `FnMut` implemented in
645645
// terms of `Fn` etc, but we could probably make this more
646646
// precise still.
647-
let input_types = stack.fresh_trait_ref.0.input_types();
648-
let unbound_input_types = input_types.iter().any(|ty| ty.is_fresh());
647+
let unbound_input_types = stack.fresh_trait_ref.input_types().any(|ty| ty.is_fresh());
649648
if unbound_input_types && self.intercrate {
650649
debug!("evaluate_stack({:?}) --> unbound argument, intercrate --> ambiguous",
651650
stack.fresh_trait_ref);
@@ -1064,9 +1063,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
10641063

10651064
match *candidate {
10661065
Ok(Some(_)) | Err(_) => true,
1067-
Ok(None) => {
1068-
cache_fresh_trait_pred.0.trait_ref.substs.types.has_infer_types()
1069-
}
1066+
Ok(None) => cache_fresh_trait_pred.has_infer_types()
10701067
}
10711068
}
10721069

@@ -1603,7 +1600,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
16031600
return;
16041601
}
16051602
};
1606-
let target = obligation.predicate.skip_binder().input_types()[1];
1603+
let target = obligation.predicate.skip_binder().trait_ref.substs.type_at(1);
16071604

16081605
debug!("assemble_candidates_for_unsizing(source={:?}, target={:?})",
16091606
source, target);
@@ -1936,7 +1933,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19361933

19371934
// for `PhantomData<T>`, we pass `T`
19381935
ty::TyStruct(def, substs) if def.is_phantom_data() => {
1939-
substs.types.to_vec()
1936+
substs.types().cloned().collect()
19401937
}
19411938

19421939
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
@@ -2180,12 +2177,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21802177
match self_ty.sty {
21812178
ty::TyTrait(ref data) => {
21822179
// OK to skip the binder, it is reintroduced below
2183-
let input_types = data.principal.skip_binder().input_types();
2180+
let input_types = data.principal.input_types();
21842181
let assoc_types = data.projection_bounds.iter()
21852182
.map(|pb| pb.skip_binder().ty);
2186-
let all_types: Vec<_> = input_types.iter().cloned()
2187-
.chain(assoc_types)
2188-
.collect();
2183+
let all_types: Vec<_> = input_types.cloned()
2184+
.chain(assoc_types)
2185+
.collect();
21892186

21902187
// reintroduce the two binding levels we skipped, then flatten into one
21912188
let all_types = ty::Binder(ty::Binder(all_types));
@@ -2476,7 +2473,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24762473
// regions here. See the comment there for more details.
24772474
let source = self.infcx.shallow_resolve(
24782475
tcx.no_late_bound_regions(&obligation.self_ty()).unwrap());
2479-
let target = obligation.predicate.skip_binder().input_types()[1];
2476+
let target = obligation.predicate.skip_binder().trait_ref.substs.type_at(1);
24802477
let target = self.infcx.shallow_resolve(target);
24812478

24822479
debug!("confirm_builtin_unsize_candidate(source={:?}, target={:?})",
@@ -2585,7 +2582,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25852582
} else {
25862583
return Err(Unimplemented);
25872584
};
2588-
let mut ty_params = BitVector::new(substs_a.types.len());
2585+
let mut ty_params = BitVector::new(substs_a.types().count());
25892586
let mut found = false;
25902587
for ty in field.walk() {
25912588
if let ty::TyParam(p) = ty.sty {
@@ -2601,14 +2598,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26012598
// TyError and ensure they do not affect any other fields.
26022599
// This could be checked after type collection for any struct
26032600
// with a potentially unsized trailing field.
2604-
let types = substs_a.types.iter().enumerate().map(|(i, ty)| {
2601+
let types = substs_a.types().enumerate().map(|(i, ty)| {
26052602
if ty_params.contains(i) {
26062603
tcx.types.err
26072604
} else {
26082605
ty
26092606
}
26102607
}).collect();
2611-
let substs = Substs::new(tcx, types, substs_a.regions.clone());
2608+
let substs = Substs::new(tcx, types, substs_a.regions().cloned().collect());
26122609
for &ty in fields.split_last().unwrap().1 {
26132610
if ty.subst(tcx, substs).references_error() {
26142611
return Err(Unimplemented);
@@ -2621,14 +2618,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26212618

26222619
// Check that the source structure with the target's
26232620
// type parameters is a subtype of the target.
2624-
let types = substs_a.types.iter().enumerate().map(|(i, ty)| {
2621+
let types = substs_a.types().enumerate().map(|(i, ty)| {
26252622
if ty_params.contains(i) {
2626-
substs_b.types[i]
2623+
substs_b.type_at(i)
26272624
} else {
26282625
ty
26292626
}
26302627
}).collect();
2631-
let substs = Substs::new(tcx, types, substs_a.regions.clone());
2628+
let substs = Substs::new(tcx, types, substs_a.regions().cloned().collect());
26322629
let new_struct = tcx.mk_struct(def, substs);
26332630
let origin = TypeOrigin::Misc(obligation.cause.span);
26342631
let InferOk { obligations, .. } =
@@ -2753,7 +2750,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27532750
// substitution if we find that any of the input types, when
27542751
// simplified, do not match.
27552752

2756-
obligation.predicate.0.input_types().iter()
2753+
obligation.predicate.skip_binder().input_types()
27572754
.zip(impl_trait_ref.input_types())
27582755
.any(|(&obligation_ty, &impl_ty)| {
27592756
let simplified_obligation_ty =

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
11521152
impl_interners!('tcx,
11531153
type_list: mk_type_list(Vec<Ty<'tcx>>, keep_local) -> [Ty<'tcx>],
11541154
substs: mk_substs(Substs<'tcx>, |substs: &Substs| {
1155-
keep_local(&substs.types) || keep_local(&substs.regions)
1155+
substs.types().any(keep_local) || substs.regions().any(keep_local)
11561156
}) -> Substs<'tcx>,
11571157
bare_fn: mk_bare_fn(BareFnTy<'tcx>, |fty: &BareFnTy| {
11581158
keep_local(&fty.sig)

src/librustc/ty/flags.rs

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

210210
fn add_substs(&mut self, substs: &Substs) {
211-
self.add_tys(&substs.types);
212-
for &r in &substs.regions {
211+
for &ty in substs.types() {
212+
self.add_ty(ty);
213+
}
214+
215+
for &r in substs.regions() {
213216
self.add_region(r);
214217
}
215218
}

src/librustc/ty/item_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
264264
match self_ty.sty {
265265
ty::TyStruct(adt_def, substs) |
266266
ty::TyEnum(adt_def, substs) => {
267-
if substs.types.is_empty() { // ignore regions
267+
if substs.types().next().is_none() { // ignore regions
268268
self.push_item_path(buffer, adt_def.did);
269269
} else {
270270
buffer.push(&format!("<{}>", self_ty));

src/librustc/ty/mod.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,6 @@ impl<'tcx> TraitPredicate<'tcx> {
951951
// leads to more recompilation.
952952
let def_ids: Vec<_> =
953953
self.input_types()
954-
.iter()
955954
.flat_map(|t| t.walk())
956955
.filter_map(|t| match t.sty {
957956
ty::TyStruct(adt_def, _) |
@@ -964,8 +963,8 @@ impl<'tcx> TraitPredicate<'tcx> {
964963
DepNode::TraitSelect(self.def_id(), def_ids)
965964
}
966965

967-
pub fn input_types(&self) -> &[Ty<'tcx>] {
968-
&self.trait_ref.substs.types
966+
pub fn input_types(&self) -> slice::Iter<Ty<'tcx>> {
967+
self.trait_ref.input_types()
969968
}
970969

971970
pub fn self_ty(&self) -> Ty<'tcx> {
@@ -1107,7 +1106,7 @@ impl<'tcx> Predicate<'tcx> {
11071106
pub fn walk_tys(&self) -> IntoIter<Ty<'tcx>> {
11081107
let vec: Vec<_> = match *self {
11091108
ty::Predicate::Trait(ref data) => {
1110-
data.0.trait_ref.input_types().to_vec()
1109+
data.skip_binder().input_types().cloned().collect()
11111110
}
11121111
ty::Predicate::Rfc1592(ref data) => {
11131112
return data.walk_tys()
@@ -1123,8 +1122,7 @@ impl<'tcx> Predicate<'tcx> {
11231122
}
11241123
ty::Predicate::Projection(ref data) => {
11251124
let trait_inputs = data.0.projection_ty.trait_ref.input_types();
1126-
trait_inputs.iter()
1127-
.cloned()
1125+
trait_inputs.cloned()
11281126
.chain(Some(data.0.ty))
11291127
.collect()
11301128
}
@@ -1206,15 +1204,15 @@ impl<'tcx> TraitRef<'tcx> {
12061204
}
12071205

12081206
pub fn self_ty(&self) -> Ty<'tcx> {
1209-
self.substs.types[0]
1207+
self.substs.type_at(0)
12101208
}
12111209

1212-
pub fn input_types(&self) -> &[Ty<'tcx>] {
1210+
pub fn input_types(&self) -> slice::Iter<Ty<'tcx>> {
12131211
// Select only the "input types" from a trait-reference. For
12141212
// now this is all the types that appear in the
12151213
// trait-reference, but it should eventually exclude
12161214
// associated types.
1217-
&self.substs.types
1215+
self.substs.types()
12181216
}
12191217
}
12201218

src/librustc/ty/relate.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,12 @@ pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
147147
{
148148
let tcx = relation.tcx();
149149

150-
let types = a_subst.types.iter().enumerate().map(|(i, a_ty)| {
151-
let b_ty = &b_subst.types[i];
150+
let types = a_subst.types().zip(b_subst.types()).enumerate().map(|(i, (a_ty, b_ty))| {
152151
let variance = variances.map_or(ty::Invariant, |v| v.types[i]);
153152
relation.relate_with_variance(variance, a_ty, b_ty)
154153
}).collect::<Result<_, _>>()?;
155154

156-
let regions = a_subst.regions.iter().enumerate().map(|(i, a_r)| {
157-
let b_r = &b_subst.regions[i];
155+
let regions = a_subst.regions().zip(b_subst.regions()).enumerate().map(|(i, (a_r, b_r))| {
158156
let variance = variances.map_or(ty::Invariant, |v| v.regions[i]);
159157
relation.relate_with_variance(variance, a_r, b_r)
160158
}).collect::<Result<_, _>>()?;

src/librustc/ty/structural_impls.rs

-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use infer::type_variable;
12-
use ty::subst::Substs;
1312
use ty::{self, Lift, Ty, TyCtxt};
1413
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1514

@@ -692,22 +691,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Region {
692691
}
693692
}
694693

695-
impl<'tcx> TypeFoldable<'tcx> for &'tcx Substs<'tcx> {
696-
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
697-
let types = self.types.fold_with(folder);
698-
let regions = self.regions.fold_with(folder);
699-
Substs::new(folder.tcx(), types, regions)
700-
}
701-
702-
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
703-
folder.fold_substs(self)
704-
}
705-
706-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
707-
self.types.visit_with(visitor) || self.regions.visit_with(visitor)
708-
}
709-
}
710-
711694
impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
712695
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
713696
ty::ClosureSubsts {

src/librustc/ty/sty.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use util::common::ErrorReported;
1919

2020
use collections::enum_set::{self, EnumSet, CLike};
2121
use std::fmt;
22-
use std::ops;
2322
use std::mem;
23+
use std::ops;
24+
use std::slice;
2425
use syntax::abi;
2526
use syntax::ast::{self, Name};
2627
use syntax::parse::token::keywords;
@@ -335,7 +336,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
335336
self.0.substs
336337
}
337338

338-
pub fn input_types(&self) -> &[Ty<'tcx>] {
339+
pub fn input_types(&self) -> slice::Iter<Ty<'tcx>> {
339340
// FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
340341
self.0.input_types()
341342
}
@@ -360,12 +361,12 @@ pub struct ExistentialTraitRef<'tcx> {
360361
}
361362

362363
impl<'tcx> ExistentialTraitRef<'tcx> {
363-
pub fn input_types(&self) -> &[Ty<'tcx>] {
364+
pub fn input_types(&self) -> slice::Iter<Ty<'tcx>>{
364365
// Select only the "input types" from a trait-reference. For
365366
// now this is all the types that appear in the
366367
// trait-reference, but it should eventually exclude
367368
// associated types.
368-
&self.substs.types
369+
self.substs.types()
369370
}
370371
}
371372

@@ -376,7 +377,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
376377
self.0.def_id
377378
}
378379

379-
pub fn input_types(&self) -> &[Ty<'tcx>] {
380+
pub fn input_types(&self) -> slice::Iter<Ty<'tcx>> {
380381
// FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
381382
self.0.input_types()
382383
}
@@ -1213,19 +1214,19 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
12131214
}
12141215
TyTrait(ref obj) => {
12151216
let mut v = vec![obj.region_bound];
1216-
v.extend_from_slice(&obj.principal.skip_binder().substs.regions);
1217+
v.extend(obj.principal.skip_binder().substs.regions());
12171218
v
12181219
}
12191220
TyEnum(_, substs) |
12201221
TyStruct(_, substs) |
12211222
TyAnon(_, substs) => {
1222-
substs.regions.to_vec()
1223+
substs.regions().cloned().collect()
12231224
}
12241225
TyClosure(_, ref substs) => {
1225-
substs.func_substs.regions.to_vec()
1226+
substs.func_substs.regions().cloned().collect()
12261227
}
12271228
TyProjection(ref data) => {
1228-
data.trait_ref.substs.regions.to_vec()
1229+
data.trait_ref.substs.regions().cloned().collect()
12291230
}
12301231
TyFnDef(..) |
12311232
TyFnPtr(_) |

0 commit comments

Comments
 (0)