1
Fork 0

Changed lists of lifetimes in ast and ty to use Vec instead of OptVec.

There is a broader revision (that does this across the board) pending
in #12675, but that is awaiting the arrival of more data (to decide
whether to keep OptVec alive by using a non-Vec internally).

For this code, the representation of lifetime lists needs to be the
same in both ScopeChain and in the ast and ty structures.  So it
seemed cleanest to just use `vec_ng::Vec`, now that it has a cheaper
empty representation than the current `vec` code.
This commit is contained in:
Felix S. Klock II 2014-03-07 16:50:40 +01:00
parent 28ebec5160
commit 586b619c76
19 changed files with 72 additions and 71 deletions

View file

@ -164,12 +164,12 @@ impl fold::Folder for PreludeInjector {
segments: vec!( segments: vec!(
ast::PathSegment { ast::PathSegment {
identifier: token::str_to_ident("std"), identifier: token::str_to_ident("std"),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
}, },
ast::PathSegment { ast::PathSegment {
identifier: token::str_to_ident("prelude"), identifier: token::str_to_ident("prelude"),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
}), }),
}; };

View file

@ -369,7 +369,7 @@ fn path_node(ids: Vec<ast::Ident> ) -> ast::Path {
global: false, global: false,
segments: ids.move_iter().map(|identifier| ast::PathSegment { segments: ids.move_iter().map(|identifier| ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
}).collect() }).collect()
} }
@ -381,7 +381,7 @@ fn path_node_global(ids: Vec<ast::Ident> ) -> ast::Path {
global: true, global: true,
segments: ids.move_iter().map(|identifier| ast::PathSegment { segments: ids.move_iter().map(|identifier| ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
}).collect() }).collect()
} }

View file

@ -13,6 +13,7 @@
//! which are available for use externally when compiled as a library. //! which are available for use externally when compiled as a library.
use std::mem::replace; use std::mem::replace;
use std::vec_ng::Vec;
use metadata::csearch; use metadata::csearch;
use middle::lint; use middle::lint;
@ -855,7 +856,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
debug!("privacy - list {}", pid.node.id); debug!("privacy - list {}", pid.node.id);
let seg = ast::PathSegment { let seg = ast::PathSegment {
identifier: pid.node.name, identifier: pid.node.name,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
}; };
let segs = vec!(seg); let segs = vec!(seg);

View file

