diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 31 | ||||
| -rw-r--r-- | src/libsyntax/attr.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 68 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 41 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 49 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 35 | ||||
| -rw-r--r-- | src/libsyntax/show_span.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/tokenstream.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/util/node_count.rs | 68 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 199 |
14 files changed, 237 insertions, 333 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f8fd6eea211..c8ea514600e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -15,7 +15,7 @@ pub use self::UnsafeSource::*; pub use self::ViewPath_::*; pub use self::PathParameters::*; -use attr::{ThinAttributes, HasAttrs}; +use attr::ThinAttributes; use syntax_pos::{mk_sp, Span, DUMMY_SP, ExpnId}; use codemap::{respan, Spanned}; use abi::Abi; @@ -846,10 +846,6 @@ impl StmtKind { StmtKind::Mac(..) => None, } } - - pub fn attrs(&self) -> &[Attribute] { - HasAttrs::attrs(self) - } } #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -879,12 +875,6 @@ pub struct Local { pub attrs: ThinAttributes, } -impl Local { - pub fn attrs(&self) -> &[Attribute] { - HasAttrs::attrs(self) - } -} - pub type Decl = Spanned<DeclKind>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -895,12 +885,6 @@ pub enum DeclKind { Item(P<Item>), } -impl Decl { - pub fn attrs(&self) -> &[Attribute] { - HasAttrs::attrs(self) - } -} - /// An arm of a 'match'. /// /// E.g. `0...10 => { println!("match!") }` as in @@ -949,12 +933,6 @@ pub struct Expr { pub attrs: ThinAttributes } -impl Expr { - pub fn attrs(&self) -> &[Attribute] { - HasAttrs::attrs(self) - } -} - impl fmt::Debug for Expr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "expr({}: {})", self.id, pprust::expr_to_string(self)) @@ -1143,7 +1121,6 @@ pub type Mac = Spanned<Mac_>; pub struct Mac_ { pub path: Path, pub tts: Vec<TokenTree>, - pub ctxt: SyntaxContext, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] @@ -1916,12 +1893,6 @@ pub struct Item { pub span: Span, } -impl Item { - pub fn attrs(&self) -> &[Attribute] { - &self.attrs - } -} - #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum ItemKind { /// An`extern crate` item, with optional original crate name. diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 9f2566a381c..09d7f28157a 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -882,21 +882,6 @@ pub trait HasAttrs: Sized { fn map_attrs<F: FnOnce(Vec<ast::Attribute>) -> Vec<ast::Attribute>>(self, f: F) -> Self; } -/// A cheap way to add Attributes to an AST node. -pub trait WithAttrs { - // FIXME: Could be extended to anything IntoIter<Item=Attribute> - fn with_attrs(self, attrs: ThinAttributes) -> Self; -} - -impl<T: HasAttrs> WithAttrs for T { - fn with_attrs(self, attrs: ThinAttributes) -> Self { - self.map_attrs(|mut orig_attrs| { - orig_attrs.extend(attrs.into_attr_vec()); - orig_attrs - }) - } -} - impl HasAttrs for Vec<Attribute> { fn attrs(&self) -> &[Attribute] { &self diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 3a3863ae653..5e34428a317 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -14,9 +14,8 @@ use ast::{MacStmtStyle, Mrk, Stmt, StmtKind, ItemKind}; use ast; use attr::HasAttrs; use ext::mtwt; -use ext::build::AstBuilder; use attr; -use attr::{AttrMetaMethods, WithAttrs, ThinAttributesExt}; +use attr::{AttrMetaMethods, ThinAttributesExt}; use codemap::{Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute}; use syntax_pos::{self, Span, ExpnId}; use config::StripUnconfigured; @@ -42,7 +41,7 @@ trait MacroGenerable: Sized { // Fold this node or list of nodes using the given folder. fn fold_with<F: Folder>(self, folder: &mut F) -> Self; - fn visit_with<'v, V: Visitor<'v>>(&'v self, visitor: &mut V); + fn visit_with<V: Visitor>(&self, visitor: &mut V); // Return a placeholder expansion to allow compilation to continue after an erroring expansion. fn dummy(span: Span) -> Self; @@ -63,7 +62,7 @@ macro_rules! impl_macro_generable { $( folder.$fold(self) )* $( self.into_iter().flat_map(|item| folder. $fold_elt (item)).collect() )* } - fn visit_with<'v, V: Visitor<'v>>(&'v self, visitor: &mut V) { + fn visit_with<V: Visitor>(&self, visitor: &mut V) { $( visitor.$visit(self) )* $( for item in self.as_slice() { visitor. $visit_elt (item) } )* } @@ -98,24 +97,23 @@ impl MacroGenerable for Option<P<ast::Expr>> { fn fold_with<F: Folder>(self, folder: &mut F) -> Self { self.and_then(|expr| folder.fold_opt_expr(expr)) } - fn visit_with<'v, V: Visitor<'v>>(&'v self, visitor: &mut V) { + fn visit_with<V: Visitor>(&self, visitor: &mut V) { self.as_ref().map(|expr| visitor.visit_expr(expr)); } } -pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> { +pub fn expand_expr(mut expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> { match expr.node { // expr_mac should really be expr_ext or something; it's the // entry-point for all syntax extensions. ast::ExprKind::Mac(mac) => { - expand_mac_invoc(mac, None, expr.attrs.into_attr_vec(), expr.span, fld) + return expand_mac_invoc(mac, None, expr.attrs.into_attr_vec(), expr.span, fld); } ast::ExprKind::While(cond, body, opt_ident) => { let cond = fld.fold_expr(cond); let (body, opt_ident) = expand_loop_block(body, opt_ident, fld); - fld.cx.expr(expr.span, ast::ExprKind::While(cond, body, opt_ident)) - .with_attrs(fold_thin_attrs(expr.attrs, fld)) + expr.node = ast::ExprKind::While(cond, body, opt_ident); } ast::ExprKind::WhileLet(pat, cond, body, opt_ident) => { @@ -132,14 +130,12 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> { }); assert!(rewritten_pats.len() == 1); - let wl = ast::ExprKind::WhileLet(rewritten_pats.remove(0), cond, body, opt_ident); - fld.cx.expr(expr.span, wl).with_attrs(fold_thin_attrs(expr.attrs, fld)) + expr.node = ast::ExprKind::WhileLet(rewritten_pats.remove(0), cond, body, opt_ident); } ast::ExprKind::Loop(loop_block, opt_ident) => { let (loop_block, opt_ident) = expand_loop_block(loop_block, opt_ident, fld); - fld.cx.expr(expr.span, ast::ExprKind::Loop(loop_block, opt_ident)) - .with_attrs(fold_thin_attrs(expr.attrs, fld)) + expr.node = ast::ExprKind::Loop(loop_block, opt_ident); } ast::ExprKind::ForLoop(pat, head, body, opt_ident) => { @@ -156,8 +152,7 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> { assert!(rewritten_pats.len() == 1); let head = fld.fold_expr(head); - let fl = ast::ExprKind::ForLoop(rewritten_pats.remove(0), head, body, opt_ident); - fld.cx.expr(expr.span, fl).with_attrs(fold_thin_attrs(expr.attrs, fld)) + expr.node = ast::ExprKind::ForLoop(rewritten_pats.remove(0), head, body, opt_ident); } ast::ExprKind::IfLet(pat, sub_expr, body, else_opt) => { @@ -175,25 +170,21 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> { let else_opt = else_opt.map(|else_opt| fld.fold_expr(else_opt)); let sub_expr = fld.fold_expr(sub_expr); - let il = ast::ExprKind::IfLet(rewritten_pats.remove(0), sub_expr, body, else_opt); - fld.cx.expr(expr.span, il).with_attrs(fold_thin_attrs(expr.attrs, fld)) + expr.node = ast::ExprKind::IfLet(rewritten_pats.remove(0), sub_expr, body, else_opt); } ast::ExprKind::Closure(capture_clause, fn_decl, block, fn_decl_span) => { let (rewritten_fn_decl, rewritten_block) = expand_and_rename_fn_decl_and_block(fn_decl, block, fld); - let new_node = ast::ExprKind::Closure(capture_clause, - rewritten_fn_decl, - rewritten_block, - fn_decl_span); - P(ast::Expr{ id: expr.id, - node: new_node, - span: expr.span, - attrs: fold_thin_attrs(expr.attrs, fld) }) + expr.node = ast::ExprKind::Closure(capture_clause, + rewritten_fn_decl, + rewritten_block, + fn_decl_span); } - _ => P(noop_fold_expr(expr, fld)), - } + _ => expr = noop_fold_expr(expr, fld), + }; + P(expr) } /// Expand a macro invocation. Returns the result of expansion. @@ -252,7 +243,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr }, }); - let marked_tts = mark_tts(&tts[..], mark); + let marked_tts = mark_tts(tts, mark); Some(expandfun.expand(fld.cx, call_site, &marked_tts)) } @@ -272,7 +263,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr } }); - let marked_tts = mark_tts(&tts, mark); + let marked_tts = mark_tts(tts, mark); Some(expander.expand(fld.cx, call_site, ident, marked_tts)) } @@ -599,7 +590,7 @@ struct PatIdentFinder { ident_accumulator: Vec<ast::Ident> } -impl<'v> Visitor<'v> for PatIdentFinder { +impl Visitor for PatIdentFinder { fn visit_pat(&mut self, pattern: &ast::Pat) { match *pattern { ast::Pat { id: _, node: PatKind::Ident(_, ref path1, ref inner), span: _ } => { @@ -993,9 +984,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> { at_crate_root: bool, } - impl<'a, 'b, 'v> Visitor<'v> for MacroLoadingVisitor<'a, 'b> { - fn visit_mac(&mut self, _: &'v ast::Mac) {} - fn visit_item(&mut self, item: &'v ast::Item) { + impl<'a, 'b> Visitor for MacroLoadingVisitor<'a, 'b> { + fn visit_mac(&mut self, _: &ast::Mac) {} + fn visit_item(&mut self, item: &ast::Item) { if let ast::ItemKind::ExternCrate(..) = item.node { // We need to error on `#[macro_use] extern crate` when it isn't at the // crate root, because `$crate` won't work properly. @@ -1008,7 +999,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { self.at_crate_root = at_crate_root; } } - fn visit_block(&mut self, block: &'v ast::Block) { + fn visit_block(&mut self, block: &ast::Block) { let at_crate_root = ::std::mem::replace(&mut self.at_crate_root, false); visit::walk_block(self, block); self.at_crate_root = at_crate_root; @@ -1215,8 +1206,7 @@ impl Folder for Marker { Spanned { node: Mac_ { path: self.fold_path(node.path), - tts: self.fold_tts(&node.tts), - ctxt: mtwt::apply_mark(self.mark, node.ctxt), + tts: self.fold_tts(node.tts), }, span: self.new_span(span), } @@ -1231,7 +1221,7 @@ impl Folder for Marker { } // apply a given mark to the given token trees. Used prior to expansion of a macro. -fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> { +fn mark_tts(tts: Vec<TokenTree>, m: Mrk) -> Vec<TokenTree> { noop_fold_tts(tts, &mut Marker{mark:m, expn_id: None}) } @@ -1261,7 +1251,7 @@ mod tests { path_accumulator: Vec<ast::Path> , } - impl<'v> Visitor<'v> for PathExprFinderContext { + impl Visitor for PathExprFinderContext { fn visit_expr(&mut self, expr: &ast::Expr) { if let ast::ExprKind::Path(None, ref p) = expr.node { self.path_accumulator.push(p.clone()); @@ -1283,7 +1273,7 @@ mod tests { ident_accumulator: Vec<ast::Ident> } - impl<'v> Visitor<'v> for IdentFinder { + impl Visitor for IdentFinder { fn visit_ident(&mut self, _: syntax_pos::Span, id: ast::Ident){ self.ident_accumulator.push(id); } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 89a260a0235..4ffcb295619 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -32,7 +32,6 @@ pub mod rt { use ext::base::ExtCtxt; use parse::{self, token, classify}; use ptr::P; - use std::rc::Rc; use tokenstream::{self, TokenTree}; @@ -216,12 +215,12 @@ pub mod rt { if self.node.style == ast::AttrStyle::Inner { r.push(TokenTree::Token(self.span, token::Not)); } - r.push(TokenTree::Delimited(self.span, Rc::new(tokenstream::Delimited { + r.push(TokenTree::Delimited(self.span, tokenstream::Delimited { delim: token::Bracket, open_span: self.span, tts: self.node.value.to_tokens(cx), close_span: self.span, - }))); + })); r } } @@ -236,12 +235,12 @@ pub mod rt { impl ToTokens for () { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { - vec![TokenTree::Delimited(DUMMY_SP, Rc::new(tokenstream::Delimited { + vec![TokenTree::Delimited(DUMMY_SP, tokenstream::Delimited { delim: token::Paren, open_span: DUMMY_SP, tts: vec![], close_span: DUMMY_SP, - }))] + })] } } @@ -793,14 +792,9 @@ fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, matcher: bool) -> Vec<ast::Stm id_ext("tokenstream"), id_ext("SequenceRepetition")]; let e_seq_struct = cx.expr_struct(sp, cx.path_global(sp, seq_path), fields); - let e_rc_new = cx.expr_call_global(sp, vec![id_ext("std"), - id_ext("rc"), - id_ext("Rc"), - id_ext("new")], - vec![e_seq_struct]); let e_tok = cx.expr_call(sp, mk_tt_path(cx, sp, "Sequence"), - vec!(e_sp, e_rc_new)); + vec!(e_sp, e_seq_struct)); let e_push = cx.expr_method_call(sp, cx.expr_ident(sp, id_ext("tt")), diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 5015a741378..23f0b1fff0a 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -28,7 +28,6 @@ use util::small_vector::SmallVector; use std::cell::RefCell; use std::collections::{HashMap}; use std::collections::hash_map::{Entry}; -use std::rc::Rc; struct ParserAnyMacro<'a> { parser: RefCell<Parser<'a>>, @@ -262,27 +261,25 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, // These spans won't matter, anyways let match_lhs_tok = MatchNt(lhs_nm, token::str_to_ident("tt")); let match_rhs_tok = MatchNt(rhs_nm, token::str_to_ident("tt")); - let argument_gram = vec!( - TokenTree::Sequence(DUMMY_SP, - Rc::new(tokenstream::SequenceRepetition { - tts: vec![ - TokenTree::Token(DUMMY_SP, match_lhs_tok), - TokenTree::Token(DUMMY_SP, token::FatArrow), - TokenTree::Token(DUMMY_SP, match_rhs_tok)], - separator: Some(token::Semi), - op: tokenstream::KleeneOp::OneOrMore, - num_captures: 2 - })), - //to phase into semicolon-termination instead of - //semicolon-separation - TokenTree::Sequence(DUMMY_SP, - Rc::new(tokenstream::SequenceRepetition { - tts: vec![TokenTree::Token(DUMMY_SP, token::Semi)], - separator: None, - op: tokenstream::KleeneOp::ZeroOrMore, - num_captures: 0 - }))); - + let argument_gram = vec![ + TokenTree::Sequence(DUMMY_SP, tokenstream::SequenceRepetition { + tts: vec![ + TokenTree::Token(DUMMY_SP, match_lhs_tok), + TokenTree::Token(DUMMY_SP, token::FatArrow), + TokenTree::Token(DUMMY_SP, match_rhs_tok), + ], + separator: Some(token::Semi), + op: tokenstream::KleeneOp::OneOrMore, + num_captures: 2, + }), + // to phase into semicolon-termination instead of semicolon-separation + TokenTree::Sequence(DUMMY_SP, tokenstream::SequenceRepetition { + tts: vec![TokenTree::Token(DUMMY_SP, token::Semi)], + separator: None, + op: tokenstream::KleeneOp::ZeroOrMore, + num_captures: 0 + }), + ]; // Parse the macro_rules! invocation (`none` is for no interpolations): let arg_reader = new_tt_reader(&cx.parse_sess().span_diagnostic, diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 9c493948d60..58328eb4246 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -79,11 +79,11 @@ pub fn new_tt_reader_with_doc_flag(sp_diag: &Handler, let mut r = TtReader { sp_diag: sp_diag, stack: vec!(TtFrame { - forest: TokenTree::Sequence(DUMMY_SP, Rc::new(tokenstream::SequenceRepetition { + forest: TokenTree::Sequence(DUMMY_SP, tokenstream::SequenceRepetition { tts: src, // doesn't matter. This merely holds the root unzipping. separator: None, op: tokenstream::KleeneOp::ZeroOrMore, num_captures: 0 - })), + }), idx: 0, dotdotdoted: false, sep: None, diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index bb72dadcaf6..d6476fdb2f0 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -800,7 +800,7 @@ macro_rules! gate_feature_post { }} } -impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { +impl<'a> Visitor for PostExpansionVisitor<'a> { fn visit_attribute(&mut self, attr: &ast::Attribute) { if !self.context.cm.span_allows_unstable(attr.span) { self.context.check_attribute(attr, false); @@ -996,9 +996,9 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } fn visit_fn(&mut self, - fn_kind: FnKind<'v>, - fn_decl: &'v ast::FnDecl, - block: &'v ast::Block, + fn_kind: FnKind, + fn_decl: &ast::FnDecl, + block: &ast::Block, span: Span, _node_id: NodeId) { // check for const fn declarations @@ -1037,7 +1037,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { visit::walk_fn(self, fn_kind, fn_decl, block, span); } - fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) { + fn visit_trait_item(&mut self, ti: &ast::TraitItem) { match ti.node { ast::TraitItemKind::Const(..) => { gate_feature_post!(&self, associated_consts, @@ -1058,7 +1058,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { visit::walk_trait_item(self, ti); } - fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) { + fn visit_impl_item(&mut self, ii: &ast::ImplItem) { if ii.defaultness == ast::Defaultness::Default { gate_feature_post!(&self, specialization, ii.span, @@ -1081,7 +1081,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { visit::walk_impl_item(self, ii); } - fn visit_vis(&mut self, vis: &'v ast::Visibility) { + fn visit_vis(&mut self, vis: &ast::Visibility) { let span = match *vis { ast::Visibility::Crate(span) => span, ast::Visibility::Restricted { ref path, .. } => path.span, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 54f65841010..73c2957bbcf 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -29,8 +29,6 @@ use tokenstream::*; use util::small_vector::SmallVector; use util::move_map::MoveMap; -use std::rc::Rc; - pub trait Folder : Sized { // Any additions to this trait should happen in form // of a call to a public `noop_*` function that only calls @@ -229,11 +227,11 @@ pub trait Folder : Sized { noop_fold_ty_params(tps, self) } - fn fold_tt(&mut self, tt: &TokenTree) -> TokenTree { + fn fold_tt(&mut self, tt: TokenTree) -> TokenTree { noop_fold_tt(tt, self) } - fn fold_tts(&mut self, tts: &[TokenTree]) -> Vec<TokenTree> { + fn fold_tts(&mut self, tts: Vec<TokenTree>) -> Vec<TokenTree> { noop_fold_tts(tts, self) } @@ -521,8 +519,7 @@ pub fn noop_fold_mac<T: Folder>(Spanned {node, span}: Mac, fld: &mut T) -> Mac { Spanned { node: Mac_ { path: fld.fold_path(node.path), - tts: fld.fold_tts(&node.tts), - ctxt: node.ctxt, + tts: fld.fold_tts(node.tts), }, span: fld.new_span(span) } @@ -549,34 +546,26 @@ pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg { } } -pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree { - match *tt { +pub fn noop_fold_tt<T: Folder>(tt: TokenTree, fld: &mut T) -> TokenTree { + match tt { TokenTree::Token(span, ref tok) => TokenTree::Token(span, fld.fold_token(tok.clone())), - TokenTree::Delimited(span, ref delimed) => { - TokenTree::Delimited(span, Rc::new( - Delimited { - delim: delimed.delim, - open_span: delimed.open_span, - tts: fld.fold_tts(&delimed.tts), - close_span: delimed.close_span, - } - )) - }, - TokenTree::Sequence(span, ref seq) => - TokenTree::Sequence(span, - Rc::new(SequenceRepetition { - tts: fld.fold_tts(&seq.tts), - separator: seq.separator.clone().map(|tok| fld.fold_token(tok)), - ..**seq - })), + TokenTree::Delimited(span, delimed) => TokenTree::Delimited(span, Delimited { + delim: delimed.delim, + open_span: delimed.open_span, + tts: fld.fold_tts(delimed.tts), + close_span: delimed.close_span, + }), + TokenTree::Sequence(span, seq) => TokenTree::Sequence(span, SequenceRepetition { + tts: fld.fold_tts(seq.tts), + separator: seq.separator.clone().map(|tok| fld.fold_token(tok)), + ..seq + }), } } -pub fn noop_fold_tts<T: Folder>(tts: &[TokenTree], fld: &mut T) -> Vec<TokenTree> { - // FIXME: Does this have to take a tts slice? - // Could use move_map otherwise... - tts.iter().map(|tt| fld.fold_tt(tt)).collect() +pub fn noop_fold_tts<T: Folder>(tts: Vec<TokenTree>, fld: &mut T) -> Vec<TokenTree> { + tts.move_map(|tt| fld.fold_tt(tt)) } // apply ident folder if it's an ident, apply other folds to interpolated nodes @@ -634,7 +623,7 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T) token::NtIdent(Box::new(Spanned::<Ident>{node: fld.fold_ident(id.node), ..*id})), token::NtMeta(meta_item) => token::NtMeta(fld.fold_meta_item(meta_item)), token::NtPath(path) => token::NtPath(Box::new(fld.fold_path(*path))), - token::NtTT(tt) => token::NtTT(P(fld.fold_tt(&tt))), + token::NtTT(tt) => token::NtTT(tt.map(|tt| fld.fold_tt(tt))), token::NtArm(arm) => token::NtArm(fld.fold_arm(arm)), token::NtImplItem(arm) => token::NtImplItem(arm.map(|arm| fld.fold_impl_item(arm) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d594e0f5558..d0863b0551a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -662,7 +662,6 @@ pub fn integer_lit(s: &str, #[cfg(test)] mod tests { use super::*; - use std::rc::Rc; use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION}; use codemap::Spanned; use ast::{self, PatKind}; @@ -763,7 +762,7 @@ mod tests { ) if first_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, - _ => panic!("value 3: {:?}", **first_delimed), + _ => panic!("value 3: {:?}", *first_delimed), } let tts = &second_delimed.tts[..]; match (tts.len(), tts.get(0), tts.get(1)) { @@ -774,10 +773,10 @@ mod tests { ) if second_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, - _ => panic!("value 4: {:?}", **second_delimed), + _ => panic!("value 4: {:?}", *second_delimed), } }, - _ => panic!("value 2: {:?}", **macro_delimed), + _ => panic!("value 2: {:?}", *macro_delimed), } }, _ => panic!("value: {:?}",tts), @@ -793,7 +792,7 @@ mod tests { TokenTree::Token(sp(3, 4), token::Ident(str_to_ident("a"))), TokenTree::Delimited( sp(5, 14), - Rc::new(tokenstream::Delimited { + tokenstream::Delimited { delim: token::DelimToken::Paren, open_span: sp(5, 6), tts: vec![ @@ -802,10 +801,10 @@ mod tests { TokenTree::Token(sp(10, 13), token::Ident(str_to_ident("i32"))), ], close_span: sp(13, 14), - })), + }), TokenTree::Delimited( sp(15, 21), - Rc::new(tokenstream::Delimited { + tokenstream::Delimited { delim: token::DelimToken::Brace, open_span: sp(15, 16), tts: vec![ @@ -813,7 +812,7 @@ mod tests { TokenTree::Token(sp(18, 19), token::Semi), ], close_span: sp(20, 21), - })) + }) ]; assert_eq!(tts, expected); @@ -996,8 +995,8 @@ mod tests { struct PatIdentVisitor { spans: Vec<Span> } - impl<'v> ::visit::Visitor<'v> for PatIdentVisitor { - fn visit_pat(&mut self, p: &'v ast::Pat) { + impl ::visit::Visitor for PatIdentVisitor { + fn visit_pat(&mut self, p: &ast::Pat) { match p.node { PatKind::Ident(_ , ref spannedident, _) => { self.spans.push(spannedident.span.clone()); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e643de66691..f383b34d1ca 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -17,7 +17,7 @@ use ast::Block; use ast::{BlockCheckMode, CaptureBy}; use ast::{Constness, Crate, CrateConfig}; use ast::{Decl, DeclKind, Defaultness}; -use ast::{EMPTY_CTXT, EnumDef}; +use ast::EnumDef; use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; @@ -1273,7 +1273,7 @@ impl<'a> Parser<'a> { let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), |pp| pp.parse_token_tree())?; - let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; + let m_ = Mac_ { path: pth, tts: tts }; let m: ast::Mac = codemap::Spanned { node: m_, span: mk_sp(lo, self.last_span.hi) }; @@ -1494,7 +1494,7 @@ impl<'a> Parser<'a> { SeqSep::none(), |p| p.parse_token_tree())?; let hi = self.span.hi; - TyKind::Mac(spanned(lo, hi, Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT })) + TyKind::Mac(spanned(lo, hi, Mac_ { path: path, tts: tts })) } else { // NAMED TYPE TyKind::Path(None, path) @@ -2375,7 +2375,7 @@ impl<'a> Parser<'a> { return Ok(self.mk_mac_expr(lo, hi, - Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }, + Mac_ { path: pth, tts: tts }, attrs)); } if self.check(&token::OpenDelim(token::Brace)) { @@ -2698,13 +2698,12 @@ impl<'a> Parser<'a> { )?; let (sep, repeat) = self.parse_sep_and_kleene_op()?; let name_num = macro_parser::count_names(&seq); - return Ok(TokenTree::Sequence(mk_sp(sp.lo, seq_span.hi), - Rc::new(SequenceRepetition { - tts: seq, - separator: sep, - op: repeat, - num_captures: name_num - }))); + return Ok(TokenTree::Sequence(mk_sp(sp.lo, seq_span.hi), SequenceRepetition { + tts: seq, + separator: sep, + op: repeat, + num_captures: name_num + })); } else if self.token.is_keyword(keywords::Crate) { self.bump(); return Ok(TokenTree::Token(sp, SpecialVarNt(SpecialMacroVar::CrateMacroVar))); @@ -2860,12 +2859,12 @@ impl<'a> Parser<'a> { _ => {} } - Ok(TokenTree::Delimited(span, Rc::new(Delimited { + Ok(TokenTree::Delimited(span, Delimited { delim: delim, open_span: open_span, tts: tts, close_span: close_span, - }))) + })) }, _ => { // invariants: the current token is not a left-delimiter, @@ -3689,7 +3688,7 @@ impl<'a> Parser<'a> { let tts = self.parse_seq_to_end( &token::CloseDelim(delim), SeqSep::none(), |p| p.parse_token_tree())?; - let mac = Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT }; + let mac = Mac_ { path: path, tts: tts }; pat = PatKind::Mac(codemap::Spanned {node: mac, span: mk_sp(lo, self.last_span.hi)}); } else { @@ -4002,7 +4001,7 @@ impl<'a> Parser<'a> { }; if id.name == keywords::Invalid.name() { - let mac = P(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })); + let mac = P(spanned(lo, hi, Mac_ { path: pth, tts: tts })); let stmt = StmtKind::Mac(mac, style, attrs.into_thin_attrs()); spanned(lo, hi, stmt) } else { @@ -4023,7 +4022,7 @@ impl<'a> Parser<'a> { self.mk_item( lo, hi, id /*id is good here*/, ItemKind::Mac(spanned(lo, hi, - Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })), + Mac_ { path: pth, tts: tts })), Visibility::Inherited, attrs)))), ast::DUMMY_NODE_ID)) } @@ -4936,7 +4935,7 @@ impl<'a> Parser<'a> { let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), |p| p.parse_token_tree())?; - let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; + let m_ = Mac_ { path: pth, tts: tts }; let m: ast::Mac = codemap::Spanned { node: m_, span: mk_sp(lo, self.last_span.hi) }; @@ -6021,7 +6020,7 @@ impl<'a> Parser<'a> { SeqSep::none(), |p| p.parse_token_tree())?; // single-variant-enum... : - let m = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; + let m = Mac_ { path: pth, tts: tts }; let m: ast::Mac = codemap::Spanned { node: m, span: mk_sp(mac_lo, self.last_span.hi) }; diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs index 5e3cd0773aa..928ffb202d0 100644 --- a/src/libsyntax/show_span.rs +++ b/src/libsyntax/show_span.rs @@ -44,7 +44,7 @@ struct ShowSpanVisitor<'a> { mode: Mode, } -impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> { +impl<'a> Visitor for ShowSpanVisitor<'a> { fn visit_expr(&mut self, e: &ast::Expr) { if let Mode::Expression = self.mode { self.span_diagnostic.span_warn(e.span, "expression"); diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index b903537a7b7..35377d14bab 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -20,7 +20,6 @@ use ext::tt::macro_parser; use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; use parse::lexer; use parse::token; -use std::rc::Rc; /// A delimited sequence of token trees #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -95,13 +94,13 @@ pub enum TokenTree { /// A single token Token(Span, token::Token), /// A delimited sequence of token trees - Delimited(Span, Rc<Delimited>), + Delimited(Span, Delimited), // This only makes sense in MBE macros. /// A kleene-style repetition sequence with a span // FIXME(eddyb) #12938 Use DST. - Sequence(Span, Rc<SequenceRepetition>), + Sequence(Span, SequenceRepetition), } impl TokenTree { @@ -150,7 +149,7 @@ impl TokenTree { Some(*cnt) }).max().unwrap_or(0); - TokenTree::Delimited(sp, Rc::new(Delimited { + TokenTree::Delimited(sp, Delimited { delim: token::Bracket, open_span: sp, tts: vec![TokenTree::Token(sp, token::Ident(token::str_to_ident("doc"))), @@ -158,7 +157,7 @@ impl TokenTree { TokenTree::Token(sp, token::Literal( token::StrRaw(token::intern(&stripped), num_of_hashes), None))], close_span: sp, - })) + }) } (&TokenTree::Delimited(_, ref delimed), _) => { if index == 0 { diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index ad6145f8618..7c364a1603e 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -26,133 +26,133 @@ impl NodeCounter { } } -impl<'v> Visitor<'v> for NodeCounter { +impl Visitor for NodeCounter { fn visit_ident(&mut self, span: Span, ident: Ident) { self.count += 1; walk_ident(self, span, ident); } - fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { + fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId) { self.count += 1; walk_mod(self, m) } - fn visit_foreign_item(&mut self, i: &'v ForeignItem) { + fn visit_foreign_item(&mut self, i: &ForeignItem) { self.count += 1; walk_foreign_item(self, i) } - fn visit_item(&mut self, i: &'v Item) { + fn visit_item(&mut self, i: &Item) { self.count += 1; walk_item(self, i) } - fn visit_local(&mut self, l: &'v Local) { + fn visit_local(&mut self, l: &Local) { self.count += 1; walk_local(self, l) } - fn visit_block(&mut self, b: &'v Block) { + fn visit_block(&mut self, b: &Block) { self.count += 1; walk_block(self, b) } - fn visit_stmt(&mut self, s: &'v Stmt) { + fn visit_stmt(&mut self, s: &Stmt) { self.count += 1; walk_stmt(self, s) } - fn visit_arm(&mut self, a: &'v Arm) { + fn visit_arm(&mut self, a: &Arm) { self.count += 1; walk_arm(self, a) } - fn visit_pat(&mut self, p: &'v Pat) { + fn visit_pat(&mut self, p: &Pat) { self.count += 1; walk_pat(self, p) } - fn visit_decl(&mut self, d: &'v Decl) { + fn visit_decl(&mut self, d: &Decl) { self.count += 1; walk_decl(self, d) } - fn visit_expr(&mut self, ex: &'v Expr) { + fn visit_expr(&mut self, ex: &Expr) { self.count += 1; walk_expr(self, ex) } - fn visit_ty(&mut self, t: &'v Ty) { + fn visit_ty(&mut self, t: &Ty) { self.count += 1; walk_ty(self, t) } - fn visit_generics(&mut self, g: &'v Generics) { + fn visit_generics(&mut self, g: &Generics) { self.count += 1; walk_generics(self, g) } - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, _: NodeId) { + fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, b: &Block, s: Span, _: NodeId) { self.count += 1; walk_fn(self, fk, fd, b, s) } - fn visit_trait_item(&mut self, ti: &'v TraitItem) { + fn visit_trait_item(&mut self, ti: &TraitItem) { self.count += 1; walk_trait_item(self, ti) } - fn visit_impl_item(&mut self, ii: &'v ImplItem) { + fn visit_impl_item(&mut self, ii: &ImplItem) { self.count += 1; walk_impl_item(self, ii) } - fn visit_trait_ref(&mut self, t: &'v TraitRef) { + fn visit_trait_ref(&mut self, t: &TraitRef) { self.count += 1; walk_trait_ref(self, t) } - fn visit_ty_param_bound(&mut self, bounds: &'v TyParamBound) { + fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) { self.count += 1; walk_ty_param_bound(self, bounds) } - fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: &'v TraitBoundModifier) { + fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) { self.count += 1; walk_poly_trait_ref(self, t, m) } - fn visit_variant_data(&mut self, s: &'v VariantData, _: Ident, - _: &'v Generics, _: NodeId, _: Span) { + fn visit_variant_data(&mut self, s: &VariantData, _: Ident, + _: &Generics, _: NodeId, _: Span) { self.count += 1; walk_struct_def(self, s) } - fn visit_struct_field(&mut self, s: &'v StructField) { + fn visit_struct_field(&mut self, s: &StructField) { self.count += 1; walk_struct_field(self, s) } - fn visit_enum_def(&mut self, enum_definition: &'v EnumDef, - generics: &'v Generics, item_id: NodeId, _: Span) { + fn visit_enum_def(&mut self, enum_definition: &EnumDef, + generics: &Generics, item_id: NodeId, _: Span) { self.count += 1; walk_enum_def(self, enum_definition, generics, item_id) } - fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics, item_id: NodeId) { + fn visit_variant(&mut self, v: &Variant, g: &Generics, item_id: NodeId) { self.count += 1; walk_variant(self, v, g, item_id) } - fn visit_lifetime(&mut self, lifetime: &'v Lifetime) { + fn visit_lifetime(&mut self, lifetime: &Lifetime) { self.count += 1; walk_lifetime(self, lifetime) } - fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) { + fn visit_lifetime_def(&mut self, lifetime: &LifetimeDef) { self.count += 1; walk_lifetime_def(self, lifetime) } - fn visit_mac(&mut self, _mac: &'v Mac) { + fn visit_mac(&mut self, _mac: &Mac) { self.count += 1; walk_mac(self, _mac) } - fn visit_path(&mut self, path: &'v Path, _id: NodeId) { + fn visit_path(&mut self, path: &Path, _id: NodeId) { self.count += 1; walk_path(self, path) } - fn visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) { + fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) { self.count += 1; walk_path_list_item(self, prefix, item) } - fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'v PathParameters) { + fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) { self.count += 1; walk_path_parameters(self, path_span, path_parameters) } - fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) { + fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) { self.count += 1; walk_assoc_type_binding(self, type_binding) } - fn visit_attribute(&mut self, _attr: &'v Attribute) { + fn visit_attribute(&mut self, _attr: &Attribute) { self.count += 1; } - fn visit_macro_def(&mut self, macro_def: &'v MacroDef) { + fn visit_macro_def(&mut self, macro_def: &MacroDef) { self.count += 1; walk_macro_def(self, macro_def) } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 113c0d0293b..9a52c0b32be 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -50,57 +50,57 @@ pub enum FnKind<'a> { /// explicitly, you need to override each method. (And you also need /// to monitor future changes to `Visitor` in case a new method with a /// new default implementation gets introduced.) -pub trait Visitor<'v> : Sized { +pub trait Visitor: Sized { fn visit_name(&mut self, _span: Span, _name: Name) { // Nothing to do. } fn visit_ident(&mut self, span: Span, ident: Ident) { walk_ident(self, span, ident); } - fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) } - fn visit_foreign_item(&mut self, i: &'v ForeignItem) { walk_foreign_item(self, i) } - fn visit_item(&mut self, i: &'v Item) { walk_item(self, i) } - fn visit_local(&mut self, l: &'v Local) { walk_local(self, l) } - fn visit_block(&mut self, b: &'v Block) { walk_block(self, b) } - fn visit_stmt(&mut self, s: &'v Stmt) { walk_stmt(self, s) } - fn visit_arm(&mut self, a: &'v Arm) { walk_arm(self, a) } - fn visit_pat(&mut self, p: &'v Pat) { walk_pat(self, p) } - fn visit_decl(&mut self, d: &'v Decl) { walk_decl(self, d) } - fn visit_expr(&mut self, ex: &'v Expr) { walk_expr(self, ex) } - fn visit_expr_post(&mut self, _ex: &'v Expr) { } - fn visit_ty(&mut self, t: &'v Ty) { walk_ty(self, t) } - fn visit_generics(&mut self, g: &'v Generics) { walk_generics(self, g) } - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, _: NodeId) { + fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId) { walk_mod(self, m) } + fn visit_foreign_item(&mut self, i: &ForeignItem) { walk_foreign_item(self, i) } + fn visit_item(&mut self, i: &Item) { walk_item(self, i) } + fn visit_local(&mut self, l: &Local) { walk_local(self, l) } + fn visit_block(&mut self, b: &Block) { walk_block(self, b) } + fn visit_stmt(&mut self, s: &Stmt) { walk_stmt(self, s) } + fn visit_arm(&mut self, a: &Arm) { walk_arm(self, a) } + fn visit_pat(&mut self, p: &Pat) { walk_pat(self, p) } + fn visit_decl(&mut self, d: &Decl) { walk_decl(self, d) } + fn visit_expr(&mut self, ex: &Expr) { walk_expr(self, ex) } + fn visit_expr_post(&mut self, _ex: &Expr) { } + fn visit_ty(&mut self, t: &Ty) { walk_ty(self, t) } + fn visit_generics(&mut self, g: &Generics) { walk_generics(self, g) } + fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, b: &Block, s: Span, _: NodeId) { walk_fn(self, fk, fd, b, s) } - fn visit_trait_item(&mut self, ti: &'v TraitItem) { walk_trait_item(self, ti) } - fn visit_impl_item(&mut self, ii: &'v ImplItem) { walk_impl_item(self, ii) } - fn visit_trait_ref(&mut self, t: &'v TraitRef) { walk_trait_ref(self, t) } - fn visit_ty_param_bound(&mut self, bounds: &'v TyParamBound) { + fn visit_trait_item(&mut self, ti: &TraitItem) { walk_trait_item(self, ti) } + fn visit_impl_item(&mut self, ii: &ImplItem) { walk_impl_item(self, ii) } + fn visit_trait_ref(&mut self, t: &TraitRef) { walk_trait_ref(self, t) } + fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) { walk_ty_param_bound(self, bounds) } - fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: &'v TraitBoundModifier) { + fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) { walk_poly_trait_ref(self, t, m) } - fn visit_variant_data(&mut self, s: &'v VariantData, _: Ident, - _: &'v Generics, _: NodeId, _: Span) { + fn visit_variant_data(&mut self, s: &VariantData, _: Ident, + _: &Generics, _: NodeId, _: Span) { walk_struct_def(self, s) } - fn visit_struct_field(&mut self, s: &'v StructField) { walk_struct_field(self, s) } - fn visit_enum_def(&mut self, enum_definition: &'v EnumDef, - generics: &'v Generics, item_id: NodeId, _: Span) { + fn visit_struct_field(&mut self, s: &StructField) { walk_struct_field(self, s) } + fn visit_enum_def(&mut self, enum_definition: &EnumDef, + generics: &Generics, item_id: NodeId, _: Span) { walk_enum_def(self, enum_definition, generics, item_id) } - fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics, item_id: NodeId) { + fn visit_variant(&mut self, v: &Variant, g: &Generics, item_id: NodeId) { walk_variant(self, v, g, item_id) } - fn visit_lifetime(&mut self, lifetime: &'v Lifetime) { + fn visit_lifetime(&mut self, lifetime: &Lifetime) { walk_lifetime(self, lifetime) } - fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) { + fn visit_lifetime_def(&mut self, lifetime: &LifetimeDef) { walk_lifetime_def(self, lifetime) } - fn visit_mac(&mut self, _mac: &'v Mac) { + fn visit_mac(&mut self, _mac: &Mac) { panic!("visit_mac disabled by default"); // NB: see note about macros above. // if you really want a visitor that @@ -108,26 +108,26 @@ pub trait Visitor<'v> : Sized { // definition in your trait impl: // visit::walk_mac(self, _mac) } - fn visit_path(&mut self, path: &'v Path, _id: NodeId) { + fn visit_path(&mut self, path: &Path, _id: NodeId) { walk_path(self, path) } - fn visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) { + fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) { walk_path_list_item(self, prefix, item) } - fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) { + fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) { walk_path_segment(self, path_span, path_segment) } - fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'v PathParameters) { + fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) { walk_path_parameters(self, path_span, path_parameters) } - fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) { + fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) { walk_assoc_type_binding(self, type_binding) } - fn visit_attribute(&mut self, _attr: &'v Attribute) {} - fn visit_macro_def(&mut self, macro_def: &'v MacroDef) { + fn visit_attribute(&mut self, _attr: &Attribute) {} + fn visit_macro_def(&mut self, macro_def: &MacroDef) { walk_macro_def(self, macro_def) } - fn visit_vis(&mut self, vis: &'v Visibility) { + fn visit_vis(&mut self, vis: &Visibility) { walk_vis(self, vis) } } @@ -146,46 +146,45 @@ macro_rules! walk_list { } } -pub fn walk_opt_name<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, opt_name: Option<Name>) { +pub fn walk_opt_name<V: Visitor>(visitor: &mut V, span: Span, opt_name: Option<Name>) { if let Some(name) = opt_name { visitor.visit_name(span, name); } } -pub fn walk_opt_ident<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, opt_ident: Option<Ident>) { +pub fn walk_opt_ident<V: Visitor>(visitor: &mut V, span: Span, opt_ident: Option<Ident>) { if let Some(ident) = opt_ident { visitor.visit_ident(span, ident); } } -pub fn walk_opt_sp_ident<'v, V: Visitor<'v>>(visitor: &mut V, - opt_sp_ident: &Option<Spanned<Ident>>) { +pub fn walk_opt_sp_ident<V: Visitor>(visitor: &mut V, opt_sp_ident: &Option<Spanned<Ident>>) { if let Some(ref sp_ident) = *opt_sp_ident { visitor.visit_ident(sp_ident.span, sp_ident.node); } } -pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, ident: Ident) { +pub fn walk_ident<V: Visitor>(visitor: &mut V, span: Span, ident: Ident) { visitor.visit_name(span, ident.name); } -pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) { +pub fn walk_crate<V: Visitor>(visitor: &mut V, krate: &Crate) { visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID); walk_list!(visitor, visit_attribute, &krate.attrs); walk_list!(visitor, visit_macro_def, &krate.exported_macros); } -pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef) { +pub fn walk_macro_def<V: Visitor>(visitor: &mut V, macro_def: &MacroDef) { visitor.visit_ident(macro_def.span, macro_def.ident); walk_opt_ident(visitor, macro_def.span, macro_def.imported_from); walk_list!(visitor, visit_attribute, ¯o_def.attrs); } -pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) { +pub fn walk_mod<V: Visitor>(visitor: &mut V, module: &Mod) { walk_list!(visitor, visit_item, &module.items); } -pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { +pub fn walk_local<V: Visitor>(visitor: &mut V, local: &Local) { for attr in local.attrs.as_attr_slice() { visitor.visit_attribute(attr); } @@ -194,33 +193,27 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { walk_list!(visitor, visit_expr, &local.init); } -pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) { +pub fn walk_lifetime<V: Visitor>(visitor: &mut V, lifetime: &Lifetime) { visitor.visit_name(lifetime.span, lifetime.name); } -pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, - lifetime_def: &'v LifetimeDef) { +pub fn walk_lifetime_def<V: Visitor>(visitor: &mut V, lifetime_def: &LifetimeDef) { visitor.visit_lifetime(&lifetime_def.lifetime); walk_list!(visitor, visit_lifetime, &lifetime_def.bounds); } -pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V, - trait_ref: &'v PolyTraitRef, - _modifier: &'v TraitBoundModifier) - where V: Visitor<'v> +pub fn walk_poly_trait_ref<V>(visitor: &mut V, trait_ref: &PolyTraitRef, _: &TraitBoundModifier) + where V: Visitor, { walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes); visitor.visit_trait_ref(&trait_ref.trait_ref); } -pub fn walk_trait_ref<'v,V>(visitor: &mut V, - trait_ref: &'v TraitRef) - where V: Visitor<'v> -{ +pub fn walk_trait_ref<V: Visitor>(visitor: &mut V, trait_ref: &TraitRef) { visitor.visit_path(&trait_ref.path, trait_ref.ref_id) } -pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { +pub fn walk_item<V: Visitor>(visitor: &mut V, item: &Item) { visitor.visit_vis(&item.vis); visitor.visit_ident(item.span, item.ident); match item.node { @@ -299,17 +292,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { walk_list!(visitor, visit_attribute, &item.attrs); } -pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, - enum_definition: &'v EnumDef, - generics: &'v Generics, - item_id: NodeId) { +pub fn walk_enum_def<V: Visitor>(visitor: &mut V, + enum_definition: &EnumDef, + generics: &Generics, + item_id: NodeId) { walk_list!(visitor, visit_variant, &enum_definition.variants, generics, item_id); } -pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, - variant: &'v Variant, - generics: &'v Generics, - item_id: NodeId) { +pub fn walk_variant<V>(visitor: &mut V, variant: &Variant, generics: &Generics, item_id: NodeId) + where V: Visitor, +{ visitor.visit_ident(variant.span, variant.node.name); visitor.visit_variant_data(&variant.node.data, variant.node.name, generics, item_id, variant.span); @@ -317,7 +309,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, walk_list!(visitor, visit_attribute, &variant.node.attrs); } -pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { +pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) { match typ.node { TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => { visitor.visit_ty(ty) @@ -363,28 +355,25 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { } } -pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { +pub fn walk_path<V: Visitor>(visitor: &mut V, path: &Path) { for segment in &path.segments { visitor.visit_path_segment(path.span, segment); } } -pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V, _prefix: &'v Path, - item: &'v PathListItem) { +pub fn walk_path_list_item<V: Visitor>(visitor: &mut V, _prefix: &Path, item: &PathListItem) { walk_opt_ident(visitor, item.span, item.node.name()); walk_opt_ident(visitor, item.span, item.node.rename()); } -pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, - path_span: Span, - segment: &'v PathSegment) { +pub fn walk_path_segment<V: Visitor>(visitor: &mut V, path_span: Span, segment: &PathSegment) { visitor.visit_ident(path_span, segment.identifier); visitor.visit_path_parameters(path_span, &segment.parameters); } -pub fn walk_path_parameters<'v, V: Visitor<'v>>(visitor: &mut V, - _path_span: Span, - path_parameters: &'v PathParameters) { +pub fn walk_path_parameters<V>(visitor: &mut V, _path_span: Span, path_parameters: &PathParameters) + where V: Visitor, +{ match *path_parameters { PathParameters::AngleBracketed(ref data) => { walk_list!(visitor, visit_ty, &data.types); @@ -398,13 +387,12 @@ pub fn walk_path_parameters<'v, V: Visitor<'v>>(visitor: &mut V, } } -pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V, - type_binding: &'v TypeBinding) { +pub fn walk_assoc_type_binding<V: Visitor>(visitor: &mut V, type_binding: &TypeBinding) { visitor.visit_ident(type_binding.span, type_binding.ident); visitor.visit_ty(&type_binding.ty); } -pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { +pub fn walk_pat<V: Visitor>(visitor: &mut V, pattern: &Pat) { match pattern.node { PatKind::TupleStruct(ref path, ref children, _) => { visitor.visit_path(path, pattern.id); @@ -449,8 +437,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { } } -pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, - foreign_item: &'v ForeignItem) { +pub fn walk_foreign_item<V: Visitor>(visitor: &mut V, foreign_item: &ForeignItem) { visitor.visit_vis(&foreign_item.vis); visitor.visit_ident(foreign_item.span, foreign_item.ident); @@ -465,8 +452,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, walk_list!(visitor, visit_attribute, &foreign_item.attrs); } -pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, - bound: &'v TyParamBound) { +pub fn walk_ty_param_bound<V: Visitor>(visitor: &mut V, bound: &TyParamBound) { match *bound { TraitTyParamBound(ref typ, ref modifier) => { visitor.visit_poly_trait_ref(typ, modifier); @@ -477,7 +463,7 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, } } -pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { +pub fn walk_generics<V: Visitor>(visitor: &mut V, generics: &Generics) { for param in &generics.ty_params { visitor.visit_ident(param.span, param.ident); walk_list!(visitor, visit_ty_param_bound, ¶m.bounds); @@ -511,13 +497,13 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics } } -pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) { +pub fn walk_fn_ret_ty<V: Visitor>(visitor: &mut V, ret_ty: &FunctionRetTy) { if let FunctionRetTy::Ty(ref output_ty) = *ret_ty { visitor.visit_ty(output_ty) } } -pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) { +pub fn walk_fn_decl<V: Visitor>(visitor: &mut V, function_declaration: &FnDecl) { for argument in &function_declaration.inputs { visitor.visit_pat(&argument.pat); visitor.visit_ty(&argument.ty) @@ -525,8 +511,7 @@ pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: & walk_fn_ret_ty(visitor, &function_declaration.output) } -pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, - function_kind: FnKind<'v>) { +pub fn walk_fn_kind<V: Visitor>(visitor: &mut V, function_kind: FnKind) { match function_kind { FnKind::ItemFn(_, generics, _, _, _, _) => { visitor.visit_generics(generics); @@ -538,17 +523,15 @@ pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, } } -pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, - function_kind: FnKind<'v>, - function_declaration: &'v FnDecl, - function_body: &'v Block, - _span: Span) { - walk_fn_decl(visitor, function_declaration); - walk_fn_kind(visitor, function_kind); - visitor.visit_block(function_body) +pub fn walk_fn<V>(visitor: &mut V, kind: FnKind, declaration: &FnDecl, body: &Block, _span: Span) + where V: Visitor, +{ + walk_fn_decl(visitor, declaration); + walk_fn_kind(visitor, kind); + visitor.visit_block(body) } -pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) { +pub fn walk_trait_item<V: Visitor>(visitor: &mut V, trait_item: &TraitItem) { visitor.visit_ident(trait_item.span, trait_item.ident); walk_list!(visitor, visit_attribute, &trait_item.attrs); match trait_item.node { @@ -574,7 +557,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai } } -pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) { +pub fn walk_impl_item<V: Visitor>(visitor: &mut V, impl_item: &ImplItem) { visitor.visit_vis(&impl_item.vis); visitor.visit_ident(impl_item.span, impl_item.ident); walk_list!(visitor, visit_attribute, &impl_item.attrs); @@ -596,25 +579,23 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt } } -pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, - struct_definition: &'v VariantData) { +pub fn walk_struct_def<V: Visitor>(visitor: &mut V, struct_definition: &VariantData) { walk_list!(visitor, visit_struct_field, struct_definition.fields()); } -pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, - struct_field: &'v StructField) { +pub fn walk_struct_field<V: Visitor>(visitor: &mut V, struct_field: &StructField) { visitor.visit_vis(&struct_field.vis); walk_opt_ident(visitor, struct_field.span, struct_field.ident); visitor.visit_ty(&struct_field.ty); walk_list!(visitor, visit_attribute, &struct_field.attrs); } -pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { +pub fn walk_block<V: Visitor>(visitor: &mut V, block: &Block) { walk_list!(visitor, visit_stmt, &block.stmts); walk_list!(visitor, visit_expr, &block.expr); } -pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { +pub fn walk_stmt<V: Visitor>(visitor: &mut V, statement: &Stmt) { match statement.node { StmtKind::Decl(ref declaration, _) => visitor.visit_decl(declaration), StmtKind::Expr(ref expression, _) | StmtKind::Semi(ref expression, _) => { @@ -629,18 +610,18 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { } } -pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) { +pub fn walk_decl<V: Visitor>(visitor: &mut V, declaration: &Decl) { match declaration.node { DeclKind::Local(ref local) => visitor.visit_local(local), DeclKind::Item(ref item) => visitor.visit_item(item), } } -pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) { +pub fn walk_mac<V: Visitor>(_: &mut V, _: &Mac) { // Empty! } -pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { +pub fn walk_expr<V: Visitor>(visitor: &mut V, expression: &Expr) { for attr in expression.attrs.as_attr_slice() { visitor.visit_attribute(attr); } @@ -790,14 +771,14 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { visitor.visit_expr_post(expression) } -pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) { +pub fn walk_arm<V: Visitor>(visitor: &mut V, arm: &Arm) { walk_list!(visitor, visit_pat, &arm.pats); walk_list!(visitor, visit_expr, &arm.guard); visitor.visit_expr(&arm.body); walk_list!(visitor, visit_attribute, &arm.attrs); } -pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) { +pub fn walk_vis<V: Visitor>(visitor: &mut V, vis: &Visibility) { if let Visibility::Restricted { ref path, id } = *vis { visitor.visit_path(path, id); } |
