diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 2abf4991856..88d6ba43954 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -1153,11 +1153,11 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } fn rebuild_ty_params(&self, - ty_params: P<[hir::TyParam]>, + ty_params: hir::HirVec, lifetime: hir::Lifetime, region_names: &HashSet) - -> P<[hir::TyParam]> { - ty_params.map(|ty_param| { + -> hir::HirVec { + ty_params.iter().map(|ty_param| { let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(), lifetime, region_names); @@ -1168,7 +1168,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { default: ty_param.default.clone(), span: ty_param.span, } - }) + }).collect() } fn rebuild_ty_param_bounds(&self, @@ -1176,7 +1176,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { lifetime: hir::Lifetime, region_names: &HashSet) -> hir::TyParamBounds { - ty_param_bounds.map(|tpb| { + ty_param_bounds.iter().map(|tpb| { match tpb { &hir::RegionTyParamBound(lt) => { // FIXME -- it's unclear whether I'm supposed to @@ -1212,7 +1212,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { }, modifier) } } - }) + }).collect() } fn rebuild_expl_self(&self, @@ -1248,7 +1248,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { add: &Vec, keep: &HashSet, remove: &HashSet, - ty_params: P<[hir::TyParam]>, + ty_params: hir::HirVec, where_clause: hir::WhereClause) -> hir::Generics { let mut lifetimes = Vec::new(); @@ -1498,10 +1498,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } } } - let new_types = data.types.map(|t| { + let new_types = data.types.iter().map(|t| { self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names) - }); - let new_bindings = data.bindings.map(|b| { + }).collect(); + let new_bindings = data.bindings.iter().map(|b| { hir::TypeBinding { id: b.id, name: b.name, @@ -1511,7 +1511,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { region_names), span: b.span } - }); + }).collect(); hir::AngleBracketedParameters(hir::AngleBracketedParameterData { lifetimes: new_lts.into(), types: new_types, diff --git a/src/librustc_front/fold.rs b/src/librustc_front/fold.rs index 784428cc114..60318ff20f8 100644 --- a/src/librustc_front/fold.rs +++ b/src/librustc_front/fold.rs @@ -210,7 +210,7 @@ pub trait Folder : Sized { noop_fold_ty_param(tp, self) } - fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> { + fn fold_ty_params(&mut self, tps: HirVec) -> HirVec { noop_fold_ty_params(tps, self) } @@ -575,9 +575,9 @@ pub fn noop_fold_ty_param(tp: TyParam, fld: &mut T) -> TyParam { } } -pub fn noop_fold_ty_params(tps: P<[TyParam]>, +pub fn noop_fold_ty_params(tps: HirVec, fld: &mut T) - -> P<[TyParam]> { + -> HirVec { tps.move_map(|tp| fld.fold_ty_param(tp)) } diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index 6b2664af60b..e47619f292d 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -56,7 +56,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder}; /// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar /// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead /// of `Vec` to avoid keeping extra capacity. -pub type HirVec = Vec; +pub type HirVec = P<[T]>; macro_rules! hir_vec { ($elem:expr; $n:expr) => ( @@ -208,8 +208,8 @@ impl PathParameters { pub fn none() -> PathParameters { AngleBracketedParameters(AngleBracketedParameterData { lifetimes: HirVec::new(), - types: P::empty(), - bindings: P::empty(), + types: HirVec::new(), + bindings: HirVec::new(), }) } @@ -282,10 +282,10 @@ pub struct AngleBracketedParameterData { /// The lifetime parameters for this path segment. pub lifetimes: HirVec, /// The type parameters for this path segment, if present. - pub types: P<[P]>, + pub types: HirVec>, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo`. - pub bindings: P<[TypeBinding]>, + pub bindings: HirVec, } impl AngleBracketedParameterData { @@ -325,7 +325,7 @@ pub enum TraitBoundModifier { Maybe, } -pub type TyParamBounds = P<[TyParamBound]>; +pub type TyParamBounds = HirVec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct TyParam { @@ -341,7 +341,7 @@ pub struct TyParam { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Generics { pub lifetimes: HirVec, - pub ty_params: P<[TyParam]>, + pub ty_params: HirVec, pub where_clause: WhereClause, } diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 136c25f425e..5aa4c22dd53 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -434,7 +434,7 @@ pub fn lower_ty_param(lctx: &LoweringContext, tp: &TyParam) -> hir::TyParam { pub fn lower_ty_params(lctx: &LoweringContext, tps: &P<[TyParam]>) - -> P<[hir::TyParam]> { + -> hir::HirVec { tps.iter().map(|tp| lower_ty_param(lctx, tp)).collect() } @@ -1772,19 +1772,19 @@ fn path_ident(span: Span, id: hir::Ident) -> hir::Path { } fn path(span: Span, strs: Vec) -> hir::Path { - path_all(span, false, strs, hir::HirVec::new(), Vec::new(), Vec::new()) + path_all(span, false, strs, hir::HirVec::new(), hir::HirVec::new(), hir::HirVec::new()) } fn path_global(span: Span, strs: Vec) -> hir::Path { - path_all(span, true, strs, hir::HirVec::new(), Vec::new(), Vec::new()) + path_all(span, true, strs, hir::HirVec::new(), hir::HirVec::new(), hir::HirVec::new()) } fn path_all(sp: Span, global: bool, mut idents: Vec, lifetimes: hir::HirVec, - types: Vec>, - bindings: Vec) + types: hir::HirVec>, + bindings: hir::HirVec) -> hir::Path { let last_identifier = idents.pop().unwrap(); let mut segments: Vec = idents.into_iter() @@ -1799,8 +1799,8 @@ fn path_all(sp: Span, identifier: last_identifier, parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData { lifetimes: lifetimes, - types: P::from_vec(types), - bindings: P::from_vec(bindings), + types: types, + bindings: bindings, }), }); hir::Path { diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index 9ac0e65cba3..edfefeec3e3 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -518,7 +518,7 @@ impl<'a> State<'a> { hir::TyBareFn(ref f) => { let generics = hir::Generics { lifetimes: f.lifetimes.clone(), - ty_params: P::empty(), + ty_params: hir::HirVec::new(), where_clause: hir::WhereClause { id: ast::DUMMY_NODE_ID, predicates: hir::HirVec::new(), @@ -2257,7 +2257,7 @@ impl<'a> State<'a> { } let generics = hir::Generics { lifetimes: hir::HirVec::new(), - ty_params: P::empty(), + ty_params: hir::HirVec::new(), where_clause: hir::WhereClause { id: ast::DUMMY_NODE_ID, predicates: hir::HirVec::new(), diff --git a/src/librustc_front/util.rs b/src/librustc_front/util.rs index 298904d1e0d..57ffefd3be4 100644 --- a/src/librustc_front/util.rs +++ b/src/librustc_front/util.rs @@ -335,7 +335,7 @@ pub fn is_path(e: P) -> bool { pub fn empty_generics() -> Generics { Generics { lifetimes: HirVec::new(), - ty_params: P::empty(), + ty_params: HirVec::new(), where_clause: WhereClause { id: DUMMY_NODE_ID, predicates: HirVec::new(), @@ -353,8 +353,8 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path { identifier: ident, parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData { lifetimes: HirVec::new(), - types: P::empty(), - bindings: P::empty(), + types: HirVec::new(), + bindings: HirVec::new(), }), }], } diff --git a/src/librustc_mir/hair/cx/to_ref.rs b/src/librustc_mir/hair/cx/to_ref.rs index da200a8a33f..24fcc2f4fcd 100644 --- a/src/librustc_mir/hair/cx/to_ref.rs +++ b/src/librustc_mir/hair/cx/to_ref.rs @@ -61,3 +61,13 @@ impl<'a,'tcx:'a,T,U> ToRef for &'tcx Vec self.iter().map(|expr| expr.to_ref()).collect() } } + +impl<'a,'tcx:'a,T,U> ToRef for &'tcx P<[T]> + where &'tcx T: ToRef +{ + type Output = Vec; + + fn to_ref(self) -> Vec { + self.iter().map(|expr| expr.to_ref()).collect() + } +} diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index bddf0e9ffb0..515a7706b82 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4906,7 +4906,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &hir::Block) -> bool { } pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, - tps: &P<[hir::TyParam]>, + tps: &[hir::TyParam], ty: Ty<'tcx>) { debug!("check_bounds_are_used(n_tps={}, ty={:?})", tps.len(), ty); diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index 1be0b08086d..0504c313c91 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -130,6 +130,10 @@ impl fmt::Debug for P<[T]> { } impl P<[T]> { + pub fn new() -> P<[T]> { + P::empty() + } + pub fn empty() -> P<[T]> { P { ptr: Default::default() } } @@ -177,12 +181,33 @@ impl Clone for P<[T]> { } } +impl From> for P<[T]> { + fn from(v: Vec) -> Self { + P::from_vec(v) + } +} + +impl Into> for P<[T]> { + fn into(self) -> Vec { + self.into_vec() + } +} + impl FromIterator for P<[T]> { fn from_iter>(iter: I) -> P<[T]> { P::from_vec(iter.into_iter().collect()) } } +impl IntoIterator for P<[T]> { + type Item = T; + type IntoIter = vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.into_vec().into_iter() + } +} + impl<'a, T> IntoIterator for &'a P<[T]> { type Item = &'a T; type IntoIter = slice::Iter<'a, T>;