@ -19,10 +19,10 @@
use driver::session; use driver::session;
use std::cell::RefCell; use std::cell::RefCell;
use std::vec_ng::Vec;
use util::nodemap::NodeMap; use util::nodemap::NodeMap;
use syntax::ast; use syntax::ast;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::opt_vec::OptVec;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
use syntax::parse::token; use syntax::parse::token;
use syntax::print::pprust::{lifetime_to_str}; use syntax::print::pprust::{lifetime_to_str};
@ -39,8 +39,8 @@ struct LifetimeContext {
} }
enum ScopeChain<'a> { enum ScopeChain<'a> {
ItemScope(&'a OptVec<ast::Lifetime>), ItemScope(&'a Vec<ast::Lifetime>),
FnScope(ast::NodeId, &'a OptVec<ast::Lifetime>, Scope<'a>), FnScope(ast::NodeId, &'a Vec<ast::Lifetime>, Scope<'a>),
BlockScope(ast::NodeId, Scope<'a>), BlockScope(ast::NodeId, Scope<'a>),
RootScope RootScope
} }
@ -267,7 +267,7 @@ impl LifetimeContext {
token::get_name(lifetime_ref.name))); token::get_name(lifetime_ref.name)));
} }
fn check_lifetime_names(&self, lifetimes: &OptVec<ast::Lifetime>) { fn check_lifetime_names(&self, lifetimes: &Vec<ast::Lifetime>) {
for i in range(0, lifetimes.len()) { for i in range(0, lifetimes.len()) {
let lifetime_i = lifetimes.get(i); let lifetime_i = lifetimes.get(i);
@ -313,7 +313,7 @@ impl LifetimeContext {
} }
} }
fn search_lifetimes(lifetimes: &OptVec<ast::Lifetime>, fn search_lifetimes(lifetimes: &Vec<ast::Lifetime>,
lifetime_ref: &ast::Lifetime) lifetime_ref: &ast::Lifetime)
-> Option<(uint, ast::NodeId)> { -> Option<(uint, ast::NodeId)> {
for (i, lifetime_decl) in lifetimes.iter().enumerate() { for (i, lifetime_decl) in lifetimes.iter().enumerate() {

View file

@ -540,7 +540,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
return FunctionWithoutDebugInfo; return FunctionWithoutDebugInfo;
} }
let empty_generics = ast::Generics { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty }; let empty_generics = ast::Generics { lifetimes: Vec::new(), ty_params: opt_vec::Empty };
let fnitem = cx.tcx.map.get(fn_ast_id); let fnitem = cx.tcx.map.get(fn_ast_id);

View file

@ -186,9 +186,9 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
} }
match anon_regions { match anon_regions {
Ok(v) => opt_vec::from(v.move_iter().collect()), Ok(v) => v.move_iter().collect(),
Err(()) => opt_vec::from(Vec::from_fn(expected_num_region_params, Err(()) => Vec::from_fn(expected_num_region_params,
|_| ty::ReStatic)) // hokey |_| ty::ReStatic) // hokey
} }
}; };
@ -231,7 +231,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
.collect(); .collect();
let mut substs = substs { let mut substs = substs {
regions: ty::NonerasedRegions(regions), regions: ty::NonerasedRegions(opt_vec::from(regions)),
self_ty: self_ty, self_ty: self_ty,
tps: tps tps: tps
}; };

View file

@ -1453,8 +1453,7 @@ pub fn impl_self_ty(vcx: &VtableContext,
let tps = vcx.infcx.next_ty_vars(n_tps); let tps = vcx.infcx.next_ty_vars(n_tps);
let substs = substs { let substs = substs {
regions: ty::NonerasedRegions(opt_vec::from(rps.move_iter() regions: ty::NonerasedRegions(opt_vec::from(rps.move_iter().collect())),
.collect())),
self_ty: None, self_ty: None,
tps: tps, tps: tps,
}; };
@ -3741,11 +3740,11 @@ pub fn instantiate_path(fcx: @FnCtxt,
nsupplied = num_supplied_regions)); nsupplied = num_supplied_regions));
} }
opt_vec::from(fcx.infcx().next_region_vars( fcx.infcx().next_region_vars(
infer::BoundRegionInTypeOrImpl(span), infer::BoundRegionInTypeOrImpl(span),
num_expected_regions).move_iter().collect()) num_expected_regions).move_iter().collect()
}; };
let regions = ty::NonerasedRegions(regions); let regions = ty::NonerasedRegions(opt_vec::from(regions));
// Special case: If there is a self parameter, omit it from the list of // Special case: If there is a self parameter, omit it from the list of
// type parameters. // type parameters.

View file

