1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! AST walker. Each overridden visit method has full control over what
12 //! happens with its node, it can do its own traversal of the node's children,
13 //! call `visit::walk_*` to apply the default traversal algorithm, or prevent
14 //! deeper traversal by doing nothing.
16 //! Note: it is an important invariant that the default visitor walks the body
17 //! of a function in "execution order" (more concretely, reverse post-order
18 //! with respect to the CFG implied by the AST), meaning that if AST node A may
19 //! execute before AST node B, then A is visited first. The borrow checker in
20 //! particular relies on this property.
22 //! Note: walking an AST before macro expansion is probably a bad idea. For
23 //! instance, a walker looking for item names in a module will miss all of
24 //! those that are created by the expansion of a macro.
31 use owned_slice::OwnedSlice;
34 /// fn foo() or extern "Abi" fn foo()
35 FkItemFn(Ident, &'a Generics, FnStyle, Abi),
38 FkMethod(Ident, &'a Generics, &'a Method),
45 /// Each method of the Visitor trait is a hook to be potentially
46 /// overridden. Each method's default implementation recursively visits
47 /// the substructure of the input via the corresponding `walk` method;
48 /// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
50 /// If you want to ensure that your code handles every variant
51 /// explicitly, you need to override each method. (And you also need
52 /// to monitor future changes to `Visitor` in case a new method with a
53 /// new default implementation gets introduced.)
54 pub trait Visitor<'v> {
56 fn visit_ident(&mut self, _sp: Span, _ident: Ident) {
57 /*! Visit the idents */
59 fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
60 fn visit_view_item(&mut self, i: &'v ViewItem) { walk_view_item(self, i) }
61 fn visit_foreign_item(&mut self, i: &'v ForeignItem) { walk_foreign_item(self, i) }
62 fn visit_item(&mut self, i: &'v Item) { walk_item(self, i) }
63 fn visit_local(&mut self, l: &'v Local) { walk_local(self, l) }
64 fn visit_block(&mut self, b: &'v Block) { walk_block(self, b) }
65 fn visit_stmt(&mut self, s: &'v Stmt) { walk_stmt(self, s) }
66 fn visit_arm(&mut self, a: &'v Arm) { walk_arm(self, a) }
67 fn visit_pat(&mut self, p: &'v Pat) { walk_pat(self, p) }
68 fn visit_decl(&mut self, d: &'v Decl) { walk_decl(self, d) }
69 fn visit_expr(&mut self, ex: &'v Expr) { walk_expr(self, ex) }
70 fn visit_expr_post(&mut self, _ex: &'v Expr) { }
71 fn visit_ty(&mut self, t: &'v Ty) { walk_ty(self, t) }
72 fn visit_generics(&mut self, g: &'v Generics) { walk_generics(self, g) }
73 fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, _: NodeId) {
74 walk_fn(self, fk, fd, b, s)
76 fn visit_ty_method(&mut self, t: &'v TypeMethod) { walk_ty_method(self, t) }
77 fn visit_trait_item(&mut self, t: &'v TraitItem) { walk_trait_item(self, t) }
78 fn visit_struct_def(&mut self, s: &'v StructDef, _: Ident, _: &'v Generics, _: NodeId) {
79 walk_struct_def(self, s)
81 fn visit_struct_field(&mut self, s: &'v StructField) { walk_struct_field(self, s) }
82 fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics) { walk_variant(self, v, g) }
83 fn visit_opt_lifetime_ref(&mut self,
85 opt_lifetime: &'v Option<Lifetime>) {
87 * Visits an optional reference to a lifetime. The `span` is
88 * the span of some surrounding reference should opt_lifetime
92 Some(ref l) => self.visit_lifetime_ref(l),
96 fn visit_lifetime_ref(&mut self, _lifetime: &'v Lifetime) {
97 /*! Visits a reference to a lifetime */
99 fn visit_lifetime_decl(&mut self, _lifetime: &'v LifetimeDef) {
100 /*! Visits a declaration of a lifetime */
102 fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
103 walk_explicit_self(self, es)
105 fn visit_mac(&mut self, _macro: &'v Mac) {
106 fail!("visit_mac disabled by default");
107 // NB: see note about macros above.
108 // if you really want a visitor that
109 // works on macros, use this
110 // definition in your trait impl:
111 // visit::walk_mac(self, _macro)
113 fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) {
114 walk_path(self, path)
116 fn visit_attribute(&mut self, _attr: &'v Attribute) {}
119 pub fn walk_inlined_item<'v,V>(visitor: &mut V, item: &'v InlinedItem)
120 where V: Visitor<'v> {
122 IIItem(ref i) => visitor.visit_item(&**i),
123 IIForeign(ref i) => visitor.visit_foreign_item(&**i),
124 IITraitItem(_, ref ti) => visitor.visit_trait_item(ti),
125 IIImplItem(_, MethodImplItem(ref m)) => {
126 walk_method_helper(visitor, &**m)
128 IIImplItem(_, TypeImplItem(ref typedef)) => {
129 visitor.visit_ident(typedef.span, typedef.ident);
130 visitor.visit_ty(&*typedef.typ);
136 pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) {
137 visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
138 for attr in krate.attrs.iter() {
139 visitor.visit_attribute(attr);
143 pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) {
144 for view_item in module.view_items.iter() {
145 visitor.visit_view_item(view_item)
148 for item in module.items.iter() {
149 visitor.visit_item(&**item)
153 pub fn walk_view_item<'v, V: Visitor<'v>>(visitor: &mut V, vi: &'v ViewItem) {
155 ViewItemExternCrate(name, _, _) => {
156 visitor.visit_ident(vi.span, name)
158 ViewItemUse(ref vp) => {
160 ViewPathSimple(ident, ref path, id) => {
161 visitor.visit_ident(vp.span, ident);
162 visitor.visit_path(path, id);
164 ViewPathGlob(ref path, id) => {
165 visitor.visit_path(path, id);
167 ViewPathList(ref path, ref list, _) => {
168 for id in list.iter() {
170 PathListIdent { name, .. } => {
171 visitor.visit_ident(id.span, name);
173 PathListMod { .. } => ()
176 walk_path(visitor, path);
181 for attr in vi.attrs.iter() {
182 visitor.visit_attribute(attr);
186 pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
187 visitor.visit_pat(&*local.pat);
188 visitor.visit_ty(&*local.ty);
189 walk_expr_opt(visitor, &local.init);
192 pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V,
193 explicit_self: &'v ExplicitSelf) {
194 match explicit_self.node {
195 SelfStatic | SelfValue(_) => {},
196 SelfRegion(ref lifetime, _, _) => {
197 visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime)
199 SelfExplicit(ref typ, _) => visitor.visit_ty(&**typ),
203 /// Like with walk_method_helper this doesn't correspond to a method
204 /// in Visitor, and so it gets a _helper suffix.
205 pub fn walk_trait_ref_helper<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef) {
206 visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
209 pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
210 visitor.visit_ident(item.span, item.ident);
212 ItemStatic(ref typ, _, ref expr) => {
213 visitor.visit_ty(&**typ);
214 visitor.visit_expr(&**expr);
216 ItemFn(ref declaration, fn_style, abi, ref generics, ref body) => {
217 visitor.visit_fn(FkItemFn(item.ident, generics, fn_style, abi),
223 ItemMod(ref module) => {
224 visitor.visit_mod(module, item.span, item.id)
226 ItemForeignMod(ref foreign_module) => {
227 for view_item in foreign_module.view_items.iter() {
228 visitor.visit_view_item(view_item)
230 for foreign_item in foreign_module.items.iter() {
231 visitor.visit_foreign_item(&**foreign_item)
234 ItemTy(ref typ, ref type_parameters) => {
235 visitor.visit_ty(&**typ);
236 visitor.visit_generics(type_parameters)
238 ItemEnum(ref enum_definition, ref type_parameters) => {
239 visitor.visit_generics(type_parameters);
240 walk_enum_def(visitor, enum_definition, type_parameters)
242 ItemImpl(ref type_parameters,
246 visitor.visit_generics(type_parameters);
247 match *trait_reference {
248 Some(ref trait_reference) => walk_trait_ref_helper(visitor,
252 visitor.visit_ty(&**typ);
253 for impl_item in impl_items.iter() {
255 MethodImplItem(ref method) => {
256 walk_method_helper(visitor, &**method)
258 TypeImplItem(ref typedef) => {
259 visitor.visit_ident(typedef.span, typedef.ident);
260 visitor.visit_ty(&*typedef.typ);
265 ItemStruct(ref struct_definition, ref generics) => {
266 visitor.visit_generics(generics);
267 visitor.visit_struct_def(&**struct_definition,
272 ItemTrait(ref generics, _, ref bounds, ref methods) => {
273 visitor.visit_generics(generics);
274 walk_ty_param_bounds(visitor, bounds);
275 for method in methods.iter() {
276 visitor.visit_trait_item(method)
279 ItemMac(ref macro) => visitor.visit_mac(macro),
281 for attr in item.attrs.iter() {
282 visitor.visit_attribute(attr);
286 pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V,
287 enum_definition: &'v EnumDef,
288 generics: &'v Generics) {
289 for variant in enum_definition.variants.iter() {
290 visitor.visit_variant(&**variant, generics);
294 pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
295 variant: &'v Variant,
296 generics: &'v Generics) {
297 visitor.visit_ident(variant.span, variant.node.name);
299 match variant.node.kind {
300 TupleVariantKind(ref variant_arguments) => {
301 for variant_argument in variant_arguments.iter() {
302 visitor.visit_ty(&*variant_argument.ty)
305 StructVariantKind(ref struct_definition) => {
306 visitor.visit_struct_def(&**struct_definition,
312 match variant.node.disr_expr {
313 Some(ref expr) => visitor.visit_expr(&**expr),
316 for attr in variant.node.attrs.iter() {
317 visitor.visit_attribute(attr);
321 pub fn skip_ty<'v, V: Visitor<'v>>(_: &mut V, _: &'v Ty) {
325 pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
327 TyUniq(ref ty) | TyVec(ref ty) | TyBox(ref ty) | TyParen(ref ty) => {
328 visitor.visit_ty(&**ty)
330 TyPtr(ref mutable_type) => {
331 visitor.visit_ty(&*mutable_type.ty)
333 TyRptr(ref lifetime, ref mutable_type) => {
334 visitor.visit_opt_lifetime_ref(typ.span, lifetime);
335 visitor.visit_ty(&*mutable_type.ty)
337 TyTup(ref tuple_element_types) => {
338 for tuple_element_type in tuple_element_types.iter() {
339 visitor.visit_ty(&**tuple_element_type)
342 TyClosure(ref function_declaration) => {
343 for argument in function_declaration.decl.inputs.iter() {
344 visitor.visit_ty(&*argument.ty)
346 visitor.visit_ty(&*function_declaration.decl.output);
347 walk_ty_param_bounds(visitor, &function_declaration.bounds);
348 walk_lifetime_decls(visitor, &function_declaration.lifetimes);
350 TyProc(ref function_declaration) => {
351 for argument in function_declaration.decl.inputs.iter() {
352 visitor.visit_ty(&*argument.ty)
354 visitor.visit_ty(&*function_declaration.decl.output);
355 walk_ty_param_bounds(visitor, &function_declaration.bounds);
356 walk_lifetime_decls(visitor, &function_declaration.lifetimes);
358 TyBareFn(ref function_declaration) => {
359 for argument in function_declaration.decl.inputs.iter() {
360 visitor.visit_ty(&*argument.ty)
362 visitor.visit_ty(&*function_declaration.decl.output);
363 walk_lifetime_decls(visitor, &function_declaration.lifetimes);
365 TyUnboxedFn(ref function_declaration) => {
366 for argument in function_declaration.decl.inputs.iter() {
367 visitor.visit_ty(&*argument.ty)
369 visitor.visit_ty(&*function_declaration.decl.output);
371 TyPath(ref path, ref opt_bounds, id) => {
372 visitor.visit_path(path, id);
374 Some(ref bounds) => {
375 walk_ty_param_bounds(visitor, bounds);
380 TyQPath(ref qpath) => {
381 visitor.visit_ty(&*qpath.for_type);
382 visitor.visit_path(&qpath.trait_name, typ.id);
383 visitor.visit_ident(typ.span, qpath.item_name);
385 TyFixedLengthVec(ref ty, ref expression) => {
386 visitor.visit_ty(&**ty);
387 visitor.visit_expr(&**expression)
389 TyTypeof(ref expression) => {
390 visitor.visit_expr(&**expression)
392 TyNil | TyBot | TyInfer => {}
396 fn walk_lifetime_decls<'v, V: Visitor<'v>>(visitor: &mut V,
397 lifetimes: &'v Vec<LifetimeDef>) {
398 for l in lifetimes.iter() {
399 visitor.visit_lifetime_decl(l);
403 pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
404 for segment in path.segments.iter() {
405 visitor.visit_ident(path.span, segment.identifier);
407 for typ in segment.types.iter() {
408 visitor.visit_ty(&**typ);
410 for lifetime in segment.lifetimes.iter() {
411 visitor.visit_lifetime_ref(lifetime);
416 pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
418 PatEnum(ref path, ref children) => {
419 visitor.visit_path(path, pattern.id);
420 for children in children.iter() {
421 for child in children.iter() {
422 visitor.visit_pat(&**child)
426 PatStruct(ref path, ref fields, _) => {
427 visitor.visit_path(path, pattern.id);
428 for field in fields.iter() {
429 visitor.visit_pat(&*field.pat)
432 PatTup(ref tuple_elements) => {
433 for tuple_element in tuple_elements.iter() {
434 visitor.visit_pat(&**tuple_element)
437 PatBox(ref subpattern) |
438 PatRegion(ref subpattern) => {
439 visitor.visit_pat(&**subpattern)
441 PatIdent(_, ref pth1, ref optional_subpattern) => {
442 visitor.visit_ident(pth1.span, pth1.node);
443 match *optional_subpattern {
445 Some(ref subpattern) => visitor.visit_pat(&**subpattern),
448 PatLit(ref expression) => visitor.visit_expr(&**expression),
449 PatRange(ref lower_bound, ref upper_bound) => {
450 visitor.visit_expr(&**lower_bound);
451 visitor.visit_expr(&**upper_bound)
454 PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => {
455 for prepattern in prepattern.iter() {
456 visitor.visit_pat(&**prepattern)
458 for slice_pattern in slice_pattern.iter() {
459 visitor.visit_pat(&**slice_pattern)
461 for postpattern in postpatterns.iter() {
462 visitor.visit_pat(&**postpattern)
465 PatMac(ref macro) => visitor.visit_mac(macro),
469 pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V,
470 foreign_item: &'v ForeignItem) {
471 visitor.visit_ident(foreign_item.span, foreign_item.ident);
473 match foreign_item.node {
474 ForeignItemFn(ref function_declaration, ref generics) => {
475 walk_fn_decl(visitor, &**function_declaration);
476 visitor.visit_generics(generics)
478 ForeignItemStatic(ref typ, _) => visitor.visit_ty(&**typ),
481 for attr in foreign_item.attrs.iter() {
482 visitor.visit_attribute(attr);
486 pub fn walk_ty_param_bounds<'v, V: Visitor<'v>>(visitor: &mut V,
487 bounds: &'v OwnedSlice<TyParamBound>) {
488 for bound in bounds.iter() {
490 TraitTyParamBound(ref typ) => {
491 walk_trait_ref_helper(visitor, typ)
493 UnboxedFnTyParamBound(ref function_declaration) => {
494 for argument in function_declaration.decl.inputs.iter() {
495 visitor.visit_ty(&*argument.ty)
497 visitor.visit_ty(&*function_declaration.decl.output);
499 RegionTyParamBound(ref lifetime) => {
500 visitor.visit_lifetime_ref(lifetime);
506 pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
507 for type_parameter in generics.ty_params.iter() {
508 walk_ty_param_bounds(visitor, &type_parameter.bounds);
509 match type_parameter.default {
510 Some(ref ty) => visitor.visit_ty(&**ty),
514 walk_lifetime_decls(visitor, &generics.lifetimes);
515 for predicate in generics.where_clause.predicates.iter() {
516 visitor.visit_ident(predicate.span, predicate.ident);
517 walk_ty_param_bounds(visitor, &predicate.bounds);
521 pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) {
522 for argument in function_declaration.inputs.iter() {
523 visitor.visit_pat(&*argument.pat);
524 visitor.visit_ty(&*argument.ty)
526 visitor.visit_ty(&*function_declaration.output)
529 // Note: there is no visit_method() method in the visitor, instead override
530 // visit_fn() and check for FkMethod(). I named this visit_method_helper()
531 // because it is not a default impl of any method, though I doubt that really
532 // clarifies anything. - Niko
533 pub fn walk_method_helper<'v, V: Visitor<'v>>(visitor: &mut V, method: &'v Method) {
535 MethDecl(ident, ref generics, _, _, _, ref decl, ref body, _) => {
536 visitor.visit_ident(method.span, ident);
537 visitor.visit_fn(FkMethod(ident, generics, method),
542 for attr in method.attrs.iter() {
543 visitor.visit_attribute(attr);
547 MethMac(ref mac) => visitor.visit_mac(mac)
551 pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
552 function_kind: FnKind<'v>,
553 function_declaration: &'v FnDecl,
554 function_body: &'v Block,
556 walk_fn_decl(visitor, function_declaration);
558 match function_kind {
559 FkItemFn(_, generics, _, _) => {
560 visitor.visit_generics(generics);
562 FkMethod(_, generics, method) => {
563 visitor.visit_generics(generics);
565 MethDecl(_, _, _, ref explicit_self, _, _, _, _) =>
566 visitor.visit_explicit_self(explicit_self),
568 visitor.visit_mac(mac)
574 visitor.visit_block(function_body)
577 pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v TypeMethod) {
578 visitor.visit_ident(method_type.span, method_type.ident);
579 visitor.visit_explicit_self(&method_type.explicit_self);
580 for argument_type in method_type.decl.inputs.iter() {
581 visitor.visit_ty(&*argument_type.ty)
583 visitor.visit_generics(&method_type.generics);
584 visitor.visit_ty(&*method_type.decl.output);
585 for attr in method_type.attrs.iter() {
586 visitor.visit_attribute(attr);
590 pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v TraitItem) {
591 match *trait_method {
592 RequiredMethod(ref method_type) => visitor.visit_ty_method(method_type),
593 ProvidedMethod(ref method) => walk_method_helper(visitor, &**method),
594 TypeTraitItem(ref associated_type) => {
595 visitor.visit_ident(associated_type.span, associated_type.ident)
600 pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V,
601 struct_definition: &'v StructDef) {
602 match struct_definition.super_struct {
603 Some(ref t) => visitor.visit_ty(&**t),
606 for field in struct_definition.fields.iter() {
607 visitor.visit_struct_field(field)
611 pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
612 struct_field: &'v StructField) {
613 match struct_field.node.kind {
614 NamedField(name, _) => {
615 visitor.visit_ident(struct_field.span, name)
620 visitor.visit_ty(&*struct_field.node.ty);
622 for attr in struct_field.node.attrs.iter() {
623 visitor.visit_attribute(attr);
627 pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
628 for view_item in block.view_items.iter() {
629 visitor.visit_view_item(view_item)
631 for statement in block.stmts.iter() {
632 visitor.visit_stmt(&**statement)
634 walk_expr_opt(visitor, &block.expr)
637 pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
638 match statement.node {
639 StmtDecl(ref declaration, _) => visitor.visit_decl(&**declaration),
640 StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => {
641 visitor.visit_expr(&**expression)
643 StmtMac(ref macro, _) => visitor.visit_mac(macro),
647 pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) {
648 match declaration.node {
649 DeclLocal(ref local) => visitor.visit_local(&**local),
650 DeclItem(ref item) => visitor.visit_item(&**item),
654 pub fn walk_expr_opt<'v, V: Visitor<'v>>(visitor: &mut V,
655 optional_expression: &'v Option<P<Expr>>) {
656 match *optional_expression {
658 Some(ref expression) => visitor.visit_expr(&**expression),
662 pub fn walk_exprs<'v, V: Visitor<'v>>(visitor: &mut V, expressions: &'v [P<Expr>]) {
663 for expression in expressions.iter() {
664 visitor.visit_expr(&**expression)
668 pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) {
672 pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
673 match expression.node {
674 ExprBox(ref place, ref subexpression) => {
675 visitor.visit_expr(&**place);
676 visitor.visit_expr(&**subexpression)
678 ExprVec(ref subexpressions) => {
679 walk_exprs(visitor, subexpressions.as_slice())
681 ExprRepeat(ref element, ref count) => {
682 visitor.visit_expr(&**element);
683 visitor.visit_expr(&**count)
685 ExprStruct(ref path, ref fields, ref optional_base) => {
686 visitor.visit_path(path, expression.id);
687 for field in fields.iter() {
688 visitor.visit_expr(&*field.expr)
690 walk_expr_opt(visitor, optional_base)
692 ExprTup(ref subexpressions) => {
693 for subexpression in subexpressions.iter() {
694 visitor.visit_expr(&**subexpression)
697 ExprCall(ref callee_expression, ref arguments) => {
698 for argument in arguments.iter() {
699 visitor.visit_expr(&**argument)
701 visitor.visit_expr(&**callee_expression)
703 ExprMethodCall(_, ref types, ref arguments) => {
704 walk_exprs(visitor, arguments.as_slice());
705 for typ in types.iter() {
706 visitor.visit_ty(&**typ)
709 ExprBinary(_, ref left_expression, ref right_expression) => {
710 visitor.visit_expr(&**left_expression);
711 visitor.visit_expr(&**right_expression)
713 ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression) => {
714 visitor.visit_expr(&**subexpression)
717 ExprCast(ref subexpression, ref typ) => {
718 visitor.visit_expr(&**subexpression);
719 visitor.visit_ty(&**typ)
721 ExprIf(ref head_expression, ref if_block, ref optional_else) => {
722 visitor.visit_expr(&**head_expression);
723 visitor.visit_block(&**if_block);
724 walk_expr_opt(visitor, optional_else)
726 ExprWhile(ref subexpression, ref block, _) => {
727 visitor.visit_expr(&**subexpression);
728 visitor.visit_block(&**block)
730 ExprForLoop(ref pattern, ref subexpression, ref block, _) => {
731 visitor.visit_pat(&**pattern);
732 visitor.visit_expr(&**subexpression);
733 visitor.visit_block(&**block)
735 ExprLoop(ref block, _) => visitor.visit_block(&**block),
736 ExprMatch(ref subexpression, ref arms) => {
737 visitor.visit_expr(&**subexpression);
738 for arm in arms.iter() {
739 visitor.visit_arm(arm)
742 ExprFnBlock(_, ref function_declaration, ref body) => {
743 visitor.visit_fn(FkFnBlock,
744 &**function_declaration,
749 ExprUnboxedFn(_, _, ref function_declaration, ref body) => {
750 visitor.visit_fn(FkFnBlock,
751 &**function_declaration,
756 ExprProc(ref function_declaration, ref body) => {
757 visitor.visit_fn(FkFnBlock,
758 &**function_declaration,
763 ExprBlock(ref block) => visitor.visit_block(&**block),
764 ExprAssign(ref left_hand_expression, ref right_hand_expression) => {
765 visitor.visit_expr(&**right_hand_expression);
766 visitor.visit_expr(&**left_hand_expression)
768 ExprAssignOp(_, ref left_expression, ref right_expression) => {
769 visitor.visit_expr(&**right_expression);
770 visitor.visit_expr(&**left_expression)
772 ExprField(ref subexpression, _, ref types) => {
773 visitor.visit_expr(&**subexpression);
774 for typ in types.iter() {
775 visitor.visit_ty(&**typ)
778 ExprTupField(ref subexpression, _, ref types) => {
779 visitor.visit_expr(&**subexpression);
780 for typ in types.iter() {
781 visitor.visit_ty(&**typ)
784 ExprIndex(ref main_expression, ref index_expression) => {
785 visitor.visit_expr(&**main_expression);
786 visitor.visit_expr(&**index_expression)
788 ExprSlice(ref main_expression, ref start, ref end, _) => {
789 visitor.visit_expr(&**main_expression);
790 walk_expr_opt(visitor, start);
791 walk_expr_opt(visitor, end)
793 ExprPath(ref path) => {
794 visitor.visit_path(path, expression.id)
796 ExprBreak(_) | ExprAgain(_) => {}
797 ExprRet(ref optional_expression) => {
798 walk_expr_opt(visitor, optional_expression)
800 ExprMac(ref macro) => visitor.visit_mac(macro),
801 ExprParen(ref subexpression) => {
802 visitor.visit_expr(&**subexpression)
804 ExprInlineAsm(ref ia) => {
805 for input in ia.inputs.iter() {
806 let (_, ref input) = *input;
807 visitor.visit_expr(&**input)
809 for output in ia.outputs.iter() {
810 let (_, ref output, _) = *output;
811 visitor.visit_expr(&**output)
816 visitor.visit_expr_post(expression)
819 pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
820 for pattern in arm.pats.iter() {
821 visitor.visit_pat(&**pattern)
823 walk_expr_opt(visitor, &arm.guard);
824 visitor.visit_expr(&*arm.body);
825 for attr in arm.attrs.iter() {
826 visitor.visit_attribute(attr);