}
fn rebuild_ty_params(&self,
- ty_params: P<[hir::TyParam]>,
+ ty_params: hir::HirVec<hir::TyParam>,
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
- -> P<[hir::TyParam]> {
- ty_params.map(|ty_param| {
+ -> hir::HirVec<hir::TyParam> {
+ ty_params.iter().map(|ty_param| {
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
lifetime,
region_names);
default: ty_param.default.clone(),
span: ty_param.span,
}
- })
+ }).collect()
}
fn rebuild_ty_param_bounds(&self,
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> 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
}, modifier)
}
}
- })
+ }).collect()
}
fn rebuild_expl_self(&self,
add: &Vec<hir::Lifetime>,
keep: &HashSet<ast::Name>,
remove: &HashSet<ast::Name>,
- ty_params: P<[hir::TyParam]>,
+ ty_params: hir::HirVec<hir::TyParam>,
where_clause: hir::WhereClause)
-> hir::Generics {
let mut lifetimes = Vec::new();
}
}
}
- 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,
region_names),
span: b.span
}
- });
+ }).collect();
hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: new_lts.into(),
types: new_types,
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<TyParam>) -> HirVec<TyParam> {
noop_fold_ty_params(tps, self)
}
}
}
-pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>,
+pub fn noop_fold_ty_params<T: Folder>(tps: HirVec<TyParam>,
fld: &mut T)
- -> P<[TyParam]> {
+ -> HirVec<TyParam> {
tps.move_map(|tp| fld.fold_ty_param(tp))
}
/// 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<T> = Vec<T>;
+pub type HirVec<T> = P<[T]>;
macro_rules! hir_vec {
($elem:expr; $n:expr) => (
pub fn none() -> PathParameters {
AngleBracketedParameters(AngleBracketedParameterData {
lifetimes: HirVec::new(),
- types: P::empty(),
- bindings: P::empty(),
+ types: HirVec::new(),
+ bindings: HirVec::new(),
})
}
/// The lifetime parameters for this path segment.
pub lifetimes: HirVec<Lifetime>,
/// The type parameters for this path segment, if present.
- pub types: P<[P<Ty>]>,
+ pub types: HirVec<P<Ty>>,
/// Bindings (equality constraints) on associated types, if present.
/// E.g., `Foo<A=Bar>`.
- pub bindings: P<[TypeBinding]>,
+ pub bindings: HirVec<TypeBinding>,
}
impl AngleBracketedParameterData {
Maybe,
}
-pub type TyParamBounds = P<[TyParamBound]>;
+pub type TyParamBounds = HirVec<TyParamBound>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TyParam {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Generics {
pub lifetimes: HirVec<LifetimeDef>,
- pub ty_params: P<[TyParam]>,
+ pub ty_params: HirVec<TyParam>,
pub where_clause: WhereClause,
}
pub fn lower_ty_params(lctx: &LoweringContext,
tps: &P<[TyParam]>)
- -> P<[hir::TyParam]> {
+ -> hir::HirVec<hir::TyParam> {
tps.iter().map(|tp| lower_ty_param(lctx, tp)).collect()
}
}
fn path(span: Span, strs: Vec<hir::Ident>) -> 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::Ident>) -> 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<hir::Ident>,
lifetimes: hir::HirVec<hir::Lifetime>,
- types: Vec<P<hir::Ty>>,
- bindings: Vec<hir::TypeBinding>)
+ types: hir::HirVec<P<hir::Ty>>,
+ bindings: hir::HirVec<hir::TypeBinding>)
-> hir::Path {
let last_identifier = idents.pop().unwrap();
let mut segments: Vec<hir::PathSegment> = idents.into_iter()
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 {
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(),
}
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(),
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(),
identifier: ident,
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: HirVec::new(),
- types: P::empty(),
- bindings: P::empty(),
+ types: HirVec::new(),
+ bindings: HirVec::new(),
}),
}],
}
self.iter().map(|expr| expr.to_ref()).collect()
}
}
+
+impl<'a,'tcx:'a,T,U> ToRef for &'tcx P<[T]>
+ where &'tcx T: ToRef<Output=U>
+{
+ type Output = Vec<U>;
+
+ fn to_ref(self) -> Vec<U> {
+ self.iter().map(|expr| expr.to_ref()).collect()
+ }
+}
}
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);
}
impl<T> P<[T]> {
+ pub fn new() -> P<[T]> {
+ P::empty()
+ }
+
pub fn empty() -> P<[T]> {
P { ptr: Default::default() }
}
}
}
+impl<T> From<Vec<T>> for P<[T]> {
+ fn from(v: Vec<T>) -> Self {
+ P::from_vec(v)
+ }
+}
+
+impl<T> Into<Vec<T>> for P<[T]> {
+ fn into(self) -> Vec<T> {
+ self.into_vec()
+ }
+}
+
impl<T> FromIterator<T> for P<[T]> {
fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> P<[T]> {
P::from_vec(iter.into_iter().collect())
}
}
+impl<T> IntoIterator for P<[T]> {
+ type Item = T;
+ type IntoIter = vec::IntoIter<T>;
+
+ 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>;