diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 085acc198d16a..a1c04dfcab5e6 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -95,7 +95,7 @@ impl<'a> CheckAttrVisitor<'a> { } } -impl<'a, 'v> Visitor<'v> for CheckAttrVisitor<'a> { +impl<'a> Visitor for CheckAttrVisitor<'a> { fn visit_item(&mut self, item: &ast::Item) { let target = Target::from_item(item); for attr in &item.attrs { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 69cf5baa26fec..8841f4ad39ada 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -138,8 +138,8 @@ impl<'a> LoweringContext<'a> { lctx: &'lcx mut LoweringContext<'interner>, } - impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> { - fn visit_item(&mut self, item: &'lcx Item) { + impl<'lcx, 'interner> Visitor for ItemLowerer<'lcx, 'interner> { + fn visit_item(&mut self, item: &Item) { self.items.insert(item.id, self.lctx.lower_item(item)); visit::walk_item(self, item); } diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index e3b6539b8ccab..5afe8cbaff7e8 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -98,7 +98,7 @@ impl<'ast> DefCollector<'ast> { self.parent_def = parent; } - fn visit_ast_const_integer(&mut self, expr: &'ast Expr) { + fn visit_ast_const_integer(&mut self, expr: &Expr) { // Find the node which will be used after lowering. if let ExprKind::Paren(ref inner) = expr.node { return self.visit_ast_const_integer(inner); @@ -124,8 +124,8 @@ impl<'ast> DefCollector<'ast> { } } -impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { - fn visit_item(&mut self, i: &'ast Item) { +impl<'ast> visit::Visitor for DefCollector<'ast> { + fn visit_item(&mut self, i: &Item) { debug!("visit_item: {:?}", i); // Pick the def data. This need not be unique, but the more @@ -183,7 +183,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { }); } - fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) { + fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) { let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.ident.name)); self.with_parent(def, |this| { @@ -191,7 +191,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { }); } - fn visit_generics(&mut self, generics: &'ast Generics) { + fn visit_generics(&mut self, generics: &Generics) { for ty_param in generics.ty_params.iter() { self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name)); } @@ -199,7 +199,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { visit::walk_generics(self, generics); } - fn visit_trait_item(&mut self, ti: &'ast TraitItem) { + fn visit_trait_item(&mut self, ti: &TraitItem) { let def_data = match ti.node { TraitItemKind::Method(..) | TraitItemKind::Const(..) => DefPathData::ValueNs(ti.ident.name), @@ -216,7 +216,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { }); } - fn visit_impl_item(&mut self, ii: &'ast ImplItem) { + fn visit_impl_item(&mut self, ii: &ImplItem) { let def_data = match ii.node { ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name), @@ -234,7 +234,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { }); } - fn visit_pat(&mut self, pat: &'ast Pat) { + fn visit_pat(&mut self, pat: &Pat) { let parent_def = self.parent_def; if let PatKind::Ident(_, id, _) = pat.node { @@ -246,7 +246,7 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { self.parent_def = parent_def; } - fn visit_expr(&mut self, expr: &'ast Expr) { + fn visit_expr(&mut self, expr: &Expr) { let parent_def = self.parent_def; if let ExprKind::Repeat(_, ref count) = expr.node { @@ -262,18 +262,18 @@ impl<'ast> visit::Visitor<'ast> for DefCollector<'ast> { self.parent_def = parent_def; } - fn visit_ty(&mut self, ty: &'ast Ty) { + fn visit_ty(&mut self, ty: &Ty) { if let TyKind::FixedLengthVec(_, ref length) = ty.node { self.visit_ast_const_integer(length); } visit::walk_ty(self, ty); } - fn visit_lifetime_def(&mut self, def: &'ast LifetimeDef) { + fn visit_lifetime_def(&mut self, def: &LifetimeDef) { self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name)); } - fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) { + fn visit_macro_def(&mut self, macro_def: &MacroDef) { self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name)); } } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 94f17ea779ac8..9ebf4dfa0178c 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -905,7 +905,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> { } } -impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { +impl<'a> ast_visit::Visitor for EarlyContext<'a> { fn visit_item(&mut self, it: &ast::Item) { self.with_lint_attrs(&it.attrs, |cx| { run_lints!(cx, check_item, early_passes, it); @@ -939,8 +939,8 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { ast_visit::walk_stmt(self, s); } - fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, decl: &'v ast::FnDecl, - body: &'v ast::Block, span: Span, id: ast::NodeId) { + fn visit_fn(&mut self, fk: ast_visit::FnKind, decl: &ast::FnDecl, + body: &ast::Block, span: Span, id: ast::NodeId) { run_lints!(self, check_fn, early_passes, fk, decl, body, span, id); ast_visit::walk_fn(self, fk, decl, body, span); run_lints!(self, check_fn_post, early_passes, fk, decl, body, span, id); diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 2025045cc8f56..31024ee8eca09 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -58,8 +58,8 @@ pub struct CrateReader<'a> { local_crate_name: String, } -impl<'a, 'ast> visit::Visitor<'ast> for LocalCrateReader<'a> { - fn visit_item(&mut self, a: &'ast ast::Item) { +impl<'a> visit::Visitor for LocalCrateReader<'a> { + fn visit_item(&mut self, a: &ast::Item) { self.process_item(a); visit::walk_item(self, a); } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 919c717f888ff..4dd54beba3893 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -57,7 +57,7 @@ impl<'a> AstValidator<'a> { } } -impl<'a, 'v> Visitor<'v> for AstValidator<'a> { +impl<'a> Visitor for AstValidator<'a> { fn visit_lifetime(&mut self, lt: &Lifetime) { if lt.name.as_str() == "'_" { self.session.add_lint( diff --git a/src/librustc_passes/no_asm.rs b/src/librustc_passes/no_asm.rs index 90f92c25b05ea..314513a974ecd 100644 --- a/src/librustc_passes/no_asm.rs +++ b/src/librustc_passes/no_asm.rs @@ -29,7 +29,7 @@ struct CheckNoAsm<'a> { sess: &'a Session, } -impl<'a, 'v> Visitor<'v> for CheckNoAsm<'a> { +impl<'a> Visitor for CheckNoAsm<'a> { fn visit_expr(&mut self, e: &ast::Expr) { match e.node { ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472, diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 775c24b6d4a67..88123f66c1a71 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -503,7 +503,7 @@ struct BuildReducedGraphVisitor<'a, 'b: 'a> { parent: Module<'b>, } -impl<'a, 'b, 'v> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b> { +impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> { fn visit_item(&mut self, item: &Item) { let old_parent = self.parent; self.resolver.build_reduced_graph_for_item(item, &mut self.parent); diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 64347d7b84d3c..7fa363c92bee0 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -71,7 +71,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> { } } -impl<'a, 'b, 'v> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b> { +impl<'a, 'b> Visitor for UnusedImportCheckVisitor<'a, 'b> { fn visit_item(&mut self, item: &ast::Item) { visit::walk_item(self, item); // Ignore is_public import statements because there's no way to be sure diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 377863b016d85..554cf1b6c858e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -500,7 +500,7 @@ pub enum Namespace { ValueNS, } -impl<'a, 'v> Visitor<'v> for Resolver<'a> { +impl<'a> Visitor for Resolver<'a> { fn visit_item(&mut self, item: &Item) { self.resolve_item(item); } @@ -562,9 +562,9 @@ impl<'a, 'v> Visitor<'v> for Resolver<'a> { }); } fn visit_fn(&mut self, - function_kind: FnKind<'v>, - declaration: &'v FnDecl, - block: &'v Block, + function_kind: FnKind, + declaration: &FnDecl, + block: &Block, _: Span, node_id: NodeId) { let rib_kind = match function_kind { diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 216d188a503e3..044e611ca34ae 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1013,7 +1013,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } } -impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx, 'll, D> { +impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> { fn visit_item(&mut self, item: &ast::Item) { use syntax::ast::ItemKind::*; self.process_macro_use(item.span, item.id); diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 27f15756a9130..203225035e0a0 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -686,7 +686,7 @@ impl PathCollector { } } -impl<'v> Visitor<'v> for PathCollector { +impl Visitor for PathCollector { fn visit_pat(&mut self, p: &ast::Pat) { match p.node { PatKind::Struct(ref path, _, _) => { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 40c98206c16e9..657c84474313b 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 codemap::{mk_sp, respan, Span, Spanned, DUMMY_SP, ExpnId}; use abi::Abi; use errors; @@ -825,10 +825,6 @@ impl StmtKind { StmtKind::Mac(..) => None, } } - - pub fn attrs(&self) -> &[Attribute] { - HasAttrs::attrs(self) - } } #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -858,12 +854,6 @@ pub struct Local { pub attrs: ThinAttributes, } -impl Local { - pub fn attrs(&self) -> &[Attribute] { - HasAttrs::attrs(self) - } -} - pub type Decl = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -874,12 +864,6 @@ pub enum DeclKind { Item(P), } -impl Decl { - pub fn attrs(&self) -> &[Attribute] { - HasAttrs::attrs(self) - } -} - /// represents one arm of a 'match' #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Arm { @@ -919,12 +903,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)) @@ -1174,13 +1152,13 @@ pub enum TokenTree { /// A single token Token(Span, token::Token), /// A delimited sequence of token trees - Delimited(Span, Rc), + 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), + Sequence(Span, SequenceRepetition), } impl TokenTree { @@ -1229,7 +1207,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"))), @@ -1237,7 +1215,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 { @@ -1300,7 +1278,6 @@ pub type Mac = Spanned; pub struct Mac_ { pub path: Path, pub tts: Vec, - pub ctxt: SyntaxContext, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] @@ -2036,12 +2013,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 c3c3deea1877f..8a2b0a0d4d64a 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -889,21 +889,6 @@ pub trait HasAttrs: Sized { fn map_attrs) -> Vec>(self, f: F) -> Self; } -/// A cheap way to add Attributes to an AST node. -pub trait WithAttrs { - // FIXME: Could be extended to anything IntoIter - fn with_attrs(self, attrs: ThinAttributes) -> Self; -} - -impl 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 { fn attrs(&self) -> &[Attribute] { &self diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 83ddc79af8474..ff2683468e093 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::TokenTree; use ast; use ext::mtwt; -use ext::build::AstBuilder; use attr; -use attr::{AttrMetaMethods, WithAttrs, ThinAttributesExt}; +use attr::{AttrMetaMethods, ThinAttributesExt}; use codemap; use codemap::{Span, Spanned, ExpnInfo, ExpnId, NameAndSpan, MacroBang, MacroAttribute}; use config::StripUnconfigured; @@ -87,19 +86,18 @@ impl MacroGenerable for Option> { } } -pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P { +pub fn expand_expr(mut expr: ast::Expr, fld: &mut MacroExpander) -> P { 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) => { @@ -116,14 +114,12 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P { }); 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) => { @@ -140,8 +136,7 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P { 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) => { @@ -159,25 +154,21 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P { 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. @@ -236,7 +227,7 @@ fn expand_mac_invoc(mac: ast::Mac, ident: Option, attrs: Vec(mac: ast::Mac, ident: Option, attrs: Vec } -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: _ } => { @@ -1190,8 +1181,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), } @@ -1206,7 +1196,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 { +fn mark_tts(tts: Vec, m: Mrk) -> Vec { noop_fold_tts(tts, &mut Marker{mark:m, expn_id: None}) } @@ -1236,7 +1226,7 @@ mod tests { path_accumulator: Vec , } - 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()); @@ -1258,7 +1248,7 @@ mod tests { ident_accumulator: Vec } - impl<'v> Visitor<'v> for IdentFinder { + impl Visitor for IdentFinder { fn visit_ident(&mut self, _: codemap::Span, id: ast::Ident){ self.ident_accumulator.push(id); } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 871b0d4b1c023..5b509a4fdb2ea 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -31,7 +31,6 @@ pub mod rt { use ext::base::ExtCtxt; use parse::{self, token, classify}; use ptr::P; - use std::rc::Rc; use ast::TokenTree; @@ -214,12 +213,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(ast::Delimited { + r.push(TokenTree::Delimited(self.span, ast::Delimited { delim: token::Bracket, open_span: self.span, tts: self.node.value.to_tokens(cx), close_span: self.span, - }))); + })); r } } @@ -234,12 +233,12 @@ pub mod rt { impl ToTokens for () { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - vec![TokenTree::Delimited(DUMMY_SP, Rc::new(ast::Delimited { + vec![TokenTree::Delimited(DUMMY_SP, ast::Delimited { delim: token::Paren, open_span: DUMMY_SP, tts: vec![], close_span: DUMMY_SP, - }))] + })] } } @@ -789,14 +788,9 @@ fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, matcher: bool) -> Vec { parser: RefCell>, @@ -246,26 +245,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(ast::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: ast::KleeneOp::OneOrMore, - num_captures: 2 - })), - //to phase into semicolon-termination instead of - //semicolon-separation - TokenTree::Sequence(DUMMY_SP, - Rc::new(ast::SequenceRepetition { - tts: vec![TokenTree::Token(DUMMY_SP, token::Semi)], - separator: None, - op: ast::KleeneOp::ZeroOrMore, - num_captures: 0 - }))); + let argument_gram = vec![ + TokenTree::Sequence(DUMMY_SP, ast::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: ast::KleeneOp::OneOrMore, + num_captures: 2, + }), + // to phase into semicolon-termination instead of semicolon-separation + TokenTree::Sequence(DUMMY_SP, ast::SequenceRepetition { + tts: vec![TokenTree::Token(DUMMY_SP, token::Semi)], + separator: None, + op: ast::KleeneOp::ZeroOrMore, + num_captures: 0, + }), + ]; // Parse the macro_rules! invocation (`none` is for no interpolations): diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 6b3b5ce9de914..cf9c7e37ce8af 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(ast::SequenceRepetition { + forest: TokenTree::Sequence(DUMMY_SP, ast::SequenceRepetition { tts: src, // doesn't matter. This merely holds the root unzipping. separator: None, op: ast::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 86c4a33896d15..2ac394021df40 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -849,7 +849,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); @@ -1045,9 +1045,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 @@ -1086,7 +1086,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, @@ -1107,7 +1107,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, @@ -1130,7 +1130,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 edf418e33325b..b88e10e482241 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -27,8 +27,6 @@ use ptr::P; 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 @@ -227,11 +225,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 { + fn fold_tts(&mut self, tts: Vec) -> Vec { noop_fold_tts(tts, self) } @@ -519,8 +517,7 @@ pub fn noop_fold_mac(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) } @@ -547,34 +544,26 @@ pub fn noop_fold_arg(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg { } } -pub fn noop_fold_tt(tt: &TokenTree, fld: &mut T) -> TokenTree { - match *tt { +pub fn noop_fold_tt(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(tts: &[TokenTree], fld: &mut T) -> Vec { - // 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(tts: Vec, fld: &mut T) -> Vec { + tts.move_map(|tt| fld.fold_tt(tt)) } // apply ident folder if it's an ident, apply other folds to interpolated nodes @@ -632,7 +621,7 @@ pub fn noop_fold_interpolated(nt: token::Nonterminal, fld: &mut T) token::NtIdent(Box::new(Spanned::{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 2a9bcfd658c18..0d8a1599c6bbc 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -660,7 +660,6 @@ pub fn integer_lit(s: &str, #[cfg(test)] mod tests { use super::*; - use std::rc::Rc; use codemap::{Span, BytePos, Pos, Spanned, NO_EXPANSION}; use ast::{self, TokenTree, PatKind}; use abi::Abi; @@ -759,7 +758,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)) { @@ -770,10 +769,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), @@ -789,7 +788,7 @@ mod tests { TokenTree::Token(sp(3, 4), token::Ident(str_to_ident("a"))), TokenTree::Delimited( sp(5, 14), - Rc::new(ast::Delimited { + ast::Delimited { delim: token::DelimToken::Paren, open_span: sp(5, 6), tts: vec![ @@ -798,10 +797,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(ast::Delimited { + ast::Delimited { delim: token::DelimToken::Brace, open_span: sp(15, 16), tts: vec![ @@ -809,7 +808,7 @@ mod tests { TokenTree::Token(sp(18, 19), token::Semi), ], close_span: sp(20, 21), - })) + }) ]; assert_eq!(tts, expected); @@ -992,8 +991,8 @@ mod tests { struct PatIdentVisitor { spans: Vec } - 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 22cc20b8f8c44..d958fc09f885c 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}; @@ -1467,7 +1467,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) @@ -2348,7 +2348,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)) { @@ -2671,13 +2671,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))); @@ -2832,12 +2831,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, @@ -3661,7 +3660,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 { @@ -3979,7 +3978,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 { @@ -4000,7 +3999,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)) } @@ -4913,7 +4912,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) }; @@ -6002,7 +6001,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 5e3cd0773aa45..928ffb202d0b3 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/util/node_count.rs b/src/libsyntax/util/node_count.rs index 919dd84b11799..5d6f0323d8cf8 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 07a6317706b84..0b48c9f7032ba 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -49,57 +49,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 @@ -107,26 +107,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) } } @@ -145,46 +145,45 @@ macro_rules! walk_list { } } -pub fn walk_opt_name<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, opt_name: Option) { +pub fn walk_opt_name(visitor: &mut V, span: Span, opt_name: Option) { 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) { +pub fn walk_opt_ident(visitor: &mut V, span: Span, opt_ident: Option) { 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>) { +pub fn walk_opt_sp_ident(visitor: &mut V, opt_sp_ident: &Option>) { 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(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(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(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(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(visitor: &mut V, local: &Local) { for attr in local.attrs.as_attr_slice() { visitor.visit_attribute(attr); } @@ -193,33 +192,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(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(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(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(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(visitor: &mut V, item: &Item) { visitor.visit_vis(&item.vis); visitor.visit_ident(item.span, item.ident); match item.node { @@ -298,17 +291,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(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(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); @@ -316,7 +308,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(visitor: &mut V, typ: &Ty) { match typ.node { TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => { visitor.visit_ty(ty) @@ -362,28 +354,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(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(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(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(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); @@ -397,13 +386,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(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(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(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(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(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(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(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(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(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(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 { @@ -571,7 +554,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(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); @@ -593,25 +576,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(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(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(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(visitor: &mut V, statement: &Stmt) { match statement.node { StmtKind::Decl(ref declaration, _) => visitor.visit_decl(declaration), StmtKind::Expr(ref expression, _) | StmtKind::Semi(ref expression, _) => { @@ -626,18 +607,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(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(_: &mut V, _: &Mac) { // Empty! } -pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { +pub fn walk_expr(visitor: &mut V, expression: &Expr) { for attr in expression.attrs.as_attr_slice() { visitor.visit_attribute(attr); } @@ -787,14 +768,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(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(visitor: &mut V, vis: &Visibility) { if let Visibility::Restricted { ref path, id } = *vis { visitor.visit_path(path, id); } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index d6adec84e8440..3661454b4330c 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -353,8 +353,8 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec>, } - impl<'a> visit::Visitor<'a> for Visitor<'a> { - fn visit_ty(&mut self, ty: &'a ast::Ty) { + impl<'a> visit::Visitor for Visitor<'a> { + fn visit_ty(&mut self, ty: &ast::Ty) { match ty.node { ast::TyKind::Path(_, ref path) if !path.global => { match path.segments.first() {