Skip to content

Commit 77dc61b

Browse files
committed
rustc: force all raw accesses to VecPerParamSpace through as_full_slice.
1 parent b354ae9 commit 77dc61b

File tree

20 files changed

+52
-85
lines changed

20 files changed

+52
-85
lines changed

src/librustc/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
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_slice().len() == 1 && substs.regions.is_empty() {
145+
if substs.types.as_full_slice().len() == 1 && substs.regions.is_empty() {
146146
if let ty::TyAnon(..) = predicate.skip_binder().self_ty().sty {
147147
return true;
148148
}

src/librustc/ty/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ impl FlagComputation {
209209
}
210210

211211
fn add_substs(&mut self, substs: &subst::Substs) {
212-
self.add_tys(substs.types.as_slice());
213-
for &r in &substs.regions {
212+
self.add_tys(substs.types.as_full_slice());
213+
for &r in substs.regions.as_full_slice() {
214214
self.add_region(r);
215215
}
216216
}

src/librustc/ty/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ impl<'tcx> TraitPredicate<'tcx> {
971971
}
972972

973973
pub fn input_types(&self) -> &[Ty<'tcx>] {
974-
self.trait_ref.substs.types.as_slice()
974+
self.trait_ref.substs.types.as_full_slice()
975975
}
976976

977977
pub fn self_ty(&self) -> Ty<'tcx> {
@@ -1113,7 +1113,7 @@ impl<'tcx> Predicate<'tcx> {
11131113
pub fn walk_tys(&self) -> IntoIter<Ty<'tcx>> {
11141114
let vec: Vec<_> = match *self {
11151115
ty::Predicate::Trait(ref data) => {
1116-
data.0.trait_ref.substs.types.as_slice().to_vec()
1116+
data.0.trait_ref.substs.types.as_full_slice().to_vec()
11171117
}
11181118
ty::Predicate::Rfc1592(ref data) => {
11191119
return data.walk_tys()
@@ -1128,7 +1128,8 @@ impl<'tcx> Predicate<'tcx> {
11281128
vec![]
11291129
}
11301130
ty::Predicate::Projection(ref data) => {
1131-
let trait_inputs = data.0.projection_ty.trait_ref.substs.types.as_slice();
1131+
let trait_inputs = data.0.projection_ty.trait_ref.substs
1132+
.types.as_full_slice();
11321133
trait_inputs.iter()
11331134
.cloned()
11341135
.chain(Some(data.0.ty))
@@ -1220,7 +1221,7 @@ impl<'tcx> TraitRef<'tcx> {
12201221
// now this is all the types that appear in the
12211222
// trait-reference, but it should eventually exclude
12221223
// associated types.
1223-
self.substs.types.as_slice()
1224+
self.substs.types.as_full_slice()
12241225
}
12251226
}
12261227

@@ -2864,15 +2865,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28642865
free_id_outlive: CodeExtent) -> Substs<'gcx> {
28652866
// map T => T
28662867
let mut types = VecPerParamSpace::empty();
2867-
for def in generics.types.as_slice() {
2868+
for def in generics.types.as_full_slice() {
28682869
debug!("construct_parameter_environment(): push_types_from_defs: def={:?}",
28692870
def);
28702871
types.push(def.space, self.global_tcx().mk_param_from_def(def));
28712872
}
28722873

28732874
// map bound 'a => free 'a
28742875
let mut regions = VecPerParamSpace::empty();
2875-
for def in generics.regions.as_slice() {
2876+
for def in generics.regions.as_full_slice() {
28762877
let region =
28772878
ReFree(FreeRegion { scope: free_id_outlive,
28782879
bound_region: def.to_bound_region() });

src/librustc/ty/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace<T> {
433433
}
434434

435435
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
436-
self.iter().any(|elem| elem.visit_with(visitor))
436+
self.as_full_slice().iter().any(|elem| elem.visit_with(visitor))
437437
}
438438
}
439439

src/librustc/ty/sty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,19 +1211,19 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
12111211
TyTrait(ref obj) => {
12121212
let mut v = vec![obj.bounds.region_bound];
12131213
v.extend_from_slice(obj.principal.skip_binder()
1214-
.substs.regions.as_slice());
1214+
.substs.regions.as_full_slice());
12151215
v
12161216
}
12171217
TyEnum(_, substs) |
12181218
TyStruct(_, substs) |
12191219
TyAnon(_, substs) => {
1220-
substs.regions.as_slice().to_vec()
1220+
substs.regions.as_full_slice().to_vec()
12211221
}
12221222
TyClosure(_, ref substs) => {
1223-
substs.func_substs.regions.as_slice().to_vec()
1223+
substs.func_substs.regions.as_full_slice().to_vec()
12241224
}
12251225
TyProjection(ref data) => {
1226-
data.trait_ref.substs.regions.as_slice().to_vec()
1226+
data.trait_ref.substs.regions.as_full_slice().to_vec()
12271227
}
12281228
TyFnDef(..) |
12291229
TyFnPtr(_) |

src/librustc/ty/subst.rs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ use ty::fold::{TypeFoldable, TypeFolder};
1919

2020
use serialize::{Encodable, Encoder, Decodable, Decoder};
2121
use std::fmt;
22-
use std::iter::IntoIterator;
23-
use std::slice::Iter;
24-
use std::vec::{Vec, IntoIter};
2522
use syntax_pos::{Span, DUMMY_SP};
2623

2724
///////////////////////////////////////////////////////////////////////////
@@ -365,46 +362,34 @@ impl<T> VecPerParamSpace<T> {
365362
&self.get_slice(space)[index]
366363
}
367364

368-
pub fn iter<'a>(&'a self) -> Iter<'a,T> {
369-
self.content.iter()
370-
}
371-
372-
pub fn into_iter(self) -> IntoIter<T> {
373-
self.content.into_iter()
374-
}
375-
376365
pub fn iter_enumerated<'a>(&'a self) -> EnumeratedItems<'a,T> {
377366
EnumeratedItems::new(self)
378367
}
379368

380-
pub fn as_slice(&self) -> &[T] {
369+
pub fn as_full_slice(&self) -> &[T] {
381370
&self.content
382371
}
383372

384-
pub fn into_vec(self) -> Vec<T> {
385-
self.content
386-
}
387-
388373
pub fn all_vecs<P>(&self, mut pred: P) -> bool where
389374
P: FnMut(&[T]) -> bool,
390375
{
391376
ParamSpace::all().iter().all(|&space| { pred(self.get_slice(space)) })
392377
}
393378

394379
pub fn all<P>(&self, pred: P) -> bool where P: FnMut(&T) -> bool {
395-
self.iter().all(pred)
380+
self.as_full_slice().iter().all(pred)
396381
}
397382

398383
pub fn any<P>(&self, pred: P) -> bool where P: FnMut(&T) -> bool {
399-
self.iter().any(pred)
384+
self.as_full_slice().iter().any(pred)
400385
}
401386

402387
pub fn is_empty(&self) -> bool {
403388
self.all_vecs(|v| v.is_empty())
404389
}
405390

406391
pub fn map<U, P>(&self, pred: P) -> VecPerParamSpace<U> where P: FnMut(&T) -> U {
407-
let result = self.iter().map(pred).collect();
392+
let result = self.as_full_slice().iter().map(pred).collect();
408393
VecPerParamSpace::new_internal(result,
409394
self.self_limit,
410395
self.type_limit)
@@ -478,29 +463,11 @@ impl<'a,T> Iterator for EnumeratedItems<'a,T> {
478463
}
479464

480465
fn size_hint(&self) -> (usize, Option<usize>) {
481-
let size = self.vec.as_slice().len();
466+
let size = self.vec.as_full_slice().len();
482467
(size, Some(size))
483468
}
484469
}
485470

486-
impl<T> IntoIterator for VecPerParamSpace<T> {
487-
type Item = T;
488-
type IntoIter = IntoIter<T>;
489-
490-
fn into_iter(self) -> IntoIter<T> {
491-
self.into_vec().into_iter()
492-
}
493-
}
494-
495-
impl<'a,T> IntoIterator for &'a VecPerParamSpace<T> {
496-
type Item = &'a T;
497-
type IntoIter = Iter<'a, T>;
498-
499-
fn into_iter(self) -> Iter<'a, T> {
500-
self.as_slice().into_iter()
501-
}
502-
}
503-
504471

505472
///////////////////////////////////////////////////////////////////////////
506473
// Public trait `Subst`

src/librustc/ty/walk.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,28 @@ fn push_subtypes<'tcx>(stack: &mut Vec<Ty<'tcx>>, parent_ty: Ty<'tcx>) {
7979
stack.push(mt.ty);
8080
}
8181
ty::TyProjection(ref data) => {
82-
push_reversed(stack, data.trait_ref.substs.types.as_slice());
82+
push_reversed(stack, data.trait_ref.substs.types.as_full_slice());
8383
}
8484
ty::TyTrait(box ty::TraitTy { ref principal, ref bounds }) => {
85-
push_reversed(stack, principal.substs().types.as_slice());
85+
push_reversed(stack, principal.substs().types.as_full_slice());
8686
push_reversed(stack, &bounds.projection_bounds.iter().map(|pred| {
8787
pred.0.ty
8888
}).collect::<Vec<_>>());
8989
}
9090
ty::TyEnum(_, ref substs) |
9191
ty::TyStruct(_, ref substs) |
9292
ty::TyAnon(_, ref substs) => {
93-
push_reversed(stack, substs.types.as_slice());
93+
push_reversed(stack, substs.types.as_full_slice());
9494
}
9595
ty::TyClosure(_, ref substs) => {
96-
push_reversed(stack, substs.func_substs.types.as_slice());
96+
push_reversed(stack, substs.func_substs.types.as_full_slice());
9797
push_reversed(stack, &substs.upvar_tys);
9898
}
9999
ty::TyTuple(ref ts) => {
100100
push_reversed(stack, ts);
101101
}
102102
ty::TyFnDef(_, substs, ref ft) => {
103-
push_reversed(stack, substs.types.as_slice());
103+
push_reversed(stack, substs.types.as_full_slice());
104104
push_sig_subtypes(stack, &ft.sig);
105105
}
106106
ty::TyFnPtr(ref ft) => {

src/librustc/ty/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
261261
let cause = self.cause(traits::MiscObligation);
262262
self.out.extend(
263263
trait_ref.substs.types
264-
.as_slice()
264+
.as_full_slice()
265265
.iter()
266266
.filter(|ty| !ty.has_escaping_regions())
267267
.map(|ty| traits::Obligation::new(cause.clone(),

src/librustc_metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,15 @@ fn encode_generics<'a, 'tcx>(rbml_w: &mut Encoder,
515515
{
516516
rbml_w.start_tag(tag);
517517

518-
for param in &generics.types {
518+
for param in generics.types.as_full_slice() {
519519
rbml_w.start_tag(tag_type_param_def);
520520
tyencode::enc_type_param_def(rbml_w.writer, &ecx.ty_str_ctxt(), param);
521521
rbml_w.mark_stable_position();
522522
rbml_w.end_tag();
523523
}
524524

525525
// Region parameters
526-
for param in &generics.regions {
526+
for param in generics.regions.as_full_slice() {
527527
rbml_w.start_tag(tag_region_param_def);
528528
tyencode::enc_region_param_def(rbml_w.writer, &ecx.ty_str_ctxt(), param);
529529
rbml_w.mark_stable_position();

src/librustc_trans/back/symbol_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a, 'tcx> Instance<'tcx> {
252252
// and should not matter anyhow.
253253
let instance_ty = scx.tcx().erase_regions(&instance_ty.ty);
254254

255-
let hash = get_symbol_hash(scx, &def_path, instance_ty, substs.types.as_slice());
255+
let hash = get_symbol_hash(scx, &def_path, instance_ty, substs.types.as_full_slice());
256256

257257
let mut buffer = SymbolPathBuffer {
258258
names: Vec::with_capacity(def_path.data.len())

0 commit comments

Comments
 (0)