Use resizable Vec instead of P<[T]> in AST
This commit is contained in:
parent
2efe865d22
commit
03620dba25
@ -596,7 +596,7 @@ impl<'a> LoweringContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_ty_params(&mut self, tps: &P<[TyParam]>, add_bounds: &NodeMap<Vec<TyParamBound>>)
|
||||
fn lower_ty_params(&mut self, tps: &Vec<TyParam>, add_bounds: &NodeMap<Vec<TyParamBound>>)
|
||||
-> hir::HirVec<hir::TyParam> {
|
||||
tps.iter().map(|tp| {
|
||||
self.lower_ty_param(tp, add_bounds.get(&tp.id).map_or(&[][..], |x| &x))
|
||||
|
@ -204,11 +204,11 @@ pub struct AngleBracketedParameterData {
|
||||
/// The lifetime parameters for this path segment.
|
||||
pub lifetimes: Vec<Lifetime>,
|
||||
/// The type parameters for this path segment, if present.
|
||||
pub types: P<[P<Ty>]>,
|
||||
pub types: Vec<P<Ty>>,
|
||||
/// Bindings (equality constraints) on associated types, if present.
|
||||
///
|
||||
/// E.g., `Foo<A=Bar>`.
|
||||
pub bindings: P<[TypeBinding]>,
|
||||
pub bindings: Vec<TypeBinding>,
|
||||
}
|
||||
|
||||
impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData {
|
||||
@ -297,7 +297,7 @@ pub enum TraitBoundModifier {
|
||||
Maybe,
|
||||
}
|
||||
|
||||
pub type TyParamBounds = P<[TyParamBound]>;
|
||||
pub type TyParamBounds = Vec<TyParamBound>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct TyParam {
|
||||
@ -314,7 +314,7 @@ pub struct TyParam {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct Generics {
|
||||
pub lifetimes: Vec<LifetimeDef>,
|
||||
pub ty_params: P<[TyParam]>,
|
||||
pub ty_params: Vec<TyParam>,
|
||||
pub where_clause: WhereClause,
|
||||
pub span: Span,
|
||||
}
|
||||
@ -344,7 +344,7 @@ impl Default for Generics {
|
||||
fn default() -> Generics {
|
||||
Generics {
|
||||
lifetimes: Vec::new(),
|
||||
ty_params: P::new(),
|
||||
ty_params: Vec::new(),
|
||||
where_clause: WhereClause {
|
||||
id: DUMMY_NODE_ID,
|
||||
predicates: Vec::new(),
|
||||
|
@ -67,9 +67,6 @@ pub trait AstBuilder {
|
||||
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
|
||||
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
|
||||
|
||||
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
|
||||
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
|
||||
|
||||
fn typaram(&self,
|
||||
span: Span,
|
||||
id: ast::Ident,
|
||||
@ -333,8 +330,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
} else {
|
||||
Some(P(ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData {
|
||||
lifetimes: lifetimes,
|
||||
types: P::from_vec(types),
|
||||
bindings: P::from_vec(bindings),
|
||||
types: types,
|
||||
bindings: bindings,
|
||||
})))
|
||||
};
|
||||
segments.push(ast::PathSegment { identifier: last_identifier, parameters: parameters });
|
||||
@ -369,8 +366,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
let mut path = trait_path;
|
||||
let parameters = ast::AngleBracketedParameterData {
|
||||
lifetimes: lifetimes,
|
||||
types: P::from_vec(types),
|
||||
bindings: P::from_vec(bindings),
|
||||
types: types,
|
||||
bindings: bindings,
|
||||
};
|
||||
path.segments.push(ast::PathSegment {
|
||||
identifier: ident,
|
||||
@ -458,20 +455,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
// these are strange, and probably shouldn't be used outside of
|
||||
// pipes. Specifically, the global version possible generates
|
||||
// incorrect code.
|
||||
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
|
||||
ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect()
|
||||
}
|
||||
|
||||
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
|
||||
ty_params
|
||||
.iter()
|
||||
.map(|p| self.ty_path(self.path_global(DUMMY_SP, vec![p.ident])))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
|
||||
ast::TraitRef {
|
||||
path: path,
|
||||
|
@ -225,7 +225,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: Vec<TyParam>) -> Vec<TyParam> {
|
||||
noop_fold_ty_params(tps, self)
|
||||
}
|
||||
|
||||
@ -674,8 +674,7 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>, fld: &mut T)
|
||||
-> P<[TyParam]> {
|
||||
pub fn noop_fold_ty_params<T: Folder>(tps: Vec<TyParam>, fld: &mut T) -> Vec<TyParam> {
|
||||
tps.move_map(|tp| fld.fold_ty_param(tp))
|
||||
}
|
||||
|
||||
|
@ -847,7 +847,7 @@ mod tests {
|
||||
Abi::Rust,
|
||||
ast::Generics{ // no idea on either of these:
|
||||
lifetimes: Vec::new(),
|
||||
ty_params: P::new(),
|
||||
ty_params: Vec::new(),
|
||||
where_clause: ast::WhereClause {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
predicates: Vec::new(),
|
||||
|
@ -685,7 +685,7 @@ impl<'a> Parser<'a> {
|
||||
pub fn parse_seq_to_before_gt_or_return<T, F>(&mut self,
|
||||
sep: Option<token::Token>,
|
||||
mut f: F)
|
||||
-> PResult<'a, (P<[T]>, bool)>
|
||||
-> PResult<'a, (Vec<T>, bool)>
|
||||
where F: FnMut(&mut Parser<'a>) -> PResult<'a, Option<T>>,
|
||||
{
|
||||
let mut v = Vec::new();
|
||||
@ -706,7 +706,7 @@ impl<'a> Parser<'a> {
|
||||
if i % 2 == 0 {
|
||||
match f(self)? {
|
||||
Some(result) => v.push(result),
|
||||
None => return Ok((P::from_vec(v), true))
|
||||
None => return Ok((v, true))
|
||||
}
|
||||
} else {
|
||||
if let Some(t) = sep.as_ref() {
|
||||
@ -715,7 +715,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
}
|
||||
}
|
||||
return Ok((P::from_vec(v), false));
|
||||
return Ok((v, false));
|
||||
}
|
||||
|
||||
/// Parse a sequence bracketed by '<' and '>', stopping
|
||||
@ -723,7 +723,7 @@ impl<'a> Parser<'a> {
|
||||
pub fn parse_seq_to_before_gt<T, F>(&mut self,
|
||||
sep: Option<token::Token>,
|
||||
mut f: F)
|
||||
-> PResult<'a, P<[T]>> where
|
||||
-> PResult<'a, Vec<T>> where
|
||||
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
|
||||
{
|
||||
let (result, returned) = self.parse_seq_to_before_gt_or_return(sep,
|
||||
@ -735,7 +735,7 @@ impl<'a> Parser<'a> {
|
||||
pub fn parse_seq_to_gt<T, F>(&mut self,
|
||||
sep: Option<token::Token>,
|
||||
f: F)
|
||||
-> PResult<'a, P<[T]>> where
|
||||
-> PResult<'a, Vec<T>> where
|
||||
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
|
||||
{
|
||||
let v = self.parse_seq_to_before_gt(sep, f)?;
|
||||
@ -746,7 +746,7 @@ impl<'a> Parser<'a> {
|
||||
pub fn parse_seq_to_gt_or_return<T, F>(&mut self,
|
||||
sep: Option<token::Token>,
|
||||
f: F)
|
||||
-> PResult<'a, (P<[T]>, bool)> where
|
||||
-> PResult<'a, (Vec<T>, bool)> where
|
||||
F: FnMut(&mut Parser<'a>) -> PResult<'a, Option<T>>,
|
||||
{
|
||||
let (v, returned) = self.parse_seq_to_before_gt_or_return(sep, f)?;
|
||||
@ -1039,11 +1039,11 @@ impl<'a> Parser<'a> {
|
||||
let other_bounds = if self.eat(&token::BinOp(token::Plus)) {
|
||||
self.parse_ty_param_bounds()?
|
||||
} else {
|
||||
P::new()
|
||||
Vec::new()
|
||||
};
|
||||
let all_bounds =
|
||||
Some(TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)).into_iter()
|
||||
.chain(other_bounds.into_vec())
|
||||
.chain(other_bounds)
|
||||
.collect();
|
||||
Ok(ast::TyKind::ObjectSum(all_bounds))
|
||||
}
|
||||
@ -1267,7 +1267,7 @@ impl<'a> Parser<'a> {
|
||||
return Ok(lhs);
|
||||
}
|
||||
|
||||
let mut bounds = self.parse_ty_param_bounds()?.into_vec();
|
||||
let mut bounds = self.parse_ty_param_bounds()?;
|
||||
|
||||
// In type grammar, `+` is treated like a binary operator,
|
||||
// and hence both L and R side are required.
|
||||
@ -1327,7 +1327,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
let sp = mk_sp(lo, self.prev_span.hi);
|
||||
let sum = TyKind::ObjectSum(bounds.into());
|
||||
let sum = TyKind::ObjectSum(bounds);
|
||||
Ok(P(Ty {id: ast::DUMMY_NODE_ID, node: sum, span: sp}))
|
||||
}
|
||||
|
||||
@ -1759,8 +1759,8 @@ impl<'a> Parser<'a> {
|
||||
let (lifetimes, types, bindings) = self.parse_generic_values_after_lt()?;
|
||||
ast::AngleBracketedParameterData {
|
||||
lifetimes: lifetimes,
|
||||
types: P::from_vec(types),
|
||||
bindings: P::from_vec(bindings),
|
||||
types: types,
|
||||
bindings: bindings,
|
||||
}.into()
|
||||
} else if self.eat(&token::OpenDelim(token::Paren)) {
|
||||
let lo = self.prev_span.lo;
|
||||
@ -1819,8 +1819,8 @@ impl<'a> Parser<'a> {
|
||||
identifier: identifier,
|
||||
parameters: ast::AngleBracketedParameterData {
|
||||
lifetimes: lifetimes,
|
||||
types: P::from_vec(types),
|
||||
bindings: P::from_vec(bindings),
|
||||
types: types,
|
||||
bindings: bindings,
|
||||
}.into(),
|
||||
});
|
||||
|
||||
@ -4192,7 +4192,7 @@ impl<'a> Parser<'a> {
|
||||
fn parse_colon_then_ty_param_bounds(&mut self) -> PResult<'a, TyParamBounds>
|
||||
{
|
||||
if !self.eat(&token::Colon) {
|
||||
Ok(P::new())
|
||||
Ok(Vec::new())
|
||||
} else {
|
||||
self.parse_ty_param_bounds()
|
||||
}
|
||||
@ -4238,7 +4238,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(P::from_vec(result));
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )?
|
||||
@ -4375,7 +4375,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
// If we found the `>`, don't continue.
|
||||
if !returned {
|
||||
return Ok((lifetimes, types.into_vec(), Vec::new()));
|
||||
return Ok((lifetimes, types, Vec::new()));
|
||||
}
|
||||
|
||||
// Then parse type bindings.
|
||||
@ -4396,7 +4396,7 @@ impl<'a> Parser<'a> {
|
||||
});
|
||||
}
|
||||
)?;
|
||||
Ok((lifetimes, types.into_vec(), bindings.into_vec()))
|
||||
Ok((lifetimes, types, bindings))
|
||||
}
|
||||
|
||||
fn forbid_lifetime(&mut self) -> PResult<'a, ()> {
|
||||
|
@ -1009,7 +1009,7 @@ impl<'a> State<'a> {
|
||||
ast::TyKind::BareFn(ref f) => {
|
||||
let generics = ast::Generics {
|
||||
lifetimes: f.lifetimes.clone(),
|
||||
ty_params: P::new(),
|
||||
ty_params: Vec::new(),
|
||||
where_clause: ast::WhereClause {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
predicates: Vec::new(),
|
||||
@ -2973,7 +2973,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
let generics = ast::Generics {
|
||||
lifetimes: Vec::new(),
|
||||
ty_params: P::new(),
|
||||
ty_params: Vec::new(),
|
||||
where_clause: ast::WhereClause {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
predicates: Vec::new(),
|
||||
|
@ -507,9 +507,8 @@ impl<'a> TraitDef<'a> {
|
||||
}
|
||||
});
|
||||
|
||||
let Generics { mut lifetimes, ty_params, mut where_clause, span } = self.generics
|
||||
let Generics { mut lifetimes, mut ty_params, mut where_clause, span } = self.generics
|
||||
.to_generics(cx, self.span, type_ident, generics);
|
||||
let mut ty_params = ty_params.into_vec();
|
||||
|
||||
// Copy the lifetimes
|
||||
lifetimes.extend(generics.lifetimes.iter().cloned());
|
||||
@ -533,7 +532,7 @@ impl<'a> TraitDef<'a> {
|
||||
bounds.push((*declared_bound).clone());
|
||||
}
|
||||
|
||||
cx.typaram(self.span, ty_param.ident, vec![], P::from_vec(bounds), None)
|
||||
cx.typaram(self.span, ty_param.ident, vec![], bounds, None)
|
||||
}));
|
||||
|
||||
// and similarly for where clauses
|
||||
@ -596,7 +595,7 @@ impl<'a> TraitDef<'a> {
|
||||
span: self.span,
|
||||
bound_lifetimes: vec![],
|
||||
bounded_ty: ty,
|
||||
bounds: P::from_vec(bounds),
|
||||
bounds: bounds,
|
||||
};
|
||||
|
||||
let predicate = ast::WherePredicate::BoundPredicate(predicate);
|
||||
@ -607,7 +606,7 @@ impl<'a> TraitDef<'a> {
|
||||
|
||||
let trait_generics = Generics {
|
||||
lifetimes: lifetimes,
|
||||
ty_params: P::from_vec(ty_params),
|
||||
ty_params: ty_params,
|
||||
where_clause: where_clause,
|
||||
span: span,
|
||||
};
|
||||
|
@ -212,7 +212,7 @@ fn mk_generics(lifetimes: Vec<ast::LifetimeDef>, ty_params: Vec<ast::TyParam>, s
|
||||
-> Generics {
|
||||
Generics {
|
||||
lifetimes: lifetimes,
|
||||
ty_params: P::from_vec(ty_params),
|
||||
ty_params: ty_params,
|
||||
where_clause: ast::WhereClause {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
predicates: Vec::new(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user