rustc: force all raw accesses to VecPerParamSpace through as_full_slice.

This commit is contained in:
Eduard Burtescu 2016-06-13 20:46:08 +03:00
parent b354ae95a2
commit 77dc61b5c6
20 changed files with 52 additions and 85 deletions

@ -142,7 +142,7 @@ impl<'a, 'gcx, 'tcx> DeferredObligation<'tcx> {
// Auto trait obligations on `impl Trait`.
if tcx.trait_has_default_impl(predicate.def_id()) {
let substs = predicate.skip_binder().trait_ref.substs;
if substs.types.as_slice().len() == 1 && substs.regions.is_empty() {
if substs.types.as_full_slice().len() == 1 && substs.regions.is_empty() {
if let ty::TyAnon(..) = predicate.skip_binder().self_ty().sty {
return true;
}

@ -209,8 +209,8 @@ impl FlagComputation {
}
fn add_substs(&mut self, substs: &subst::Substs) {
self.add_tys(substs.types.as_slice());
for &r in &substs.regions {
self.add_tys(substs.types.as_full_slice());
for &r in substs.regions.as_full_slice() {
self.add_region(r);
}
}

@ -971,7 +971,7 @@ impl<'tcx> TraitPredicate<'tcx> {
}
pub fn input_types(&self) -> &[Ty<'tcx>] {
self.trait_ref.substs.types.as_slice()
self.trait_ref.substs.types.as_full_slice()
}
pub fn self_ty(&self) -> Ty<'tcx> {
@ -1113,7 +1113,7 @@ impl<'tcx> Predicate<'tcx> {
pub fn walk_tys(&self) -> IntoIter<Ty<'tcx>> {
let vec: Vec<_> = match *self {
ty::Predicate::Trait(ref data) => {
data.0.trait_ref.substs.types.as_slice().to_vec()
data.0.trait_ref.substs.types.as_full_slice().to_vec()
}
ty::Predicate::Rfc1592(ref data) => {
return data.walk_tys()
@ -1128,7 +1128,8 @@ impl<'tcx> Predicate<'tcx> {
vec![]
}
ty::Predicate::Projection(ref data) => {
let trait_inputs = data.0.projection_ty.trait_ref.substs.types.as_slice();
let trait_inputs = data.0.projection_ty.trait_ref.substs
.types.as_full_slice();
trait_inputs.iter()
.cloned()
.chain(Some(data.0.ty))
@ -1220,7 +1221,7 @@ impl<'tcx> TraitRef<'tcx> {
// now this is all the types that appear in the
// trait-reference, but it should eventually exclude
// associated types.
self.substs.types.as_slice()
self.substs.types.as_full_slice()
}
}
@ -2864,7 +2865,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
free_id_outlive: CodeExtent) -> Substs<'gcx> {
// map T => T
let mut types = VecPerParamSpace::empty();
for def in generics.types.as_slice() {
for def in generics.types.as_full_slice() {
debug!("construct_parameter_environment(): push_types_from_defs: def={:?}",
def);
types.push(def.space, self.global_tcx().mk_param_from_def(def));
@ -2872,7 +2873,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// map bound 'a => free 'a
let mut regions = VecPerParamSpace::empty();
for def in generics.regions.as_slice() {
for def in generics.regions.as_full_slice() {
let region =
ReFree(FreeRegion { scope: free_id_outlive,
bound_region: def.to_bound_region() });

@ -433,7 +433,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace<T> {
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
self.iter().any(|elem| elem.visit_with(visitor))
self.as_full_slice().iter().any(|elem| elem.visit_with(visitor))
}
}

@ -1211,19 +1211,19 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
TyTrait(ref obj) => {
let mut v = vec![obj.bounds.region_bound];
v.extend_from_slice(obj.principal.skip_binder()
.substs.regions.as_slice());
.substs.regions.as_full_slice());
v
}
TyEnum(_, substs) |
TyStruct(_, substs) |
TyAnon(_, substs) => {
substs.regions.as_slice().to_vec()
substs.regions.as_full_slice().to_vec()
}
TyClosure(_, ref substs) => {
substs.func_substs.regions.as_slice().to_vec()
substs.func_substs.regions.as_full_slice().to_vec()
}
TyProjection(ref data) => {
data.trait_ref.substs.regions.as_slice().to_vec()
data.trait_ref.substs.regions.as_full_slice().to_vec()
}
TyFnDef(..) |
TyFnPtr(_) |

@ -19,9 +19,6 @@ use ty::fold::{TypeFoldable, TypeFolder};
use serialize::{Encodable, Encoder, Decodable, Decoder};
use std::fmt;
use std::iter::IntoIterator;
use std::slice::Iter;
use std::vec::{Vec, IntoIter};
use syntax_pos::{Span, DUMMY_SP};
///////////////////////////////////////////////////////////////////////////
@ -365,26 +362,14 @@ impl<T> VecPerParamSpace<T> {
&self.get_slice(space)[index]
}
pub fn iter<'a>(&'a self) -> Iter<'a,T> {
self.content.iter()
}
pub fn into_iter(self) -> IntoIter<T> {
self.content.into_iter()
}
pub fn iter_enumerated<'a>(&'a self) -> EnumeratedItems<'a,T> {
EnumeratedItems::new(self)
}
pub fn as_slice(&self) -> &[T] {
pub fn as_full_slice(&self) -> &[T] {
&self.content
}
pub fn into_vec(self) -> Vec<T> {
self.content
}
pub fn all_vecs<P>(&self, mut pred: P) -> bool where
P: FnMut(&[T]) -> bool,
{
@ -392,11 +377,11 @@ impl<T> VecPerParamSpace<T> {
}
pub fn all<P>(&self, pred: P) -> bool where P: FnMut(&T) -> bool {
self.iter().all(pred)
self.as_full_slice().iter().all(pred)
}
pub fn any<P>(&self, pred: P) -> bool where P: FnMut(&T) -> bool {
self.iter().any(pred)
self.as_full_slice().iter().any(pred)
}
pub fn is_empty(&self) -> bool {
@ -404,7 +389,7 @@ impl<T> VecPerParamSpace<T> {
}
pub fn map<U, P>(&self, pred: P) -> VecPerParamSpace<U> where P: FnMut(&T) -> U {
let result = self.iter().map(pred).collect();
let result = self.as_full_slice().iter().map(pred).collect();
VecPerParamSpace::new_internal(result,
self.self_limit,
self.type_limit)
@ -478,29 +463,11 @@ impl<'a,T> Iterator for EnumeratedItems<'a,T> {
}
fn size_hint(&self) -> (usize, Option<usize>) {
let size = self.vec.as_slice().len();
let size = self.vec.as_full_slice().len();
(size, Some(size))
}
}
impl<T> IntoIterator for VecPerParamSpace<T> {
type Item = T;
type IntoIter = IntoIter<T>;
fn into_iter(self) -> IntoIter<T> {
self.into_vec().into_iter()
}
}
impl<'a,T> IntoIterator for &'a VecPerParamSpace<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;
fn into_iter(self) -> Iter<'a, T> {
self.as_slice().into_iter()
}
}
///////////////////////////////////////////////////////////////////////////
// Public trait `Subst`

@ -79,10 +79,10 @@ fn push_subtypes<'tcx>(stack: &mut Vec<Ty<'tcx>>, parent_ty: Ty<'tcx>) {
stack.push(mt.ty);
}
ty::TyProjection(ref data) => {
push_reversed(stack, data.trait_ref.substs.types.as_slice());
push_reversed(stack, data.trait_ref.substs.types.as_full_slice());
}
ty::TyTrait(box ty::TraitTy { ref principal, ref bounds }) => {
push_reversed(stack, principal.substs().types.as_slice());
push_reversed(stack, principal.substs().types.as_full_slice());
push_reversed(stack, &bounds.projection_bounds.iter().map(|pred| {
pred.0.ty
}).collect::<Vec<_>>());
@ -90,17 +90,17 @@ fn push_subtypes<'tcx>(stack: &mut Vec<Ty<'tcx>>, parent_ty: Ty<'tcx>) {
ty::TyEnum(_, ref substs) |
ty::TyStruct(_, ref substs) |
ty::TyAnon(_, ref substs) => {
push_reversed(stack, substs.types.as_slice());
push_reversed(stack, substs.types.as_full_slice());
}
ty::TyClosure(_, ref substs) => {
push_reversed(stack, substs.func_substs.types.as_slice());
push_reversed(stack, substs.func_substs.types.as_full_slice());
push_reversed(stack, &substs.upvar_tys);
}
ty::TyTuple(ref ts) => {
push_reversed(stack, ts);
}
ty::TyFnDef(_, substs, ref ft) => {
push_reversed(stack, substs.types.as_slice());
push_reversed(stack, substs.types.as_full_slice());
push_sig_subtypes(stack, &ft.sig);
}
ty::TyFnPtr(ref ft) => {

@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
let cause = self.cause(traits::MiscObligation);
self.out.extend(
trait_ref.substs.types
.as_slice()
.as_full_slice()
.iter()
.filter(|ty| !ty.has_escaping_regions())
.map(|ty| traits::Obligation::new(cause.clone(),

@ -515,7 +515,7 @@ fn encode_generics<'a, 'tcx>(rbml_w: &mut Encoder,
{
rbml_w.start_tag(tag);
for param in &generics.types {
for param in generics.types.as_full_slice() {
rbml_w.start_tag(tag_type_param_def);
tyencode::enc_type_param_def(rbml_w.writer, &ecx.ty_str_ctxt(), param);
rbml_w.mark_stable_position();
@ -523,7 +523,7 @@ fn encode_generics<'a, 'tcx>(rbml_w: &mut Encoder,
}
// Region parameters
for param in &generics.regions {
for param in generics.regions.as_full_slice() {
rbml_w.start_tag(tag_region_param_def);
tyencode::enc_region_param_def(rbml_w.writer, &ecx.ty_str_ctxt(), param);
rbml_w.mark_stable_position();

@ -252,7 +252,7 @@ impl<'a, 'tcx> Instance<'tcx> {
// and should not matter anyhow.
let instance_ty = scx.tcx().erase_regions(&instance_ty.ty);
let hash = get_symbol_hash(scx, &def_path, instance_ty, substs.types.as_slice());
let hash = get_symbol_hash(scx, &def_path, instance_ty, substs.types.as_full_slice());
let mut buffer = SymbolPathBuffer {
names: Vec::with_capacity(def_path.data.len())

@ -358,7 +358,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
name_to_append_suffix_to: &mut String)
-> DIArray
{
let actual_types = param_substs.types.as_slice();
let actual_types = param_substs.types.as_full_slice();
if actual_types.is_empty() {
return create_DIArray(DIB(cx), &[]);
@ -381,7 +381,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
// Again, only create type information if full debuginfo is enabled
let template_params: Vec<_> = if cx.sess().opts.debuginfo == FullDebugInfo {
generics.types.as_slice().iter().enumerate().map(|(i, param)| {
generics.types.as_full_slice().iter().enumerate().map(|(i, param)| {
let actual_type = cx.tcx().normalize_associated_type(&actual_types[i]);
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
let name = CString::new(param.name.as_str().as_bytes()).unwrap();

@ -181,7 +181,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
output.push('<');
for &type_parameter in &substs.types {
for &type_parameter in substs.types.as_full_slice() {
push_debuginfo_type_name(cx, type_parameter, true, output);
output.push_str(", ");
}

@ -181,7 +181,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
impl<'tcx> Instance<'tcx> {
pub fn new(def_id: DefId, substs: &'tcx Substs<'tcx>)
-> Instance<'tcx> {
assert!(substs.regions.iter().all(|&r| r == ty::ReErased));
assert!(substs.regions.as_full_slice().iter().all(|&r| r == ty::ReErased));
Instance { def: def_id, substs: substs }
}
pub fn mono<'a>(scx: &SharedCrateContext<'a, 'tcx>, def_id: DefId) -> Instance<'tcx> {

@ -570,7 +570,7 @@ fn push_type_params<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
output.push('<');
for &type_parameter in types {
for &type_parameter in types.as_full_slice() {
push_unique_type_name(tcx, type_parameter, output);
output.push_str(", ");
}

@ -888,7 +888,8 @@ fn check_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// `{Self}` is allowed
Position::ArgumentNamed(s) if s == "Self" => (),
// So is `{A}` if A is a type parameter
Position::ArgumentNamed(s) => match types.iter().find(|t| {
Position::ArgumentNamed(s) => match types.as_full_slice()
.iter().find(|t| {
t.name.as_str() == s
}) {
Some(_) => (),
@ -1895,7 +1896,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
/// Registers obligations that all types appearing in `substs` are well-formed.
pub fn add_wf_bounds(&self, substs: &Substs<'tcx>, expr: &hir::Expr)
{
for &ty in &substs.types {
for &ty in substs.types.as_full_slice() {
self.register_wf_obligation(ty, expr.span, traits::MiscObligation);
}
}

@ -1445,11 +1445,11 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
let origin = infer::ParameterInScope(origin, expr_span);
for &region in &substs.regions {
for &region in substs.regions.as_full_slice() {
self.sub_regions(origin.clone(), expr_region, region);
}
for &ty in &substs.types {
for &ty in substs.types.as_full_slice() {
let ty = self.resolve_type(ty);
self.type_must_outlive(origin.clone(), ty, expr_region);
}
@ -1571,18 +1571,15 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
// the problem is to add `T: 'r`, which isn't true. So, if there are no
// inference variables, we use a verify constraint instead of adding
// edges, which winds up enforcing the same condition.
let needs_infer = {
projection_ty.trait_ref.substs.types.iter().any(|t| t.needs_infer()) ||
projection_ty.trait_ref.substs.regions.iter().any(|r| r.needs_infer())
};
let needs_infer = projection_ty.trait_ref.needs_infer();
if env_bounds.is_empty() && needs_infer {
debug!("projection_must_outlive: no declared bounds");
for &component_ty in &projection_ty.trait_ref.substs.types {
for &component_ty in projection_ty.trait_ref.substs.types.as_full_slice() {
self.type_must_outlive(origin.clone(), component_ty, region);
}
for &r in &projection_ty.trait_ref.substs.regions {
for &r in projection_ty.trait_ref.substs.regions.as_full_slice() {
self.sub_regions(origin.clone(), region, r);
}
@ -1600,7 +1597,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
if !env_bounds.is_empty() && env_bounds[1..].iter().all(|b| *b == env_bounds[0]) {
let unique_bound = env_bounds[0];
debug!("projection_must_outlive: unique declared bound = {:?}", unique_bound);
if projection_ty.trait_ref.substs.regions
if projection_ty.trait_ref.substs.regions.as_full_slice()
.iter()
.any(|r| env_bounds.contains(r))
{

@ -621,7 +621,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Trait impl: take implied bounds from all types that
// appear in the trait reference.
let trait_ref = self.instantiate_type_scheme(span, free_substs, trait_ref);
trait_ref.substs.types.as_slice().to_vec()
trait_ref.substs.types.as_full_slice().to_vec()
}
None => {

@ -1550,7 +1550,7 @@ fn convert_typed_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// Debugging aid.
if tcx.has_attr(ccx.tcx.map.local_def_id(it.id), "rustc_object_lifetime_default") {
let object_lifetime_default_reprs: String =
scheme.generics.types.iter()
scheme.generics.types.as_full_slice().iter()
.map(|t| match t.object_lifetime_default {
ty::ObjectLifetimeDefault::Specific(r) => r.to_string(),
d => format!("{:?}", d),

@ -302,8 +302,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_substs(
generics,
trait_ref.def_id,
trait_def.generics.types.as_slice(),
trait_def.generics.regions.as_slice(),
trait_def.generics.types.as_full_slice(),
trait_def.generics.regions.as_full_slice(),
trait_ref.substs,
variance);
}
@ -388,8 +388,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_substs(
generics,
trait_ref.def_id,
trait_def.generics.types.as_slice(),
trait_def.generics.regions.as_slice(),
trait_def.generics.types.as_full_slice(),
trait_def.generics.regions.as_full_slice(),
trait_ref.substs,
variance);
}

@ -788,8 +788,9 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
impl<'tcx> Clean<Option<Vec<TyParamBound>>> for subst::Substs<'tcx> {
fn clean(&self, cx: &DocContext) -> Option<Vec<TyParamBound>> {
let mut v = Vec::new();
v.extend(self.regions.iter().filter_map(|r| r.clean(cx)).map(RegionBound));
v.extend(self.types.iter().map(|t| TraitBound(PolyTrait {
v.extend(self.regions.as_full_slice().iter().filter_map(|r| r.clean(cx))
.map(RegionBound));
v.extend(self.types.as_full_slice().iter().map(|t| TraitBound(PolyTrait {
trait_: t.clean(cx),
lifetimes: vec![]
}, hir::TraitBoundModifier::None)));