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())

src/librustc_trans/debuginfo/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
358358
name_to_append_suffix_to: &mut String)
359359
-> DIArray
360360
{
361-
let actual_types = param_substs.types.as_slice();
361+
let actual_types = param_substs.types.as_full_slice();
362362

363363
if actual_types.is_empty() {
364364
return create_DIArray(DIB(cx), &[]);
@@ -381,7 +381,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
381381

382382
// Again, only create type information if full debuginfo is enabled
383383
let template_params: Vec<_> = if cx.sess().opts.debuginfo == FullDebugInfo {
384-
generics.types.as_slice().iter().enumerate().map(|(i, param)| {
384+
generics.types.as_full_slice().iter().enumerate().map(|(i, param)| {
385385
let actual_type = cx.tcx().normalize_associated_type(&actual_types[i]);
386386
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
387387
let name = CString::new(param.name.as_str().as_bytes()).unwrap();

src/librustc_trans/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
181181

182182
output.push('<');
183183

184-
for &type_parameter in &substs.types {
184+
for &type_parameter in substs.types.as_full_slice() {
185185
push_debuginfo_type_name(cx, type_parameter, true, output);
186186
output.push_str(", ");
187187
}

src/librustc_trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
181181
impl<'tcx> Instance<'tcx> {
182182
pub fn new(def_id: DefId, substs: &'tcx Substs<'tcx>)
183183
-> Instance<'tcx> {
184-
assert!(substs.regions.iter().all(|&r| r == ty::ReErased));
184+
assert!(substs.regions.as_full_slice().iter().all(|&r| r == ty::ReErased));
185185
Instance { def: def_id, substs: substs }
186186
}
187187
pub fn mono<'a>(scx: &SharedCrateContext<'a, 'tcx>, def_id: DefId) -> Instance<'tcx> {

src/librustc_trans/trans_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn push_type_params<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
570570

571571
output.push('<');
572572

573-
for &type_parameter in types {
573+
for &type_parameter in types.as_full_slice() {
574574
push_unique_type_name(tcx, type_parameter, output);
575575
output.push_str(", ");
576576
}

src/librustc_typeck/check/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,8 @@ fn check_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
888888
// `{Self}` is allowed
889889
Position::ArgumentNamed(s) if s == "Self" => (),
890890
// So is `{A}` if A is a type parameter
891-
Position::ArgumentNamed(s) => match types.iter().find(|t| {
891+
Position::ArgumentNamed(s) => match types.as_full_slice()
892+
.iter().find(|t| {
892893
t.name.as_str() == s
893894
}) {
894895
Some(_) => (),
@@ -1895,7 +1896,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
18951896
/// Registers obligations that all types appearing in `substs` are well-formed.
18961897
pub fn add_wf_bounds(&self, substs: &Substs<'tcx>, expr: &hir::Expr)
18971898
{
1898-
for &ty in &substs.types {
1899+
for &ty in substs.types.as_full_slice() {
18991900
self.register_wf_obligation(ty, expr.span, traits::MiscObligation);
19001901
}
19011902
}

src/librustc_typeck/check/regionck.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,11 +1445,11 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
14451445

14461446
let origin = infer::ParameterInScope(origin, expr_span);
14471447

1448-
for &region in &substs.regions {
1448+
for &region in substs.regions.as_full_slice() {
14491449
self.sub_regions(origin.clone(), expr_region, region);
14501450
}
14511451

1452-
for &ty in &substs.types {
1452+
for &ty in substs.types.as_full_slice() {
14531453
let ty = self.resolve_type(ty);
14541454
self.type_must_outlive(origin.clone(), ty, expr_region);
14551455
}
@@ -1571,18 +1571,15 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
15711571
// the problem is to add `T: 'r`, which isn't true. So, if there are no
15721572
// inference variables, we use a verify constraint instead of adding
15731573
// edges, which winds up enforcing the same condition.
1574-
let needs_infer = {
1575-
projection_ty.trait_ref.substs.types.iter().any(|t| t.needs_infer()) ||
1576-
projection_ty.trait_ref.substs.regions.iter().any(|r| r.needs_infer())
1577-
};
1574+
let needs_infer = projection_ty.trait_ref.needs_infer();
15781575
if env_bounds.is_empty() && needs_infer {
15791576
debug!("projection_must_outlive: no declared bounds");
15801577

1581-
for &component_ty in &projection_ty.trait_ref.substs.types {
1578+
for &component_ty in projection_ty.trait_ref.substs.types.as_full_slice() {
15821579
self.type_must_outlive(origin.clone(), component_ty, region);
15831580
}
15841581

1585-
for &r in &projection_ty.trait_ref.substs.regions {
1582+
for &r in projection_ty.trait_ref.substs.regions.as_full_slice() {
15861583
self.sub_regions(origin.clone(), region, r);
15871584
}
15881585

@@ -1600,7 +1597,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
16001597
if !env_bounds.is_empty() && env_bounds[1..].iter().all(|b| *b == env_bounds[0]) {
16011598
let unique_bound = env_bounds[0];
16021599
debug!("projection_must_outlive: unique declared bound = {:?}", unique_bound);
1603-
if projection_ty.trait_ref.substs.regions
1600+
if projection_ty.trait_ref.substs.regions.as_full_slice()
16041601
.iter()
16051602
.any(|r| env_bounds.contains(r))
16061603
{

src/librustc_typeck/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
621621
// Trait impl: take implied bounds from all types that
622622
// appear in the trait reference.
623623
let trait_ref = self.instantiate_type_scheme(span, free_substs, trait_ref);
624-
trait_ref.substs.types.as_slice().to_vec()
624+
trait_ref.substs.types.as_full_slice().to_vec()
625625
}
626626

627627
None => {

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ fn convert_typed_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
15501550
// Debugging aid.
15511551
if tcx.has_attr(ccx.tcx.map.local_def_id(it.id), "rustc_object_lifetime_default") {
15521552
let object_lifetime_default_reprs: String =
1553-
scheme.generics.types.iter()
1553+
scheme.generics.types.as_full_slice().iter()
15541554
.map(|t| match t.object_lifetime_default {
15551555
ty::ObjectLifetimeDefault::Specific(r) => r.to_string(),
15561556
d => format!("{:?}", d),

0 commit comments

Comments
 (0)