Skip to content

Commit 03620db

Browse files
committed
Use resizable Vec instead of P<[T]> in AST
1 parent 2efe865 commit 03620db

File tree

9 files changed

+38
-57
lines changed

9 files changed

+38
-57
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl<'a> LoweringContext<'a> {
596596
}
597597
}
598598

599-
fn lower_ty_params(&mut self, tps: &P<[TyParam]>, add_bounds: &NodeMap<Vec<TyParamBound>>)
599+
fn lower_ty_params(&mut self, tps: &Vec<TyParam>, add_bounds: &NodeMap<Vec<TyParamBound>>)
600600
-> hir::HirVec<hir::TyParam> {
601601
tps.iter().map(|tp| {
602602
self.lower_ty_param(tp, add_bounds.get(&tp.id).map_or(&[][..], |x| &x))

src/libsyntax/ast.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ pub struct AngleBracketedParameterData {
204204
/// The lifetime parameters for this path segment.
205205
pub lifetimes: Vec<Lifetime>,
206206
/// The type parameters for this path segment, if present.
207-
pub types: P<[P<Ty>]>,
207+
pub types: Vec<P<Ty>>,
208208
/// Bindings (equality constraints) on associated types, if present.
209209
///
210210
/// E.g., `Foo<A=Bar>`.
211-
pub bindings: P<[TypeBinding]>,
211+
pub bindings: Vec<TypeBinding>,
212212
}
213213

214214
impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData {
@@ -297,7 +297,7 @@ pub enum TraitBoundModifier {
297297
Maybe,
298298
}
299299

300-
pub type TyParamBounds = P<[TyParamBound]>;
300+
pub type TyParamBounds = Vec<TyParamBound>;
301301

302302
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
303303
pub struct TyParam {
@@ -314,7 +314,7 @@ pub struct TyParam {
314314
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
315315
pub struct Generics {
316316
pub lifetimes: Vec<LifetimeDef>,
317-
pub ty_params: P<[TyParam]>,
317+
pub ty_params: Vec<TyParam>,
318318
pub where_clause: WhereClause,
319319
pub span: Span,
320320
}
@@ -344,7 +344,7 @@ impl Default for Generics {
344344
fn default() -> Generics {
345345
Generics {
346346
lifetimes: Vec::new(),
347-
ty_params: P::new(),
347+
ty_params: Vec::new(),
348348
where_clause: WhereClause {
349349
id: DUMMY_NODE_ID,
350350
predicates: Vec::new(),

src/libsyntax/ext/build.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ pub trait AstBuilder {
6767
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
6868
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
6969

70-
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
71-
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
72-
7370
fn typaram(&self,
7471
span: Span,
7572
id: ast::Ident,
@@ -333,8 +330,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
333330
} else {
334331
Some(P(ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData {
335332
lifetimes: lifetimes,
336-
types: P::from_vec(types),
337-
bindings: P::from_vec(bindings),
333+
types: types,
334+
bindings: bindings,
338335
})))
339336
};
340337
segments.push(ast::PathSegment { identifier: last_identifier, parameters: parameters });
@@ -369,8 +366,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
369366
let mut path = trait_path;
370367
let parameters = ast::AngleBracketedParameterData {
371368
lifetimes: lifetimes,
372-
types: P::from_vec(types),
373-
bindings: P::from_vec(bindings),
369+
types: types,
370+
bindings: bindings,
374371
};
375372
path.segments.push(ast::PathSegment {
376373
identifier: ident,
@@ -458,20 +455,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
458455
}
459456
}
460457

461-
// these are strange, and probably shouldn't be used outside of
462-
// pipes. Specifically, the global version possible generates
463-
// incorrect code.
464-
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
465-
ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect()
466-
}
467-
468-
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
469-
ty_params
470-
.iter()
471-
.map(|p| self.ty_path(self.path_global(DUMMY_SP, vec![p.ident])))
472-
.collect()
473-
}
474-
475458
fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
476459
ast::TraitRef {
477460
path: path,

src/libsyntax/fold.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub trait Folder : Sized {
225225
noop_fold_ty_param(tp, self)
226226
}
227227

228-
fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> {
228+
fn fold_ty_params(&mut self, tps: Vec<TyParam>) -> Vec<TyParam> {
229229
noop_fold_ty_params(tps, self)
230230
}
231231

@@ -674,8 +674,7 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
674674
}
675675
}
676676

677-
pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>, fld: &mut T)
678-
-> P<[TyParam]> {
677+
pub fn noop_fold_ty_params<T: Folder>(tps: Vec<TyParam>, fld: &mut T) -> Vec<TyParam> {
679678
tps.move_map(|tp| fld.fold_ty_param(tp))
680679
}
681680

src/libsyntax/parse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ mod tests {
847847
Abi::Rust,
848848
ast::Generics{ // no idea on either of these:
849849
lifetimes: Vec::new(),
850-
ty_params: P::new(),
850+
ty_params: Vec::new(),
851851
where_clause: ast::WhereClause {
852852
id: ast::DUMMY_NODE_ID,
853853
predicates: Vec::new(),

src/libsyntax/parse/parser.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ impl<'a> Parser<'a> {
685685
pub fn parse_seq_to_before_gt_or_return<T, F>(&mut self,
686686
sep: Option<token::Token>,
687687
mut f: F)
688-
-> PResult<'a, (P<[T]>, bool)>
688+
-> PResult<'a, (Vec<T>, bool)>
689689
where F: FnMut(&mut Parser<'a>) -> PResult<'a, Option<T>>,
690690
{
691691
let mut v = Vec::new();
@@ -706,7 +706,7 @@ impl<'a> Parser<'a> {
706706
if i % 2 == 0 {
707707
match f(self)? {
708708
Some(result) => v.push(result),
709-
None => return Ok((P::from_vec(v), true))
709+
None => return Ok((v, true))
710710
}
711711
} else {
712712
if let Some(t) = sep.as_ref() {
@@ -715,15 +715,15 @@ impl<'a> Parser<'a> {
715715

716716
}
717717
}
718-
return Ok((P::from_vec(v), false));
718+
return Ok((v, false));
719719
}
720720

721721
/// Parse a sequence bracketed by '<' and '>', stopping
722722
/// before the '>'.
723723
pub fn parse_seq_to_before_gt<T, F>(&mut self,
724724
sep: Option<token::Token>,
725725
mut f: F)
726-
-> PResult<'a, P<[T]>> where
726+
-> PResult<'a, Vec<T>> where
727727
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
728728
{
729729
let (result, returned) = self.parse_seq_to_before_gt_or_return(sep,
@@ -735,7 +735,7 @@ impl<'a> Parser<'a> {
735735
pub fn parse_seq_to_gt<T, F>(&mut self,
736736
sep: Option<token::Token>,
737737
f: F)
738-
-> PResult<'a, P<[T]>> where
738+
-> PResult<'a, Vec<T>> where
739739
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
740740
{
741741
let v = self.parse_seq_to_before_gt(sep, f)?;
@@ -746,7 +746,7 @@ impl<'a> Parser<'a> {
746746
pub fn parse_seq_to_gt_or_return<T, F>(&mut self,
747747
sep: Option<token::Token>,
748748
f: F)
749-
-> PResult<'a, (P<[T]>, bool)> where
749+
-> PResult<'a, (Vec<T>, bool)> where
750750
F: FnMut(&mut Parser<'a>) -> PResult<'a, Option<T>>,
751751
{
752752
let (v, returned) = self.parse_seq_to_before_gt_or_return(sep, f)?;
@@ -1039,11 +1039,11 @@ impl<'a> Parser<'a> {
10391039
let other_bounds = if self.eat(&token::BinOp(token::Plus)) {
10401040
self.parse_ty_param_bounds()?
10411041
} else {
1042-
P::new()
1042+
Vec::new()
10431043
};
10441044
let all_bounds =
10451045
Some(TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)).into_iter()
1046-
.chain(other_bounds.into_vec())
1046+
.chain(other_bounds)
10471047
.collect();
10481048
Ok(ast::TyKind::ObjectSum(all_bounds))
10491049
}
@@ -1267,7 +1267,7 @@ impl<'a> Parser<'a> {
12671267
return Ok(lhs);
12681268
}
12691269

1270-
let mut bounds = self.parse_ty_param_bounds()?.into_vec();
1270+
let mut bounds = self.parse_ty_param_bounds()?;
12711271

12721272
// In type grammar, `+` is treated like a binary operator,
12731273
// and hence both L and R side are required.
@@ -1327,7 +1327,7 @@ impl<'a> Parser<'a> {
13271327
}
13281328

13291329
let sp = mk_sp(lo, self.prev_span.hi);
1330-
let sum = TyKind::ObjectSum(bounds.into());
1330+
let sum = TyKind::ObjectSum(bounds);
13311331
Ok(P(Ty {id: ast::DUMMY_NODE_ID, node: sum, span: sp}))
13321332
}
13331333

@@ -1759,8 +1759,8 @@ impl<'a> Parser<'a> {
17591759
let (lifetimes, types, bindings) = self.parse_generic_values_after_lt()?;
17601760
ast::AngleBracketedParameterData {
17611761
lifetimes: lifetimes,
1762-
types: P::from_vec(types),
1763-
bindings: P::from_vec(bindings),
1762+
types: types,
1763+
bindings: bindings,
17641764
}.into()
17651765
} else if self.eat(&token::OpenDelim(token::Paren)) {
17661766
let lo = self.prev_span.lo;
@@ -1819,8 +1819,8 @@ impl<'a> Parser<'a> {
18191819
identifier: identifier,
18201820
parameters: ast::AngleBracketedParameterData {
18211821
lifetimes: lifetimes,
1822-
types: P::from_vec(types),
1823-
bindings: P::from_vec(bindings),
1822+
types: types,
1823+
bindings: bindings,
18241824
}.into(),
18251825
});
18261826

@@ -4192,7 +4192,7 @@ impl<'a> Parser<'a> {
41924192
fn parse_colon_then_ty_param_bounds(&mut self) -> PResult<'a, TyParamBounds>
41934193
{
41944194
if !self.eat(&token::Colon) {
4195-
Ok(P::new())
4195+
Ok(Vec::new())
41964196
} else {
41974197
self.parse_ty_param_bounds()
41984198
}
@@ -4238,7 +4238,7 @@ impl<'a> Parser<'a> {
42384238
}
42394239
}
42404240

4241-
return Ok(P::from_vec(result));
4241+
return Ok(result);
42424242
}
42434243

42444244
/// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )?
@@ -4375,7 +4375,7 @@ impl<'a> Parser<'a> {
43754375

43764376
// If we found the `>`, don't continue.
43774377
if !returned {
4378-
return Ok((lifetimes, types.into_vec(), Vec::new()));
4378+
return Ok((lifetimes, types, Vec::new()));
43794379
}
43804380

43814381
// Then parse type bindings.
@@ -4396,7 +4396,7 @@ impl<'a> Parser<'a> {
43964396
});
43974397
}
43984398
)?;
4399-
Ok((lifetimes, types.into_vec(), bindings.into_vec()))
4399+
Ok((lifetimes, types, bindings))
44004400
}
44014401

44024402
fn forbid_lifetime(&mut self) -> PResult<'a, ()> {

src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ impl<'a> State<'a> {
10091009
ast::TyKind::BareFn(ref f) => {
10101010
let generics = ast::Generics {
10111011
lifetimes: f.lifetimes.clone(),
1012-
ty_params: P::new(),
1012+
ty_params: Vec::new(),
10131013
where_clause: ast::WhereClause {
10141014
id: ast::DUMMY_NODE_ID,
10151015
predicates: Vec::new(),
@@ -2973,7 +2973,7 @@ impl<'a> State<'a> {
29732973
}
29742974
let generics = ast::Generics {
29752975
lifetimes: Vec::new(),
2976-
ty_params: P::new(),
2976+
ty_params: Vec::new(),
29772977
where_clause: ast::WhereClause {
29782978
id: ast::DUMMY_NODE_ID,
29792979
predicates: Vec::new(),

src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,8 @@ impl<'a> TraitDef<'a> {
507507
}
508508
});
509509

510-
let Generics { mut lifetimes, ty_params, mut where_clause, span } = self.generics
510+
let Generics { mut lifetimes, mut ty_params, mut where_clause, span } = self.generics
511511
.to_generics(cx, self.span, type_ident, generics);
512-
let mut ty_params = ty_params.into_vec();
513512

514513
// Copy the lifetimes
515514
lifetimes.extend(generics.lifetimes.iter().cloned());
@@ -533,7 +532,7 @@ impl<'a> TraitDef<'a> {
533532
bounds.push((*declared_bound).clone());
534533
}
535534

536-
cx.typaram(self.span, ty_param.ident, vec![], P::from_vec(bounds), None)
535+
cx.typaram(self.span, ty_param.ident, vec![], bounds, None)
537536
}));
538537

539538
// and similarly for where clauses
@@ -596,7 +595,7 @@ impl<'a> TraitDef<'a> {
596595
span: self.span,
597596
bound_lifetimes: vec![],
598597
bounded_ty: ty,
599-
bounds: P::from_vec(bounds),
598+
bounds: bounds,
600599
};
601600

602601
let predicate = ast::WherePredicate::BoundPredicate(predicate);
@@ -607,7 +606,7 @@ impl<'a> TraitDef<'a> {
607606

608607
let trait_generics = Generics {
609608
lifetimes: lifetimes,
610-
ty_params: P::from_vec(ty_params),
609+
ty_params: ty_params,
611610
where_clause: where_clause,
612611
span: span,
613612
};

src/libsyntax_ext/deriving/generic/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn mk_generics(lifetimes: Vec<ast::LifetimeDef>, ty_params: Vec<ast::TyParam>, s
212212
-> Generics {
213213
Generics {
214214
lifetimes: lifetimes,
215-
ty_params: P::from_vec(ty_params),
215+
ty_params: ty_params,
216216
where_clause: ast::WhereClause {
217217
id: ast::DUMMY_NODE_ID,
218218
predicates: Vec::new(),

0 commit comments

Comments
 (0)