@ -142,7 +142,7 @@ pub struct PathSegment {
/// The identifier portion of this path segment. /// The identifier portion of this path segment.
identifier: Ident, identifier: Ident,
/// The lifetime parameters for this path segment. /// The lifetime parameters for this path segment.
lifetimes: OptVec<Lifetime>, lifetimes: Vec<Lifetime>,
/// The type parameters for this path segment, if present. /// The type parameters for this path segment, if present.
types: OptVec<P<Ty>>, types: OptVec<P<Ty>>,
} }
@ -187,7 +187,7 @@ pub struct TyParam {
#[deriving(Clone, Eq, Encodable, Decodable, Hash)] #[deriving(Clone, Eq, Encodable, Decodable, Hash)]
pub struct Generics { pub struct Generics {
lifetimes: OptVec<Lifetime>, lifetimes: Vec<Lifetime>,
ty_params: OptVec<TyParam>, ty_params: OptVec<TyParam>,
} }
@ -795,7 +795,7 @@ impl fmt::Show for Onceness {
pub struct ClosureTy { pub struct ClosureTy {
sigil: Sigil, sigil: Sigil,
region: Option<Lifetime>, region: Option<Lifetime>,
lifetimes: OptVec<Lifetime>, lifetimes: Vec<Lifetime>,
purity: Purity, purity: Purity,
onceness: Onceness, onceness: Onceness,
decl: P<FnDecl>, decl: P<FnDecl>,
@ -810,7 +810,7 @@ pub struct ClosureTy {
pub struct BareFnTy { pub struct BareFnTy {
purity: Purity, purity: Purity,
abis: AbiSet, abis: AbiSet,
lifetimes: OptVec<Lifetime>, lifetimes: Vec<Lifetime>,
decl: P<FnDecl> decl: P<FnDecl>
} }

View file

@ -195,7 +195,7 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
segments: vec!( segments: vec!(
ast::PathSegment { ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
), ),
@ -311,7 +311,7 @@ pub fn operator_prec(op: ast::BinOp) -> uint {
pub static as_prec: uint = 12u; pub static as_prec: uint = 12u;
pub fn empty_generics() -> Generics { pub fn empty_generics() -> Generics {
Generics {lifetimes: opt_vec::Empty, Generics {lifetimes: Vec::new(),
ty_params: opt_vec::Empty} ty_params: opt_vec::Empty}
} }
@ -690,10 +690,11 @@ mod test {
use ast::*; use ast::*;
use super::*; use super::*;
use opt_vec; use opt_vec;
use std::vec_ng::Vec;
fn ident_to_segment(id : &Ident) -> PathSegment { fn ident_to_segment(id : &Ident) -> PathSegment {
PathSegment {identifier:id.clone(), PathSegment {identifier:id.clone(),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty} types: opt_vec::Empty}
} }

View file

@ -42,7 +42,7 @@ pub trait AstBuilder {
fn path_all(&self, sp: Span, fn path_all(&self, sp: Span,
global: bool, global: bool,
idents: Vec<ast::Ident> , idents: Vec<ast::Ident> ,
lifetimes: OptVec<ast::Lifetime>, lifetimes: Vec<ast::Lifetime>,
types: Vec<P<ast::Ty>> ) types: Vec<P<ast::Ty>> )
-> ast::Path; -> ast::Path;
@ -255,19 +255,19 @@ pub trait AstBuilder {
impl<'a> AstBuilder for ExtCtxt<'a> { impl<'a> AstBuilder for ExtCtxt<'a> {
fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path { fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
self.path_all(span, false, strs, opt_vec::Empty, Vec::new()) self.path_all(span, false, strs, Vec::new(), Vec::new())
} }
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path { fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
self.path(span, vec!(id)) self.path(span, vec!(id))
} }
fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path { fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
self.path_all(span, true, strs, opt_vec::Empty, Vec::new()) self.path_all(span, true, strs, Vec::new(), Vec::new())
} }
fn path_all(&self, fn path_all(&self,
sp: Span, sp: Span,
global: bool, global: bool,
mut idents: Vec<ast::Ident> , mut idents: Vec<ast::Ident> ,
lifetimes: OptVec<ast::Lifetime>, lifetimes: Vec<ast::Lifetime>,
types: Vec<P<ast::Ty>> ) types: Vec<P<ast::Ty>> )
-> ast::Path { -> ast::Path {
let last_identifier = idents.pop().unwrap(); let last_identifier = idents.pop().unwrap();
@ -275,7 +275,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
.map(|ident| { .map(|ident| {
ast::PathSegment { ast::PathSegment {
identifier: ident, identifier: ident,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
}).collect(); }).collect();
@ -342,7 +342,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.ident_of("option"), self.ident_of("option"),
self.ident_of("Option") self.ident_of("Option")
), ),
opt_vec::Empty, Vec::new(),
vec!( ty )), None) vec!( ty )), None)
} }

View file

@ -15,6 +15,7 @@ use ext::base;
use opt_vec; use opt_vec;
use parse::token; use parse::token;
use parse::token::{str_to_ident}; use parse::token::{str_to_ident};
use std::vec_ng::Vec;
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult { -> base::MacResult {
@ -51,7 +52,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
segments: vec!( segments: vec!(
ast::PathSegment { ast::PathSegment {
identifier: res, identifier: res,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
) )

View file

@ -14,7 +14,6 @@ use codemap::Span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::build::{AstBuilder}; use ext::build::{AstBuilder};
use ext::deriving::generic::*; use ext::deriving::generic::*;
use opt_vec;
use std::vec_ng::Vec; use std::vec_ng::Vec;
@ -84,7 +83,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
let rand_name = cx.path_all(trait_span, let rand_name = cx.path_all(trait_span,
true, true,
rand_ident.clone(), rand_ident.clone(),
opt_vec::Empty, Vec::new(),
Vec::new()); Vec::new());
let rand_name = cx.expr_path(rand_name); let rand_name = cx.expr_path(rand_name);

View file

@ -19,7 +19,6 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use codemap::{Span,respan}; use codemap::{Span,respan};
use opt_vec; use opt_vec;
use opt_vec::OptVec;
use std::vec_ng::Vec; use std::vec_ng::Vec;
@ -118,11 +117,12 @@ fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifet
} }
} }
fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> { fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
match *lt { let lifetimes = match *lt {
Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s).name)), Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s).name)),
None => opt_vec::Empty None => opt_vec::Empty
} };
opt_vec::take_vec(lifetimes)
} }
impl<'a> Ty<'a> { impl<'a> Ty<'a> {
@ -199,7 +199,7 @@ fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, bounds: &[Path],
fn mk_generics(lifetimes: Vec<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics { fn mk_generics(lifetimes: Vec<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics {
Generics { Generics {
lifetimes: opt_vec::from(lifetimes), lifetimes: lifetimes,
ty_params: opt_vec::from(ty_params) ty_params: opt_vec::from(ty_params)
} }
} }

View file

@ -19,10 +19,10 @@ use codemap::Span;
use ext::base::*; use ext::base::*;
use ext::base; use ext::base;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use opt_vec;
use parse::token; use parse::token;
use std::os; use std::os;
use std::vec_ng::Vec;
pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult { -> base::MacResult {
@ -38,7 +38,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
vec!(cx.ident_of("std"), vec!(cx.ident_of("std"),
cx.ident_of("option"), cx.ident_of("option"),
cx.ident_of("None")), cx.ident_of("None")),
opt_vec::Empty, Vec::new(),
vec!(cx.ty_rptr(sp, vec!(cx.ty_rptr(sp,
cx.ty_ident(sp, cx.ty_ident(sp,
cx.ident_of("str")), cx.ident_of("str")),

View file

@ -14,7 +14,6 @@ use codemap::{Span, respan};
use ext::base::*; use ext::base::*;
use ext::base; use ext::base;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use opt_vec;
use parse::token::InternedString; use parse::token::InternedString;
use parse::token; use parse::token;
use rsparse = parse; use rsparse = parse;
@ -509,7 +508,7 @@ impl<'a> Context<'a> {
sp, sp,
true, true,
self.rtpath("Method"), self.rtpath("Method"),
opt_vec::with(life), vec!(life),
Vec::new() Vec::new()
), None); ), None);
let st = ast::ItemStatic(ty, ast::MutImmutable, method); let st = ast::ItemStatic(ty, ast::MutImmutable, method);
@ -632,8 +631,8 @@ impl<'a> Context<'a> {
self.ecx.ident_of("fmt"), self.ecx.ident_of("fmt"),
self.ecx.ident_of("rt"), self.ecx.ident_of("rt"),
self.ecx.ident_of("Piece")), self.ecx.ident_of("Piece")),
opt_vec::with( vec!(self.ecx.lifetime(self.fmtsp,
self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static").name)), self.ecx.ident_of("static").name)),
Vec::new() Vec::new()
), None); ), None);
let ty = ast::TyFixedLengthVec( let ty = ast::TyFixedLengthVec(

View file

@ -439,8 +439,8 @@ pub fn fold_lifetime<T: Folder>(l: &Lifetime, fld: &mut T) -> Lifetime {
} }
} }
pub fn fold_lifetimes<T: Folder>(lts: &OptVec<Lifetime>, fld: &mut T) pub fn fold_lifetimes<T: Folder>(lts: &Vec<Lifetime>, fld: &mut T)
-> OptVec<Lifetime> { -> Vec<Lifetime> {
lts.map(|l| fold_lifetime(l, fld)) lts.map(|l| fold_lifetime(l, fld))
} }

View file

@ -556,7 +556,7 @@ mod test {
segments: vec!( segments: vec!(
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("d"), identifier: str_to_ident("d"),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
), ),
@ -578,7 +578,7 @@ mod test {
segments: vec!( segments: vec!(
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("b"), identifier: str_to_ident("b"),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
), ),
@ -605,7 +605,7 @@ mod test {
segments: vec!( segments: vec!(
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("b"), identifier: str_to_ident("b"),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
), ),
@ -633,7 +633,7 @@ mod test {
ast::PathSegment { ast::PathSegment {
identifier: identifier:
str_to_ident("int"), str_to_ident("int"),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
), ),
@ -651,7 +651,7 @@ mod test {
ast::PathSegment { ast::PathSegment {
identifier: identifier:
str_to_ident("b"), str_to_ident("b"),
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
), ),
@ -671,7 +671,7 @@ mod test {
ast::ImpureFn, ast::ImpureFn,
abi::AbiSet::Rust(), abi::AbiSet::Rust(),
ast::Generics{ // no idea on either of these: ast::Generics{ // no idea on either of these:
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
ty_params: opt_vec::Empty, ty_params: opt_vec::Empty,
}, },
ast::P(ast::Block { ast::P(ast::Block {
@ -689,7 +689,7 @@ mod test {
str_to_ident( str_to_ident(
"b"), "b"),
lifetimes: lifetimes:
opt_vec::Empty, Vec::new(),
types: types:
opt_vec::Empty opt_vec::Empty
} }

View file

@ -958,7 +958,7 @@ impl Parser {
lifetimes lifetimes
} else { } else {
opt_vec::Empty Vec::new()
}; };
let inputs = if self.eat(&token::OROR) { let inputs = if self.eat(&token::OROR) {
@ -1015,7 +1015,7 @@ impl Parser {
// parse a function type (following the 'fn') // parse a function type (following the 'fn')
pub fn parse_ty_fn_decl(&mut self, allow_variadic: bool) pub fn parse_ty_fn_decl(&mut self, allow_variadic: bool)
-> (P<FnDecl>, OptVec<ast::Lifetime>) { -> (P<FnDecl>, Vec<ast::Lifetime>) {
/* /*
(fn) <'lt> (S) -> T (fn) <'lt> (S) -> T
@ -1031,7 +1031,7 @@ impl Parser {
self.expect_gt(); self.expect_gt();
lifetimes lifetimes
} else { } else {
opt_vec::Empty Vec::new()
}; };
let (inputs, variadic) = self.parse_fn_args(false, allow_variadic); let (inputs, variadic) = self.parse_fn_args(false, allow_variadic);
@ -1510,7 +1510,7 @@ impl Parser {
segments.push(PathSegmentAndBoundSet { segments.push(PathSegmentAndBoundSet {
segment: ast::PathSegment { segment: ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
}, },
bound_set: bound_set bound_set: bound_set
@ -1525,7 +1525,7 @@ impl Parser {
self.parse_generic_values_after_lt(); self.parse_generic_values_after_lt();
(true, lifetimes, opt_vec::from(types)) (true, lifetimes, opt_vec::from(types))
} else { } else {
(false, opt_vec::Empty, opt_vec::Empty) (false, Vec::new(), opt_vec::Empty)
} }
}; };
@ -1621,7 +1621,7 @@ impl Parser {
// matches lifetimes = ( lifetime ) | ( lifetime , lifetimes ) // matches lifetimes = ( lifetime ) | ( lifetime , lifetimes )
// actually, it matches the empty one too, but putting that in there // actually, it matches the empty one too, but putting that in there
// messes up the grammar.... // messes up the grammar....
pub fn parse_lifetimes(&mut self) -> OptVec<ast::Lifetime> { pub fn parse_lifetimes(&mut self) -> Vec<ast::Lifetime> {
/*! /*!
* *
* Parses zero or more comma separated lifetimes. * Parses zero or more comma separated lifetimes.
@ -1630,7 +1630,7 @@ impl Parser {
* lists, where we expect something like `<'a, 'b, T>`. * lists, where we expect something like `<'a, 'b, T>`.
*/ */
let mut res = opt_vec::Empty; let mut res = Vec::new();
loop { loop {
match self.token { match self.token {
token::LIFETIME(_) => { token::LIFETIME(_) => {
@ -1995,7 +1995,7 @@ impl Parser {
self.expect(&token::LT); self.expect(&token::LT);
self.parse_generic_values_after_lt() self.parse_generic_values_after_lt()
} else { } else {
(opt_vec::Empty, Vec::new()) (Vec::new(), Vec::new())
}; };
// expr.f() method call // expr.f() method call
@ -3515,7 +3515,7 @@ impl Parser {
} }
} }
fn parse_generic_values_after_lt(&mut self) -> (OptVec<ast::Lifetime>, Vec<P<Ty>> ) { fn parse_generic_values_after_lt(&mut self) -> (Vec<ast::Lifetime>, Vec<P<Ty>> ) {
let lifetimes = self.parse_lifetimes(); let lifetimes = self.parse_lifetimes();
let result = self.parse_seq_to_gt( let result = self.parse_seq_to_gt(
Some(token::COMMA), Some(token::COMMA),
@ -4886,7 +4886,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| { segments: path.move_iter().map(|identifier| {
ast::PathSegment { ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
}).collect() }).collect()
@ -4921,7 +4921,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| { segments: path.move_iter().map(|identifier| {
ast::PathSegment { ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
}).collect() }).collect()
@ -4939,7 +4939,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| { segments: path.move_iter().map(|identifier| {
ast::PathSegment { ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
}).collect() }).collect()
@ -4961,7 +4961,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| { segments: path.move_iter().map(|identifier| {
ast::PathSegment { ast::PathSegment {
identifier: identifier, identifier: identifier,
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
types: opt_vec::Empty, types: opt_vec::Empty,
} }
}).collect() }).collect()

View file

@ -15,6 +15,7 @@ use codemap::Span;
use parse; use parse;
use opt_vec; use opt_vec;
use opt_vec::OptVec; use opt_vec::OptVec;
use std::vec_ng::Vec;
// Context-passing AST walker. Each overridden visit method has full control // Context-passing AST walker. Each overridden visit method has full control
// over what happens with its node, it can do its own traversal of the node's // over what happens with its node, it can do its own traversal of the node's
@ -55,7 +56,7 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics {
} }
FkFnBlock(..) => { FkFnBlock(..) => {
Generics { Generics {
lifetimes: opt_vec::Empty, lifetimes: Vec::new(),
ty_params: opt_vec::Empty, ty_params: opt_vec::Empty,
} }
} }
@ -370,7 +371,7 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
} }
fn walk_lifetime_decls<E: Clone, V: Visitor<E>>(visitor: &mut V, fn walk_lifetime_decls<E: Clone, V: Visitor<E>>(visitor: &mut V,
lifetimes: &OptVec<Lifetime>, lifetimes: &Vec<Lifetime>,
env: E) { env: E) {
for l in lifetimes.iter() { for l in lifetimes.iter() {
visitor.visit_lifetime_decl(l, env.clone()); visitor.visit_lifetime_decl(l, env.clone());