diff options
| author | bors <bors@rust-lang.org> | 2014-09-12 13:45:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-09-12 13:45:41 +0000 |
| commit | 9c68679f2ebd5b165694e9346e4ad96a3e32aceb (patch) | |
| tree | 46712fd21dad760e4eb815a89dbcdd04665b32ed /src/libsyntax | |
| parent | e9278c92199ac46a486f476bc530bd4baec8fff9 (diff) | |
| parent | 7ef6ff06696c29dc956b17b9a5c57713b0c8e0cb (diff) | |
| download | rust-9c68679f2ebd5b165694e9346e4ad96a3e32aceb.tar.gz rust-9c68679f2ebd5b165694e9346e4ad96a3e32aceb.zip | |
auto merge of #17069 : eddyb/rust/visitor, r=pnkfelix
Few visitors used the context passing feature and it can be easily emulated. The added lifetime threading allows a visitor to keep safe references to AST nodes it visits, making a non-owning ast_map design possible, for #13316.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast_util.rs | 90 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 45 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 687 |
3 files changed, 378 insertions, 444 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 8ef13ef2604..ff733673bd2 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -366,17 +366,16 @@ impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> { } } -impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { +impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> { fn visit_mod(&mut self, module: &Mod, _: Span, - node_id: NodeId, - env: ()) { + node_id: NodeId) { self.operation.visit_id(node_id); - visit::walk_mod(self, module, env) + visit::walk_mod(self, module) } - fn visit_view_item(&mut self, view_item: &ViewItem, env: ()) { + fn visit_view_item(&mut self, view_item: &ViewItem) { if !self.pass_through_items { if self.visited_outermost { return; @@ -403,16 +402,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { } } } - visit::walk_view_item(self, view_item, env); + visit::walk_view_item(self, view_item); self.visited_outermost = false; } - fn visit_foreign_item(&mut self, foreign_item: &ForeignItem, env: ()) { + fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) { self.operation.visit_id(foreign_item.id); - visit::walk_foreign_item(self, foreign_item, env) + visit::walk_foreign_item(self, foreign_item) } - fn visit_item(&mut self, item: &Item, env: ()) { + fn visit_item(&mut self, item: &Item) { if !self.pass_through_items { if self.visited_outermost { return @@ -431,59 +430,58 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { _ => {} } - visit::walk_item(self, item, env); + visit::walk_item(self, item); self.visited_outermost = false } - fn visit_local(&mut self, local: &Local, env: ()) { + fn visit_local(&mut self, local: &Local) { self.operation.visit_id(local.id); - visit::walk_local(self, local, env) + visit::walk_local(self, local) } - fn visit_block(&mut self, block: &Block, env: ()) { + fn visit_block(&mut self, block: &Block) { self.operation.visit_id(block.id); - visit::walk_block(self, block, env) + visit::walk_block(self, block) } - fn visit_stmt(&mut self, statement: &Stmt, env: ()) { + fn visit_stmt(&mut self, statement: &Stmt) { self.operation.visit_id(ast_util::stmt_id(statement)); - visit::walk_stmt(self, statement, env) + visit::walk_stmt(self, statement) } - fn visit_pat(&mut self, pattern: &Pat, env: ()) { + fn visit_pat(&mut self, pattern: &Pat) { self.operation.visit_id(pattern.id); - visit::walk_pat(self, pattern, env) + visit::walk_pat(self, pattern) } - fn visit_expr(&mut self, expression: &Expr, env: ()) { + fn visit_expr(&mut self, expression: &Expr) { self.operation.visit_id(expression.id); - visit::walk_expr(self, expression, env) + visit::walk_expr(self, expression) } - fn visit_ty(&mut self, typ: &Ty, env: ()) { + fn visit_ty(&mut self, typ: &Ty) { self.operation.visit_id(typ.id); match typ.node { TyPath(_, _, id) => self.operation.visit_id(id), _ => {} } - visit::walk_ty(self, typ, env) + visit::walk_ty(self, typ) } - fn visit_generics(&mut self, generics: &Generics, env: ()) { + fn visit_generics(&mut self, generics: &Generics) { self.visit_generics_helper(generics); - visit::walk_generics(self, generics, env) + visit::walk_generics(self, generics) } fn visit_fn(&mut self, - function_kind: &visit::FnKind, - function_declaration: &FnDecl, - block: &Block, + function_kind: visit::FnKind<'v>, + function_declaration: &'v FnDecl, + block: &'v Block, span: Span, - node_id: NodeId, - env: ()) { + node_id: NodeId) { if !self.pass_through_items { - match *function_kind { + match function_kind { visit::FkMethod(..) if self.visited_outermost => return, visit::FkMethod(..) => self.visited_outermost = true, _ => {} @@ -492,7 +490,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { self.operation.visit_id(node_id); - match *function_kind { + match function_kind { visit::FkItemFn(_, generics, _, _) | visit::FkMethod(_, generics, _) => { self.visit_generics_helper(generics) @@ -508,39 +506,37 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { function_kind, function_declaration, block, - span, - env); + span); if !self.pass_through_items { - match *function_kind { + match function_kind { visit::FkMethod(..) => self.visited_outermost = false, _ => {} } } } - fn visit_struct_field(&mut self, struct_field: &StructField, env: ()) { + fn visit_struct_field(&mut self, struct_field: &StructField) { self.operation.visit_id(struct_field.node.id); - visit::walk_struct_field(self, struct_field, env) + visit::walk_struct_field(self, struct_field) } fn visit_struct_def(&mut self, struct_def: &StructDef, _: ast::Ident, _: &ast::Generics, - id: NodeId, - _: ()) { + id: NodeId) { self.operation.visit_id(id); struct_def.ctor_id.map(|ctor_id| self.operation.visit_id(ctor_id)); - visit::walk_struct_def(self, struct_def, ()); + visit::walk_struct_def(self, struct_def); } - fn visit_trait_item(&mut self, tm: &ast::TraitItem, _: ()) { + fn visit_trait_item(&mut self, tm: &ast::TraitItem) { match *tm { ast::RequiredMethod(ref m) => self.operation.visit_id(m.id), ast::ProvidedMethod(ref m) => self.operation.visit_id(m.id), } - visit::walk_trait_item(self, tm, ()); + visit::walk_trait_item(self, tm); } } @@ -552,7 +548,7 @@ pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem, visited_outermost: false, }; - visit::walk_inlined_item(&mut id_visitor, item, ()); + visit::walk_inlined_item(&mut id_visitor, item); } struct IdRangeComputingVisitor { @@ -575,7 +571,7 @@ pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange { visitor.result.get() } -pub fn compute_id_range_for_fn_body(fk: &visit::FnKind, +pub fn compute_id_range_for_fn_body(fk: visit::FnKind, decl: &FnDecl, body: &Block, sp: Span, @@ -595,7 +591,7 @@ pub fn compute_id_range_for_fn_body(fk: &visit::FnKind, pass_through_items: false, visited_outermost: false, }; - id_visitor.visit_fn(fk, decl, body, sp, id, ()); + id_visitor.visit_fn(fk, decl, body, sp, id); visitor.result.get() } @@ -643,8 +639,8 @@ struct EachViewItemData<'a> { callback: |&ast::ViewItem|: 'a -> bool, } -impl<'a> Visitor<()> for EachViewItemData<'a> { - fn visit_view_item(&mut self, view_item: &ast::ViewItem, _: ()) { +impl<'a, 'v> Visitor<'v> for EachViewItemData<'a> { + fn visit_view_item(&mut self, view_item: &ast::ViewItem) { let _ = (self.callback)(view_item); } } @@ -654,7 +650,7 @@ impl EachViewItem for ast::Crate { let mut visit = EachViewItemData { callback: f, }; - visit::walk_crate(&mut visit, self, ()); + visit::walk_crate(&mut visit, self); true } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d0f3cf6f9d7..8b10c26c43c 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -648,29 +648,29 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm { /// array #[deriving(Clone)] struct PatIdentFinder { - ident_accumulator: Vec<ast::Ident> , + ident_accumulator: Vec<ast::Ident> } -impl Visitor<()> for PatIdentFinder { - fn visit_pat(&mut self, pattern: &ast::Pat, _: ()) { +impl<'v> Visitor<'v> for PatIdentFinder { + fn visit_pat(&mut self, pattern: &ast::Pat) { match *pattern { ast::Pat { id: _, node: ast::PatIdent(_, ref path1, ref inner), span: _ } => { self.ident_accumulator.push(path1.node); // visit optional subpattern of PatIdent: for subpat in inner.iter() { - self.visit_pat(&**subpat, ()) + self.visit_pat(&**subpat) } } // use the default traversal for non-PatIdents - _ => visit::walk_pat(self, pattern, ()) + _ => visit::walk_pat(self, pattern) } } } /// find the PatIdent paths in a pattern -fn pattern_bindings(pat : &ast::Pat) -> Vec<ast::Ident> { +fn pattern_bindings(pat: &ast::Pat) -> Vec<ast::Ident> { let mut name_finder = PatIdentFinder{ident_accumulator:Vec::new()}; - name_finder.visit_pat(pat,()); + name_finder.visit_pat(pat); name_finder.ident_accumulator } @@ -678,7 +678,7 @@ fn pattern_bindings(pat : &ast::Pat) -> Vec<ast::Ident> { fn fn_decl_arg_bindings(fn_decl: &ast::FnDecl) -> Vec<ast::Ident> { let mut pat_idents = PatIdentFinder{ident_accumulator:Vec::new()}; for arg in fn_decl.inputs.iter() { - pat_idents.visit_pat(&*arg.pat, ()); + pat_idents.visit_pat(&*arg.pat); } pat_idents.ident_accumulator } @@ -1099,7 +1099,7 @@ fn original_span(cx: &ExtCtxt) -> Gc<codemap::ExpnInfo> { /// Check that there are no macro invocations left in the AST: pub fn check_for_macros(sess: &parse::ParseSess, krate: &ast::Crate) { - visit::walk_crate(&mut MacroExterminator{sess:sess}, krate, ()); + visit::walk_crate(&mut MacroExterminator{sess:sess}, krate); } /// A visitor that ensures that no macro invocations remain in an AST. @@ -1107,8 +1107,8 @@ struct MacroExterminator<'a>{ sess: &'a parse::ParseSess } -impl<'a> visit::Visitor<()> for MacroExterminator<'a> { - fn visit_mac(&mut self, macro: &ast::Mac, _:()) { +impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> { + fn visit_mac(&mut self, macro: &ast::Mac) { self.sess.span_diagnostic.span_bug(macro.span, "macro exterminator: expected AST \ with no macro invocations"); @@ -1144,15 +1144,14 @@ mod test { path_accumulator: Vec<ast::Path> , } - impl Visitor<()> for PathExprFinderContext { - - fn visit_expr(&mut self, expr: &ast::Expr, _: ()) { - match *expr { - ast::Expr{id:_,span:_,node:ast::ExprPath(ref p)} => { + impl<'v> Visitor<'v> for PathExprFinderContext { + fn visit_expr(&mut self, expr: &ast::Expr) { + match expr.node { + ast::ExprPath(ref p) => { self.path_accumulator.push(p.clone()); // not calling visit_path, but it should be fine. } - _ => visit::walk_expr(self,expr,()) + _ => visit::walk_expr(self, expr) } } } @@ -1160,18 +1159,18 @@ mod test { // find the variable references in a crate fn crate_varrefs(the_crate : &ast::Crate) -> Vec<ast::Path> { let mut path_finder = PathExprFinderContext{path_accumulator:Vec::new()}; - visit::walk_crate(&mut path_finder, the_crate, ()); + visit::walk_crate(&mut path_finder, the_crate); path_finder.path_accumulator } /// A Visitor that extracts the identifiers from a thingy. // as a side note, I'm starting to want to abstract over these.... - struct IdentFinder{ + struct IdentFinder { ident_accumulator: Vec<ast::Ident> } - impl Visitor<()> for IdentFinder { - fn visit_ident(&mut self, _: codemap::Span, id: ast::Ident, _: ()){ + impl<'v> Visitor<'v> for IdentFinder { + fn visit_ident(&mut self, _: codemap::Span, id: ast::Ident){ self.ident_accumulator.push(id); } } @@ -1179,7 +1178,7 @@ mod test { /// Find the idents in a crate fn crate_idents(the_crate: &ast::Crate) -> Vec<ast::Ident> { let mut ident_finder = IdentFinder{ident_accumulator: Vec::new()}; - visit::walk_crate(&mut ident_finder, the_crate, ()); + visit::walk_crate(&mut ident_finder, the_crate); ident_finder.ident_accumulator } @@ -1277,7 +1276,7 @@ mod test { // find the pat_ident paths in a crate fn crate_bindings(the_crate : &ast::Crate) -> Vec<ast::Ident> { let mut name_finder = PatIdentFinder{ident_accumulator:Vec::new()}; - visit::walk_crate(&mut name_finder, the_crate, ()); + visit::walk_crate(&mut name_finder, the_crate); name_finder.ident_accumulator } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 50b42ea2c0f..2a989e6d63a 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -8,11 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Context-passing AST walker. Each overridden visit method has full control -//! over what happens with its node, it can do its own traversal of the node's -//! children (potentially passing in different contexts to each), call -//! `visit::visit_*` to apply the default traversal algorithm (again, it can -//! override the context), or prevent deeper traversal by doing nothing. +//! AST walker. Each overridden visit method has full control over what +//! happens with its node, it can do its own traversal of the node's children, +//! call `visit::walk_*` to apply the default traversal algorithm, or prevent +//! deeper traversal by doing nothing. //! //! Note: it is an important invariant that the default visitor walks the body //! of a function in "execution order" (more concretely, reverse post-order @@ -27,9 +26,7 @@ use abi::Abi; use ast::*; use ast; -use ast_util; use codemap::Span; -use parse; use owned_slice::OwnedSlice; use std::gc::Gc; @@ -46,23 +43,6 @@ pub enum FnKind<'a> { FkFnBlock, } -pub fn name_of_fn(fk: &FnKind) -> Ident { - match *fk { - FkItemFn(name, _, _, _) | FkMethod(name, _, _) => name, - FkFnBlock(..) => parse::token::special_idents::invalid - } -} - -pub fn generics_of_fn(fk: &FnKind) -> Generics { - match *fk { - FkItemFn(_, generics, _, _) | - FkMethod(_, generics, _) => { - (*generics).clone() - } - FkFnBlock(..) => ast_util::empty_generics(), - } -} - /// Each method of the Visitor trait is a hook to be potentially /// overridden. Each method's default implementation recursively visits /// the substructure of the input via the corresponding `walk` method; @@ -72,85 +52,82 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics { /// 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<E: Clone> { +pub trait Visitor<'v> { - fn visit_ident(&mut self, _sp: Span, _ident: Ident, _e: E) { + fn visit_ident(&mut self, _sp: Span, _ident: Ident) { /*! Visit the idents */ } - fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId, e: E) { walk_mod(self, m, e) } - fn visit_view_item(&mut self, i: &ViewItem, e: E) { walk_view_item(self, i, e) } - fn visit_foreign_item(&mut self, i: &ForeignItem, e: E) { walk_foreign_item(self, i, e) } - fn visit_item(&mut self, i: &Item, e: E) { walk_item(self, i, e) } - fn visit_local(&mut self, l: &Local, e: E) { walk_local(self, l, e) } - fn visit_block(&mut self, b: &Block, e: E) { walk_block(self, b, e) } - fn visit_stmt(&mut self, s: &Stmt, e: E) { walk_stmt(self, s, e) } - fn visit_arm(&mut self, a: &Arm, e: E) { walk_arm(self, a, e) } - fn visit_pat(&mut self, p: &Pat, e: E) { walk_pat(self, p, e) } - fn visit_decl(&mut self, d: &Decl, e: E) { walk_decl(self, d, e) } - fn visit_expr(&mut self, ex: &Expr, e: E) { walk_expr(self, ex, e) } - fn visit_expr_post(&mut self, _ex: &Expr, _e: E) { } - fn visit_ty(&mut self, t: &Ty, e: E) { walk_ty(self, t, e) } - fn visit_generics(&mut self, g: &Generics, e: E) { walk_generics(self, g, e) } - fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, _: NodeId, e: E) { - walk_fn(self, fk, fd, b, s, e) - } - fn visit_ty_method(&mut self, t: &TypeMethod, e: E) { walk_ty_method(self, t, e) } - fn visit_trait_item(&mut self, t: &TraitItem, e: E) { walk_trait_item(self, t, e) } - fn visit_struct_def(&mut self, s: &StructDef, _: Ident, _: &Generics, _: NodeId, e: E) { - walk_struct_def(self, s, e) - } - fn visit_struct_field(&mut self, s: &StructField, e: E) { walk_struct_field(self, s, e) } - fn visit_variant(&mut self, v: &Variant, g: &Generics, e: E) { walk_variant(self, v, g, e) } + fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) } + fn visit_view_item(&mut self, i: &'v ViewItem) { walk_view_item(self, i) } + 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) { + walk_fn(self, fk, fd, b, s) + } + fn visit_ty_method(&mut self, t: &'v TypeMethod) { walk_ty_method(self, t) } + fn visit_trait_item(&mut self, t: &'v TraitItem) { walk_trait_item(self, t) } + fn visit_struct_def(&mut self, s: &'v StructDef, _: Ident, _: &'v Generics, _: NodeId) { + walk_struct_def(self, s) + } + fn visit_struct_field(&mut self, s: &'v StructField) { walk_struct_field(self, s) } + fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics) { walk_variant(self, v, g) } fn visit_opt_lifetime_ref(&mut self, _span: Span, - opt_lifetime: &Option<Lifetime>, - env: E) { + opt_lifetime: &'v Option<Lifetime>) { /*! * Visits an optional reference to a lifetime. The `span` is * the span of some surrounding reference should opt_lifetime * be None. */ match *opt_lifetime { - Some(ref l) => self.visit_lifetime_ref(l, env), + Some(ref l) => self.visit_lifetime_ref(l), None => () } } - fn visit_lifetime_ref(&mut self, _lifetime: &Lifetime, _e: E) { + fn visit_lifetime_ref(&mut self, _lifetime: &'v Lifetime) { /*! Visits a reference to a lifetime */ } - fn visit_lifetime_decl(&mut self, _lifetime: &LifetimeDef, _e: E) { + fn visit_lifetime_decl(&mut self, _lifetime: &'v LifetimeDef) { /*! Visits a declaration of a lifetime */ } - fn visit_explicit_self(&mut self, es: &ExplicitSelf, e: E) { - walk_explicit_self(self, es, e) + fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) { + walk_explicit_self(self, es) } - fn visit_mac(&mut self, _macro: &Mac, _e: E) { + fn visit_mac(&mut self, _macro: &'v Mac) { fail!("visit_mac disabled by default"); // NB: see note about macros above. // if you really want a visitor that // works on macros, use this // definition in your trait impl: - // visit::walk_mac(self, _macro, _e) + // visit::walk_mac(self, _macro) } - fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) { - walk_path(self, path, e) + fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) { + walk_path(self, path) } - fn visit_attribute(&mut self, _attr: &Attribute, _e: E) {} + fn visit_attribute(&mut self, _attr: &'v Attribute) {} } -pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V, - item: &ast::InlinedItem, - env: E) { +pub fn walk_inlined_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v InlinedItem) { match *item { - IIItem(i) => visitor.visit_item(&*i, env), - IIForeign(i) => visitor.visit_foreign_item(&*i, env), - IITraitItem(_, iti) => { - match iti { - ProvidedInlinedTraitItem(m) => { - walk_method_helper(visitor, &*m, env) + IIItem(ref i) => visitor.visit_item(&**i), + IIForeign(ref i) => visitor.visit_foreign_item(&**i), + IITraitItem(_, ref iti) => { + match *iti { + ProvidedInlinedTraitItem(ref m) => { + walk_method_helper(visitor, &**m) } - RequiredInlinedTraitItem(m) => { - walk_method_helper(visitor, &*m, env) + RequiredInlinedTraitItem(ref m) => { + walk_method_helper(visitor, &**m) } } } @@ -158,719 +135,681 @@ pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V, } -pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, krate: &Crate, env: E) { - visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env.clone()); +pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) { + visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID); for attr in krate.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } -pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) { +pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) { for view_item in module.view_items.iter() { - visitor.visit_view_item(view_item, env.clone()) + visitor.visit_view_item(view_item) } for item in module.items.iter() { - visitor.visit_item(&**item, env.clone()) + visitor.visit_item(&**item) } } -pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, env: E) { +pub fn walk_view_item<'v, V: Visitor<'v>>(visitor: &mut V, vi: &'v ViewItem) { match vi.node { ViewItemExternCrate(name, _, _) => { - visitor.visit_ident(vi.span, name, env.clone()) + visitor.visit_ident(vi.span, name) } ViewItemUse(ref vp) => { match vp.node { ViewPathSimple(ident, ref path, id) => { - visitor.visit_ident(vp.span, ident, env.clone()); - visitor.visit_path(path, id, env.clone()); + visitor.visit_ident(vp.span, ident); + visitor.visit_path(path, id); } ViewPathGlob(ref path, id) => { - visitor.visit_path(path, id, env.clone()); + visitor.visit_path(path, id); } ViewPathList(ref path, ref list, _) => { for id in list.iter() { match id.node { PathListIdent { name, .. } => { - visitor.visit_ident(id.span, name, env.clone()); + visitor.visit_ident(id.span, name); } PathListMod { .. } => () } } - walk_path(visitor, path, env.clone()); + walk_path(visitor, path); } } } } for attr in vi.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } -pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: E) { - visitor.visit_pat(&*local.pat, env.clone()); - visitor.visit_ty(&*local.ty, env.clone()); - match local.init { - None => {} - Some(initializer) => visitor.visit_expr(&*initializer, env), - } +pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { + visitor.visit_pat(&*local.pat); + visitor.visit_ty(&*local.ty); + walk_expr_opt(visitor, &local.init); } -pub fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V, - explicit_self: &ExplicitSelf, - env: E) { +pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V, + explicit_self: &'v ExplicitSelf) { match explicit_self.node { SelfStatic | SelfValue(_) => {}, SelfRegion(ref lifetime, _, _) => { - visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env) + visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime) } - SelfExplicit(ref typ, _) => visitor.visit_ty(&**typ, env.clone()), + SelfExplicit(ref typ, _) => visitor.visit_ty(&**typ), } } /// Like with walk_method_helper this doesn't correspond to a method /// in Visitor, and so it gets a _helper suffix. -pub fn walk_trait_ref_helper<E: Clone, V: Visitor<E>>(visitor: &mut V, - trait_ref: &TraitRef, - env: E) { - visitor.visit_path(&trait_ref.path, trait_ref.ref_id, env) +pub fn walk_trait_ref_helper<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef) { + visitor.visit_path(&trait_ref.path, trait_ref.ref_id) } -pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E) { - visitor.visit_ident(item.span, item.ident, env.clone()); +pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { + visitor.visit_ident(item.span, item.ident); match item.node { ItemStatic(ref typ, _, ref expr) => { - visitor.visit_ty(&**typ, env.clone()); - visitor.visit_expr(&**expr, env.clone()); + visitor.visit_ty(&**typ); + visitor.visit_expr(&**expr); } - ItemFn(declaration, fn_style, abi, ref generics, body) => { - visitor.visit_fn(&FkItemFn(item.ident, generics, fn_style, abi), - &*declaration, - &*body, + ItemFn(ref declaration, fn_style, abi, ref generics, ref body) => { + visitor.visit_fn(FkItemFn(item.ident, generics, fn_style, abi), + &**declaration, + &**body, item.span, - item.id, - env.clone()) + item.id) } ItemMod(ref module) => { - visitor.visit_mod(module, item.span, item.id, env.clone()) + visitor.visit_mod(module, item.span, item.id) } ItemForeignMod(ref foreign_module) => { for view_item in foreign_module.view_items.iter() { - visitor.visit_view_item(view_item, env.clone()) + visitor.visit_view_item(view_item) } for foreign_item in foreign_module.items.iter() { - visitor.visit_foreign_item(&**foreign_item, env.clone()) + visitor.visit_foreign_item(&**foreign_item) } } ItemTy(ref typ, ref type_parameters) => { - visitor.visit_ty(&**typ, env.clone()); - visitor.visit_generics(type_parameters, env.clone()) + visitor.visit_ty(&**typ); + visitor.visit_generics(type_parameters) } ItemEnum(ref enum_definition, ref type_parameters) => { - visitor.visit_generics(type_parameters, env.clone()); - walk_enum_def(visitor, enum_definition, type_parameters, env.clone()) + visitor.visit_generics(type_parameters); + walk_enum_def(visitor, enum_definition, type_parameters) } ItemImpl(ref type_parameters, ref trait_reference, - typ, + ref typ, ref impl_items) => { - visitor.visit_generics(type_parameters, env.clone()); + visitor.visit_generics(type_parameters); match *trait_reference { Some(ref trait_reference) => walk_trait_ref_helper(visitor, - trait_reference, env.clone()), + trait_reference), None => () } - visitor.visit_ty(&*typ, env.clone()); + visitor.visit_ty(&**typ); for impl_item in impl_items.iter() { match *impl_item { - MethodImplItem(method) => { - walk_method_helper(visitor, &*method, env.clone()) + MethodImplItem(ref method) => { + walk_method_helper(visitor, &**method) } } } } ItemStruct(ref struct_definition, ref generics) => { - visitor.visit_generics(generics, env.clone()); + visitor.visit_generics(generics); visitor.visit_struct_def(&**struct_definition, item.ident, generics, - item.id, - env.clone()) + item.id) } ItemTrait(ref generics, _, ref bounds, ref methods) => { - visitor.visit_generics(generics, env.clone()); - walk_ty_param_bounds(visitor, bounds, env.clone()); + visitor.visit_generics(generics); + walk_ty_param_bounds(visitor, bounds); for method in methods.iter() { - visitor.visit_trait_item(method, env.clone()) + visitor.visit_trait_item(method) } } - ItemMac(ref macro) => visitor.visit_mac(macro, env.clone()), + ItemMac(ref macro) => visitor.visit_mac(macro), } for attr in item.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } -pub fn walk_enum_def<E: Clone, V:Visitor<E>>(visitor: &mut V, - enum_definition: &EnumDef, - generics: &Generics, - env: E) { - for &variant in enum_definition.variants.iter() { - visitor.visit_variant(&*variant, generics, env.clone()); +pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, + enum_definition: &'v EnumDef, + generics: &'v Generics) { + for variant in enum_definition.variants.iter() { + visitor.visit_variant(&**variant, generics); } } -pub fn walk_variant<E: Clone, V: Visitor<E>>(visitor: &mut V, - variant: &Variant, - generics: &Generics, - env: E) { - visitor.visit_ident(variant.span, variant.node.name, env.clone()); +pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, + variant: &'v Variant, + generics: &'v Generics) { + visitor.visit_ident(variant.span, variant.node.name); match variant.node.kind { TupleVariantKind(ref variant_arguments) => { for variant_argument in variant_arguments.iter() { - visitor.visit_ty(&*variant_argument.ty, env.clone()) + visitor.visit_ty(&*variant_argument.ty) } } StructVariantKind(ref struct_definition) => { visitor.visit_struct_def(&**struct_definition, variant.node.name, generics, - variant.node.id, - env.clone()) + variant.node.id) } } match variant.node.disr_expr { - Some(ref expr) => visitor.visit_expr(&**expr, env.clone()), + Some(ref expr) => visitor.visit_expr(&**expr), None => () } for attr in variant.node.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } -pub fn skip_ty<E, V: Visitor<E>>(_: &mut V, _: &Ty, _: E) { +pub fn skip_ty<'v, V: Visitor<'v>>(_: &mut V, _: &'v Ty) { // Empty! } -pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) { +pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { match typ.node { - TyUniq(ty) | TyVec(ty) | TyBox(ty) | TyParen(ty) => { - visitor.visit_ty(&*ty, env) + TyUniq(ref ty) | TyVec(ref ty) | TyBox(ref ty) | TyParen(ref ty) => { + visitor.visit_ty(&**ty) } TyPtr(ref mutable_type) => { - visitor.visit_ty(&*mutable_type.ty, env) + visitor.visit_ty(&*mutable_type.ty) } TyRptr(ref lifetime, ref mutable_type) => { - visitor.visit_opt_lifetime_ref(typ.span, lifetime, env.clone()); - visitor.visit_ty(&*mutable_type.ty, env) + visitor.visit_opt_lifetime_ref(typ.span, lifetime); + visitor.visit_ty(&*mutable_type.ty) } TyTup(ref tuple_element_types) => { - for &tuple_element_type in tuple_element_types.iter() { - visitor.visit_ty(&*tuple_element_type, env.clone()) + for tuple_element_type in tuple_element_types.iter() { + visitor.visit_ty(&**tuple_element_type) } } TyClosure(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty, env.clone()) + visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output, env.clone()); - walk_ty_param_bounds(visitor, &function_declaration.bounds, - env.clone()); - walk_lifetime_decls(visitor, &function_declaration.lifetimes, - env.clone()); + visitor.visit_ty(&*function_declaration.decl.output); + walk_ty_param_bounds(visitor, &function_declaration.bounds); + walk_lifetime_decls(visitor, &function_declaration.lifetimes); } TyProc(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty, env.clone()) + visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output, env.clone()); - walk_ty_param_bounds(visitor, &function_declaration.bounds, - env.clone()); - walk_lifetime_decls(visitor, &function_declaration.lifetimes, - env.clone()); + visitor.visit_ty(&*function_declaration.decl.output); + walk_ty_param_bounds(visitor, &function_declaration.bounds); + walk_lifetime_decls(visitor, &function_declaration.lifetimes); } TyBareFn(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty, env.clone()) + visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output, env.clone()); - walk_lifetime_decls(visitor, &function_declaration.lifetimes, - env.clone()); + visitor.visit_ty(&*function_declaration.decl.output); + walk_lifetime_decls(visitor, &function_declaration.lifetimes); } TyUnboxedFn(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty, env.clone()) + visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output, env.clone()); + visitor.visit_ty(&*function_declaration.decl.output); } TyPath(ref path, ref opt_bounds, id) => { - visitor.visit_path(path, id, env.clone()); + visitor.visit_path(path, id); match *opt_bounds { Some(ref bounds) => { - walk_ty_param_bounds(visitor, bounds, env.clone()); + walk_ty_param_bounds(visitor, bounds); } None => { } } } TyFixedLengthVec(ref ty, ref expression) => { - visitor.visit_ty(&**ty, env.clone()); - visitor.visit_expr(&**expression, env) + visitor.visit_ty(&**ty); + visitor.visit_expr(&**expression) } TyTypeof(ref expression) => { - visitor.visit_expr(&**expression, env) + visitor.visit_expr(&**expression) } TyNil | TyBot | TyInfer => {} } } -fn walk_lifetime_decls<E: Clone, V: Visitor<E>>(visitor: &mut V, - lifetimes: &Vec<LifetimeDef>, - env: E) { +fn walk_lifetime_decls<'v, V: Visitor<'v>>(visitor: &mut V, + lifetimes: &'v Vec<LifetimeDef>) { for l in lifetimes.iter() { - visitor.visit_lifetime_decl(l, env.clone()); + visitor.visit_lifetime_decl(l); } } -pub fn walk_path<E: Clone, V: Visitor<E>>(visitor: &mut V, path: &Path, env: E) { +pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { for segment in path.segments.iter() { - visitor.visit_ident(path.span, segment.identifier, env.clone()); + visitor.visit_ident(path.span, segment.identifier); for typ in segment.types.iter() { - visitor.visit_ty(&**typ, env.clone()); + visitor.visit_ty(&**typ); } for lifetime in segment.lifetimes.iter() { - visitor.visit_lifetime_ref(lifetime, env.clone()); + visitor.visit_lifetime_ref(lifetime); } } } -pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) { +pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { match pattern.node { PatEnum(ref path, ref children) => { - visitor.visit_path(path, pattern.id, env.clone()); + visitor.visit_path(path, pattern.id); for children in children.iter() { for child in children.iter() { - visitor.visit_pat(&**child, env.clone()) + visitor.visit_pat(&**child) } } } PatStruct(ref path, ref fields, _) => { - visitor.visit_path(path, pattern.id, env.clone()); + visitor.visit_path(path, pattern.id); for field in fields.iter() { - visitor.visit_pat(&*field.pat, env.clone()) + visitor.visit_pat(&*field.pat) } } PatTup(ref tuple_elements) => { for tuple_element in tuple_elements.iter() { - visitor.visit_pat(&**tuple_element, env.clone()) + visitor.visit_pat(&**tuple_element) } } PatBox(ref subpattern) | PatRegion(ref subpattern) => { - visitor.visit_pat(&**subpattern, env) + visitor.visit_pat(&**subpattern) } PatIdent(_, ref pth1, ref optional_subpattern) => { - visitor.visit_ident(pth1.span, pth1.node, env.clone()); + visitor.visit_ident(pth1.span, pth1.node); match *optional_subpattern { None => {} - Some(ref subpattern) => visitor.visit_pat(&**subpattern, env), + Some(ref subpattern) => visitor.visit_pat(&**subpattern), } } - PatLit(ref expression) => visitor.visit_expr(&**expression, env), + PatLit(ref expression) => visitor.visit_expr(&**expression), PatRange(ref lower_bound, ref upper_bound) => { - visitor.visit_expr(&**lower_bound, env.clone()); - visitor.visit_expr(&**upper_bound, env) + visitor.visit_expr(&**lower_bound); + visitor.visit_expr(&**upper_bound) } PatWild(_) => (), PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => { for prepattern in prepattern.iter() { - visitor.visit_pat(&**prepattern, env.clone()) + visitor.visit_pat(&**prepattern) } for slice_pattern in slice_pattern.iter() { - visitor.visit_pat(&**slice_pattern, env.clone()) + visitor.visit_pat(&**slice_pattern) } for postpattern in postpatterns.iter() { - visitor.visit_pat(&**postpattern, env.clone()) + visitor.visit_pat(&**postpattern) } } - PatMac(ref macro) => visitor.visit_mac(macro, env), + PatMac(ref macro) => visitor.visit_mac(macro), } } -pub fn walk_foreign_item<E: Clone, V: Visitor<E>>(visitor: &mut V, - foreign_item: &ForeignItem, - env: E) { - visitor.visit_ident(foreign_item.span, foreign_item.ident, env.clone()); +pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, + foreign_item: &'v ForeignItem) { + visitor.visit_ident(foreign_item.span, foreign_item.ident); match foreign_item.node { ForeignItemFn(ref function_declaration, ref generics) => { - walk_fn_decl(visitor, &**function_declaration, env.clone()); - visitor.visit_generics(generics, env.clone()) + walk_fn_decl(visitor, &**function_declaration); + visitor.visit_generics(generics) } - ForeignItemStatic(ref typ, _) => visitor.visit_ty(&**typ, env.clone()), + ForeignItemStatic(ref typ, _) => visitor.visit_ty(&**typ), } for attr in foreign_item.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } -pub fn walk_ty_param_bounds<E: Clone, V: Visitor<E>>(visitor: &mut V, - bounds: &OwnedSlice<TyParamBound>, - env: E) { +pub fn walk_ty_param_bounds<'v, V: Visitor<'v>>(visitor: &mut V, + bounds: &'v OwnedSlice<TyParamBound>) { for bound in bounds.iter() { match *bound { TraitTyParamBound(ref typ) => { - walk_trait_ref_helper(visitor, typ, env.clone()) + walk_trait_ref_helper(visitor, typ) } UnboxedFnTyParamBound(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty, env.clone()) + visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output, - env.clone()); + visitor.visit_ty(&*function_declaration.decl.output); } RegionTyParamBound(ref lifetime) => { - visitor.visit_lifetime_ref(lifetime, env.clone()); + visitor.visit_lifetime_ref(lifetime); } } } } -pub fn walk_generics<E: Clone, V: Visitor<E>>(visitor: &mut V, - generics: &Generics, - env: E) { +pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { for type_parameter in generics.ty_params.iter() { - walk_ty_param_bounds(visitor, &type_parameter.bounds, env.clone()); + walk_ty_param_bounds(visitor, &type_parameter.bounds); match type_parameter.default { - Some(ref ty) => visitor.visit_ty(&**ty, env.clone()), + Some(ref ty) => visitor.visit_ty(&**ty), None => {} } } - walk_lifetime_decls(visitor, &generics.lifetimes, env.clone()); + walk_lifetime_decls(visitor, &generics.lifetimes); for predicate in generics.where_clause.predicates.iter() { - visitor.visit_ident(predicate.span, predicate.ident, env.clone()); - walk_ty_param_bounds(visitor, &predicate.bounds, env.clone()); + visitor.visit_ident(predicate.span, predicate.ident); + walk_ty_param_bounds(visitor, &predicate.bounds); } } -pub fn walk_fn_decl<E: Clone, V: Visitor<E>>(visitor: &mut V, - function_declaration: &FnDecl, - env: E) { +pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) { for argument in function_declaration.inputs.iter() { - visitor.visit_pat(&*argument.pat, env.clone()); - visitor.visit_ty(&*argument.ty, env.clone()) + visitor.visit_pat(&*argument.pat); + visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.output, env) + visitor.visit_ty(&*function_declaration.output) } // Note: there is no visit_method() method in the visitor, instead override // visit_fn() and check for FkMethod(). I named this visit_method_helper() // because it is not a default impl of any method, though I doubt that really // clarifies anything. - Niko -pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V, - method: &Method, - env: E) { +pub fn walk_method_helper<'v, V: Visitor<'v>>(visitor: &mut V, method: &'v Method) { match method.node { - MethDecl(ident, ref generics, _, _, _, decl, body, _) => { - visitor.visit_ident(method.span, ident, env.clone()); - visitor.visit_fn(&FkMethod(ident, generics, method), - &*decl, - &*body, + MethDecl(ident, ref generics, _, _, _, ref decl, ref body, _) => { + visitor.visit_ident(method.span, ident); + visitor.visit_fn(FkMethod(ident, generics, method), + &**decl, + &**body, method.span, - method.id, - env.clone()); + method.id); for attr in method.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } }, - MethMac(ref mac) => visitor.visit_mac(mac, env.clone()) + MethMac(ref mac) => visitor.visit_mac(mac) } } -pub fn walk_fn<E: Clone, V: Visitor<E>>(visitor: &mut V, - function_kind: &FnKind, - function_declaration: &FnDecl, - function_body: &Block, - _span: Span, - env: E) { - walk_fn_decl(visitor, function_declaration, env.clone()); +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); - match *function_kind { + match function_kind { FkItemFn(_, generics, _, _) => { - visitor.visit_generics(generics, env.clone()); + visitor.visit_generics(generics); } FkMethod(_, generics, method) => { - visitor.visit_generics(generics, env.clone()); + visitor.visit_generics(generics); match method.node { MethDecl(_, _, _, ref explicit_self, _, _, _, _) => - visitor.visit_explicit_self(explicit_self, env.clone()), + visitor.visit_explicit_self(explicit_self), MethMac(ref mac) => - visitor.visit_mac(mac, env.clone()) + visitor.visit_mac(mac) } } FkFnBlock(..) => {} } - visitor.visit_block(function_body, env) + visitor.visit_block(function_body) } -pub fn walk_ty_method<E: Clone, V: Visitor<E>>(visitor: &mut V, - method_type: &TypeMethod, - env: E) { - visitor.visit_ident(method_type.span, method_type.ident, env.clone()); - visitor.visit_explicit_self(&method_type.explicit_self, env.clone()); +pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v TypeMethod) { + visitor.visit_ident(method_type.span, method_type.ident); + visitor.visit_explicit_self(&method_type.explicit_self); for argument_type in method_type.decl.inputs.iter() { - visitor.visit_ty(&*argument_type.ty, env.clone()) + visitor.visit_ty(&*argument_type.ty) } - visitor.visit_generics(&method_type.generics, env.clone()); - visitor.visit_ty(&*method_type.decl.output, env.clone()); + visitor.visit_generics(&method_type.generics); + visitor.visit_ty(&*method_type.decl.output); for attr in method_type.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } -pub fn walk_trait_item<E: Clone, V: Visitor<E>>(visitor: &mut V, - trait_method: &TraitItem, - env: E) { +pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v TraitItem) { match *trait_method { RequiredMethod(ref method_type) => { - visitor.visit_ty_method(method_type, env) + visitor.visit_ty_method(method_type) } - ProvidedMethod(ref method) => walk_method_helper(visitor, &**method, env), + ProvidedMethod(ref method) => walk_method_helper(visitor, &**method), } } -pub fn walk_struct_def<E: Clone, V: Visitor<E>>(visitor: &mut V, - struct_definition: &StructDef, - env: E) { +pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, + struct_definition: &'v StructDef) { match struct_definition.super_struct { - Some(ref t) => visitor.visit_ty(&**t, env.clone()), + Some(ref t) => visitor.visit_ty(&**t), None => {}, } for field in struct_definition.fields.iter() { - visitor.visit_struct_field(field, env.clone()) + visitor.visit_struct_field(field) } } -pub fn walk_struct_field<E: Clone, V: Visitor<E>>(visitor: &mut V, - struct_field: &StructField, - env: E) { +pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, + struct_field: &'v StructField) { match struct_field.node.kind { NamedField(name, _) => { - visitor.visit_ident(struct_field.span, name, env.clone()) + visitor.visit_ident(struct_field.span, name) } _ => {} } - visitor.visit_ty(&*struct_field.node.ty, env.clone()); + visitor.visit_ty(&*struct_field.node.ty); for attr in struct_field.node.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } -pub fn walk_block<E: Clone, V: Visitor<E>>(visitor: &mut V, block: &Block, env: E) { +pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { for view_item in block.view_items.iter() { - visitor.visit_view_item(view_item, env.clone()) + visitor.visit_view_item(view_item) } for statement in block.stmts.iter() { - visitor.visit_stmt(&**statement, env.clone()) + visitor.visit_stmt(&**statement) } - walk_expr_opt(visitor, block.expr, env) + walk_expr_opt(visitor, &block.expr) } -pub fn walk_stmt<E: Clone, V: Visitor<E>>(visitor: &mut V, statement: &Stmt, env: E) { +pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { match statement.node { - StmtDecl(ref declaration, _) => visitor.visit_decl(&**declaration, env), + StmtDecl(ref declaration, _) => visitor.visit_decl(&**declaration), StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => { - visitor.visit_expr(&**expression, env) + visitor.visit_expr(&**expression) } - StmtMac(ref macro, _) => visitor.visit_mac(macro, env), + StmtMac(ref macro, _) => visitor.visit_mac(macro), } } -pub fn walk_decl<E: Clone, V: Visitor<E>>(visitor: &mut V, declaration: &Decl, env: E) { +pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) { match declaration.node { - DeclLocal(ref local) => visitor.visit_local(&**local, env), - DeclItem(ref item) => visitor.visit_item(&**item, env), + DeclLocal(ref local) => visitor.visit_local(&**local), + DeclItem(ref item) => visitor.visit_item(&**item), } } -pub fn walk_expr_opt<E: Clone, V: Visitor<E>>(visitor: &mut V, - optional_expression: Option<Gc<Expr>>, - env: E) { - match optional_expression { +pub fn walk_expr_opt<'v, V: Visitor<'v>>(visitor: &mut V, + optional_expression: &'v Option<Gc<Expr>>) { + match *optional_expression { None => {} - Some(ref expression) => visitor.visit_expr(&**expression, env), + Some(ref expression) => visitor.visit_expr(&**expression), } } -pub fn walk_exprs<E: Clone, V: Visitor<E>>(visitor: &mut V, - expressions: &[Gc<Expr>], - env: E) { +pub fn walk_exprs<'v, V: Visitor<'v>>(visitor: &mut V, expressions: &'v [Gc<Expr>]) { for expression in expressions.iter() { - visitor.visit_expr(&**expression, env.clone()) + visitor.visit_expr(&**expression) } } -pub fn walk_mac<E, V: Visitor<E>>(_: &mut V, _: &Mac, _: E) { +pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) { // Empty! } -pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, env: E) { +pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { match expression.node { ExprBox(ref place, ref subexpression) => { - visitor.visit_expr(&**place, env.clone()); - visitor.visit_expr(&**subexpression, env.clone()) + visitor.visit_expr(&**place); + visitor.visit_expr(&**subexpression) } ExprVec(ref subexpressions) => { - walk_exprs(visitor, subexpressions.as_slice(), env.clone()) + walk_exprs(visitor, subexpressions.as_slice()) } ExprRepeat(ref element, ref count) => { - visitor.visit_expr(&**element, env.clone()); - visitor.visit_expr(&**count, env.clone()) + visitor.visit_expr(&**element); + visitor.visit_expr(&**count) } - ExprStruct(ref path, ref fields, optional_base) => { - visitor.visit_path(path, expression.id, env.clone()); + ExprStruct(ref path, ref fields, ref optional_base) => { + visitor.visit_path(path, expression.id); for field in fields.iter() { - visitor.visit_expr(&*field.expr, env.clone()) + visitor.visit_expr(&*field.expr) } - walk_expr_opt(visitor, optional_base, env.clone()) + walk_expr_opt(visitor, optional_base) } ExprTup(ref subexpressions) => { for subexpression in subexpressions.iter() { - visitor.visit_expr(&**subexpression, env.clone()) + visitor.visit_expr(&**subexpression) } } ExprCall(ref callee_expression, ref arguments) => { for argument in arguments.iter() { - visitor.visit_expr(&**argument, env.clone()) + visitor.visit_expr(&**argument) } - visitor.visit_expr(&**callee_expression, env.clone()) + visitor.visit_expr(&**callee_expression) } ExprMethodCall(_, ref types, ref arguments) => { - walk_exprs(visitor, arguments.as_slice(), env.clone()); + walk_exprs(visitor, arguments.as_slice()); for typ in types.iter() { - visitor.visit_ty(&**typ, env.clone()) + visitor.visit_ty(&**typ) } } ExprBinary(_, ref left_expression, ref right_expression) => { - visitor.visit_expr(&**left_expression, env.clone()); - visitor.visit_expr(&**right_expression, env.clone()) + visitor.visit_expr(&**left_expression); + visitor.visit_expr(&**right_expression) } ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression) => { - visitor.visit_expr(&**subexpression, env.clone()) + visitor.visit_expr(&**subexpression) } ExprLit(_) => {} ExprCast(ref subexpression, ref typ) => { - visitor.visit_expr(&**subexpression, env.clone()); - visitor.visit_ty(&**typ, env.clone()) + visitor.visit_expr(&**subexpression); + visitor.visit_ty(&**typ) } - ExprIf(ref head_expression, ref if_block, optional_else) => { - visitor.visit_expr(&**head_expression, env.clone()); - visitor.visit_block(&**if_block, env.clone()); - walk_expr_opt(visitor, optional_else, env.clone()) + ExprIf(ref head_expression, ref if_block, ref optional_else) => { + visitor.visit_expr(&**head_expression); + visitor.visit_block(&**if_block); + walk_expr_opt(visitor, optional_else) } ExprWhile(ref subexpression, ref block, _) => { - visitor.visit_expr(&**subexpression, env.clone()); - visitor.visit_block(&**block, env.clone()) + visitor.visit_expr(&**subexpression); + visitor.visit_block(&**block) } ExprForLoop(ref pattern, ref subexpression, ref block, _) => { - visitor.visit_pat(&**pattern, env.clone()); - visitor.visit_expr(&**subexpression, env.clone()); - visitor.visit_block(&**block, env.clone()) + visitor.visit_pat(&**pattern); + visitor.visit_expr(&**subexpression); + visitor.visit_block(&**block) } - ExprLoop(ref block, _) => visitor.visit_block(&**block, env.clone()), + ExprLoop(ref block, _) => visitor.visit_block(&**block), ExprMatch(ref subexpression, ref arms) => { - visitor.visit_expr(&**subexpression, env.clone()); + visitor.visit_expr(&**subexpression); for arm in arms.iter() { - visitor.visit_arm(arm, env.clone()) + visitor.visit_arm(arm) } } ExprFnBlock(_, ref function_declaration, ref body) => { - visitor.visit_fn(&FkFnBlock, + visitor.visit_fn(FkFnBlock, &**function_declaration, &**body, expression.span, - expression.id, - env.clone()) + expression.id) } ExprUnboxedFn(_, _, ref function_declaration, ref body) => { - visitor.visit_fn(&FkFnBlock, + visitor.visit_fn(FkFnBlock, &**function_declaration, &**body, expression.span, - expression.id, - env.clone()) + expression.id) } ExprProc(ref function_declaration, ref body) => { - visitor.visit_fn(&FkFnBlock, + visitor.visit_fn(FkFnBlock, &**function_declaration, &**body, expression.span, - expression.id, - env.clone()) + expression.id) } - ExprBlock(ref block) => visitor.visit_block(&**block, env.clone()), + ExprBlock(ref block) => visitor.visit_block(&**block), ExprAssign(ref left_hand_expression, ref right_hand_expression) => { - visitor.visit_expr(&**right_hand_expression, env.clone()); - visitor.visit_expr(&**left_hand_expression, env.clone()) + visitor.visit_expr(&**right_hand_expression); + visitor.visit_expr(&**left_hand_expression) } ExprAssignOp(_, ref left_expression, ref right_expression) => { - visitor.visit_expr(&**right_expression, env.clone()); - visitor.visit_expr(&**left_expression, env.clone()) + visitor.visit_expr(&**right_expression); + visitor.visit_expr(&**left_expression) } ExprField(ref subexpression, _, ref types) => { - visitor.visit_expr(&**subexpression, env.clone()); + visitor.visit_expr(&**subexpression); for typ in types.iter() { - visitor.visit_ty(&**typ, env.clone()) + visitor.visit_ty(&**typ) } } ExprTupField(ref subexpression, _, ref types) => { - visitor.visit_expr(&**subexpression, env.clone()); + visitor.visit_expr(&**subexpression); for typ in types.iter() { - visitor.visit_ty(&**typ, env.clone()) + visitor.visit_ty(&**typ) } } ExprIndex(ref main_expression, ref index_expression) => { - visitor.visit_expr(&**main_expression, env.clone()); - visitor.visit_expr(&**index_expression, env.clone()) + visitor.visit_expr(&**main_expression); + visitor.visit_expr(&**index_expression) } ExprPath(ref path) => { - visitor.visit_path(path, expression.id, env.clone()) + visitor.visit_path(path, expression.id) } ExprBreak(_) | ExprAgain(_) => {} - ExprRet(optional_expression) => { - walk_expr_opt(visitor, optional_expression, env.clone()) + ExprRet(ref optional_expression) => { + walk_expr_opt(visitor, optional_expression) } - ExprMac(ref macro) => visitor.visit_mac(macro, env.clone()), + ExprMac(ref macro) => visitor.visit_mac(macro), ExprParen(ref subexpression) => { - visitor.visit_expr(&**subexpression, env.clone()) + visitor.visit_expr(&**subexpression) } ExprInlineAsm(ref ia) => { - for &(_, ref input) in ia.inputs.iter() { - visitor.visit_expr(&**input, env.clone()) + for input in ia.inputs.iter() { + let (_, ref input) = *input; + visitor.visit_expr(&**input) } - for &(_, ref output, _) in ia.outputs.iter() { - visitor.visit_expr(&**output, env.clone()) + for output in ia.outputs.iter() { + let (_, ref output, _) = *output; + visitor.visit_expr(&**output) } } } - visitor.visit_expr_post(expression, env.clone()) + visitor.visit_expr_post(expression) } -pub fn walk_arm<E: Clone, V: Visitor<E>>(visitor: &mut V, arm: &Arm, env: E) { +pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) { for pattern in arm.pats.iter() { - visitor.visit_pat(&**pattern, env.clone()) + visitor.visit_pat(&**pattern) } - walk_expr_opt(visitor, arm.guard, env.clone()); - visitor.visit_expr(&*arm.body, env.clone()); + walk_expr_opt(visitor, &arm.guard); + visitor.visit_expr(&*arm.body); for attr in arm.attrs.iter() { - visitor.visit_attribute(attr, env.clone()); + visitor.visit_attribute(attr); } } |
