]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_hir/src/intravisit.rs
Rollup merge of #98390 - GuillaumeGomez:keyword-rustdoc-json, r=notriddle
[rust.git] / compiler / rustc_hir / src / intravisit.rs
1 //! HIR walker for walking the contents of nodes.
2 //!
3 //! Here are the three available patterns for the visitor strategy,
4 //! in roughly the order of desirability:
5 //!
6 //! 1. **Shallow visit**: Get a simple callback for every item (or item-like thing) in the HIR.
7 //!    - Example: find all items with a `#[foo]` attribute on them.
8 //!    - How: Use the `hir_crate_items` or `hir_module_items` query to traverse over item-like ids
9 //!       (ItemId, TraitItemId, etc.) and use tcx.def_kind and `tcx.hir().item*(id)` to filter and
10 //!       access actual item-like thing, respectively.
11 //!    - Pro: Efficient; just walks the lists of item ids and gives users control whether to access
12 //!       the hir_owners themselves or not.
13 //!    - Con: Don't get information about nesting
14 //!    - Con: Don't have methods for specific bits of HIR, like "on
15 //!      every expr, do this".
16 //! 2. **Deep visit**: Want to scan for specific kinds of HIR nodes within
17 //!    an item, but don't care about how item-like things are nested
18 //!    within one another.
19 //!    - Example: Examine each expression to look for its type and do some check or other.
20 //!    - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
21 //!      `nested_filter::OnlyBodies` (and implement `nested_visit_map`), and use
22 //!      `tcx.hir().deep_visit_all_item_likes(&mut visitor)`. Within your
23 //!      `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke
24 //!      `intravisit::walk_expr()` to keep walking the subparts).
25 //!    - Pro: Visitor methods for any kind of HIR node, not just item-like things.
26 //!    - Pro: Integrates well into dependency tracking.
27 //!    - Con: Don't get information about nesting between items
28 //! 3. **Nested visit**: Want to visit the whole HIR and you care about the nesting between
29 //!    item-like things.
30 //!    - Example: Lifetime resolution, which wants to bring lifetimes declared on the
31 //!      impl into scope while visiting the impl-items, and then back out again.
32 //!    - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
33 //!      `nested_filter::All` (and implement `nested_visit_map`). Walk your crate with
34 //!      `tcx.hir().walk_toplevel_module(visitor)` invoked on `tcx.hir().krate()`.
35 //!    - Pro: Visitor methods for any kind of HIR node, not just item-like things.
36 //!    - Pro: Preserves nesting information
37 //!    - Con: Does not integrate well into dependency tracking.
38 //!
39 //! If you have decided to use this visitor, here are some general
40 //! notes on how to do so:
41 //!
42 //! Each overridden visit method has full control over what
43 //! happens with its node, it can do its own traversal of the node's children,
44 //! call `intravisit::walk_*` to apply the default traversal algorithm, or prevent
45 //! deeper traversal by doing nothing.
46 //!
47 //! When visiting the HIR, the contents of nested items are NOT visited
48 //! by default. This is different from the AST visitor, which does a deep walk.
49 //! Hence this module is called `intravisit`; see the method `visit_nested_item`
50 //! for more details.
51 //!
52 //! Note: it is an important invariant that the default visitor walks
53 //! the body of a function in "execution order" - more concretely, if
54 //! we consider the reverse post-order (RPO) of the CFG implied by the HIR,
55 //! then a pre-order traversal of the HIR is consistent with the CFG RPO
56 //! on the *initial CFG point* of each HIR node, while a post-order traversal
57 //! of the HIR is consistent with the CFG RPO on each *final CFG point* of
58 //! each CFG node.
59 //!
60 //! One thing that follows is that if HIR node A always starts/ends executing
61 //! before HIR node B, then A appears in traversal pre/postorder before B,
62 //! respectively. (This follows from RPO respecting CFG domination).
63 //!
64 //! This order consistency is required in a few places in rustc, for
65 //! example generator inference, and possibly also HIR borrowck.
66
67 use crate::hir::*;
68 use crate::itemlikevisit::ParItemLikeVisitor;
69 use rustc_ast::walk_list;
70 use rustc_ast::{Attribute, Label};
71 use rustc_span::symbol::{Ident, Symbol};
72 use rustc_span::Span;
73
74 pub trait IntoVisitor<'hir> {
75     type Visitor: Visitor<'hir>;
76     fn into_visitor(&self) -> Self::Visitor;
77 }
78
79 pub struct ParDeepVisitor<V>(pub V);
80
81 impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor<V>
82 where
83     V: IntoVisitor<'hir>,
84 {
85     fn visit_item(&self, item: &'hir Item<'hir>) {
86         self.0.into_visitor().visit_item(item);
87     }
88
89     fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>) {
90         self.0.into_visitor().visit_trait_item(trait_item);
91     }
92
93     fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>) {
94         self.0.into_visitor().visit_impl_item(impl_item);
95     }
96
97     fn visit_foreign_item(&self, foreign_item: &'hir ForeignItem<'hir>) {
98         self.0.into_visitor().visit_foreign_item(foreign_item);
99     }
100 }
101
102 #[derive(Copy, Clone, Debug)]
103 pub enum FnKind<'a> {
104     /// `#[xxx] pub async/const/extern "Abi" fn foo()`
105     ItemFn(Ident, &'a Generics<'a>, FnHeader),
106
107     /// `fn foo(&self)`
108     Method(Ident, &'a FnSig<'a>),
109
110     /// `|x, y| {}`
111     Closure,
112 }
113
114 impl<'a> FnKind<'a> {
115     pub fn header(&self) -> Option<&FnHeader> {
116         match *self {
117             FnKind::ItemFn(_, _, ref header) => Some(header),
118             FnKind::Method(_, ref sig) => Some(&sig.header),
119             FnKind::Closure => None,
120         }
121     }
122
123     pub fn constness(self) -> Constness {
124         self.header().map_or(Constness::NotConst, |header| header.constness)
125     }
126
127     pub fn asyncness(self) -> IsAsync {
128         self.header().map_or(IsAsync::NotAsync, |header| header.asyncness)
129     }
130 }
131
132 /// An abstract representation of the HIR `rustc_middle::hir::map::Map`.
133 pub trait Map<'hir> {
134     /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
135     fn find(&self, hir_id: HirId) -> Option<Node<'hir>>;
136     fn body(&self, id: BodyId) -> &'hir Body<'hir>;
137     fn item(&self, id: ItemId) -> &'hir Item<'hir>;
138     fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>;
139     fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>;
140     fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>;
141 }
142
143 // Used when no map is actually available, forcing manual implementation of nested visitors.
144 impl<'hir> Map<'hir> for ! {
145     fn find(&self, _: HirId) -> Option<Node<'hir>> {
146         *self;
147     }
148     fn body(&self, _: BodyId) -> &'hir Body<'hir> {
149         *self;
150     }
151     fn item(&self, _: ItemId) -> &'hir Item<'hir> {
152         *self;
153     }
154     fn trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> {
155         *self;
156     }
157     fn impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> {
158         *self;
159     }
160     fn foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> {
161         *self;
162     }
163 }
164
165 pub mod nested_filter {
166     use super::Map;
167
168     /// Specifies what nested things a visitor wants to visit. By "nested
169     /// things", we are referring to bits of HIR that are not directly embedded
170     /// within one another but rather indirectly, through a table in the crate.
171     /// This is done to control dependencies during incremental compilation: the
172     /// non-inline bits of HIR can be tracked and hashed separately.
173     ///
174     /// The most common choice is `OnlyBodies`, which will cause the visitor to
175     /// visit fn bodies for fns that it encounters, and closure bodies, but
176     /// skip over nested item-like things.
177     ///
178     /// See the comments on `ItemLikeVisitor` for more details on the overall
179     /// visit strategy.
180     pub trait NestedFilter<'hir> {
181         type Map: Map<'hir>;
182
183         /// Whether the visitor visits nested "item-like" things.
184         /// E.g., item, impl-item.
185         const INTER: bool;
186         /// Whether the visitor visits "intra item-like" things.
187         /// E.g., function body, closure, `AnonConst`
188         const INTRA: bool;
189     }
190
191     /// Do not visit any nested things. When you add a new
192     /// "non-nested" thing, you will want to audit such uses to see if
193     /// they remain valid.
194     ///
195     /// Use this if you are only walking some particular kind of tree
196     /// (i.e., a type, or fn signature) and you don't want to thread a
197     /// HIR map around.
198     pub struct None(());
199     impl NestedFilter<'_> for None {
200         type Map = !;
201         const INTER: bool = false;
202         const INTRA: bool = false;
203     }
204 }
205
206 use nested_filter::NestedFilter;
207
208 /// Each method of the Visitor trait is a hook to be potentially
209 /// overridden. Each method's default implementation recursively visits
210 /// the substructure of the input via the corresponding `walk` method;
211 /// e.g., the `visit_mod` method by default calls `intravisit::walk_mod`.
212 ///
213 /// Note that this visitor does NOT visit nested items by default
214 /// (this is why the module is called `intravisit`, to distinguish it
215 /// from the AST's `visit` module, which acts differently). If you
216 /// simply want to visit all items in the crate in some order, you
217 /// should call `Crate::visit_all_items`. Otherwise, see the comment
218 /// on `visit_nested_item` for details on how to visit nested items.
219 ///
220 /// If you want to ensure that your code handles every variant
221 /// explicitly, you need to override each method. (And you also need
222 /// to monitor future changes to `Visitor` in case a new method with a
223 /// new default implementation gets introduced.)
224 pub trait Visitor<'v>: Sized {
225     // this type should not be overridden, it exists for convenient usage as `Self::Map`
226     type Map: Map<'v> = <Self::NestedFilter as NestedFilter<'v>>::Map;
227
228     ///////////////////////////////////////////////////////////////////////////
229     // Nested items.
230
231     /// Override this type to control which nested HIR are visited; see
232     /// [`NestedFilter`] for details. If you override this type, you
233     /// must also override [`nested_visit_map`](Self::nested_visit_map).
234     ///
235     /// **If for some reason you want the nested behavior, but don't
236     /// have a `Map` at your disposal:** then override the
237     /// `visit_nested_XXX` methods. If a new `visit_nested_XXX` variant is
238     /// added in the future, it will cause a panic which can be detected
239     /// and fixed appropriately.
240     type NestedFilter: NestedFilter<'v> = nested_filter::None;
241
242     /// If `type NestedFilter` is set to visit nested items, this method
243     /// must also be overridden to provide a map to retrieve nested items.
244     fn nested_visit_map(&mut self) -> Self::Map {
245         panic!(
246             "nested_visit_map must be implemented or consider using \
247             `type NestedFilter = nested_filter::None` (the default)"
248         );
249     }
250
251     /// Invoked when a nested item is encountered. By default, when
252     /// `Self::NestedFilter` is `nested_filter::None`, this method does
253     /// nothing. **You probably don't want to override this method** --
254     /// instead, override [`Self::NestedFilter`] or use the "shallow" or
255     /// "deep" visit patterns described on
256     /// `itemlikevisit::ItemLikeVisitor`. The only reason to override
257     /// this method is if you want a nested pattern but cannot supply a
258     /// [`Map`]; see `nested_visit_map` for advice.
259     fn visit_nested_item(&mut self, id: ItemId) {
260         if Self::NestedFilter::INTER {
261             let item = self.nested_visit_map().item(id);
262             self.visit_item(item);
263         }
264     }
265
266     /// Like `visit_nested_item()`, but for trait items. See
267     /// `visit_nested_item()` for advice on when to override this
268     /// method.
269     fn visit_nested_trait_item(&mut self, id: TraitItemId) {
270         if Self::NestedFilter::INTER {
271             let item = self.nested_visit_map().trait_item(id);
272             self.visit_trait_item(item);
273         }
274     }
275
276     /// Like `visit_nested_item()`, but for impl items. See
277     /// `visit_nested_item()` for advice on when to override this
278     /// method.
279     fn visit_nested_impl_item(&mut self, id: ImplItemId) {
280         if Self::NestedFilter::INTER {
281             let item = self.nested_visit_map().impl_item(id);
282             self.visit_impl_item(item);
283         }
284     }
285
286     /// Like `visit_nested_item()`, but for foreign items. See
287     /// `visit_nested_item()` for advice on when to override this
288     /// method.
289     fn visit_nested_foreign_item(&mut self, id: ForeignItemId) {
290         if Self::NestedFilter::INTER {
291             let item = self.nested_visit_map().foreign_item(id);
292             self.visit_foreign_item(item);
293         }
294     }
295
296     /// Invoked to visit the body of a function, method or closure. Like
297     /// `visit_nested_item`, does nothing by default unless you override
298     /// `Self::NestedFilter`.
299     fn visit_nested_body(&mut self, id: BodyId) {
300         if Self::NestedFilter::INTRA {
301             let body = self.nested_visit_map().body(id);
302             self.visit_body(body);
303         }
304     }
305
306     fn visit_param(&mut self, param: &'v Param<'v>) {
307         walk_param(self, param)
308     }
309
310     /// Visits the top-level item and (optionally) nested items / impl items. See
311     /// `visit_nested_item` for details.
312     fn visit_item(&mut self, i: &'v Item<'v>) {
313         walk_item(self, i)
314     }
315
316     fn visit_body(&mut self, b: &'v Body<'v>) {
317         walk_body(self, b);
318     }
319
320     ///////////////////////////////////////////////////////////////////////////
321
322     fn visit_id(&mut self, _hir_id: HirId) {
323         // Nothing to do.
324     }
325     fn visit_name(&mut self, _span: Span, _name: Symbol) {
326         // Nothing to do.
327     }
328     fn visit_ident(&mut self, ident: Ident) {
329         walk_ident(self, ident)
330     }
331     fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: HirId) {
332         walk_mod(self, m, n)
333     }
334     fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
335         walk_foreign_item(self, i)
336     }
337     fn visit_local(&mut self, l: &'v Local<'v>) {
338         walk_local(self, l)
339     }
340     fn visit_block(&mut self, b: &'v Block<'v>) {
341         walk_block(self, b)
342     }
343     fn visit_stmt(&mut self, s: &'v Stmt<'v>) {
344         walk_stmt(self, s)
345     }
346     fn visit_arm(&mut self, a: &'v Arm<'v>) {
347         walk_arm(self, a)
348     }
349     fn visit_pat(&mut self, p: &'v Pat<'v>) {
350         walk_pat(self, p)
351     }
352     fn visit_array_length(&mut self, len: &'v ArrayLen) {
353         walk_array_len(self, len)
354     }
355     fn visit_anon_const(&mut self, c: &'v AnonConst) {
356         walk_anon_const(self, c)
357     }
358     fn visit_expr(&mut self, ex: &'v Expr<'v>) {
359         walk_expr(self, ex)
360     }
361     fn visit_let_expr(&mut self, lex: &'v Let<'v>) {
362         walk_let_expr(self, lex)
363     }
364     fn visit_ty(&mut self, t: &'v Ty<'v>) {
365         walk_ty(self, t)
366     }
367     fn visit_generic_param(&mut self, p: &'v GenericParam<'v>) {
368         walk_generic_param(self, p)
369     }
370     fn visit_const_param_default(&mut self, _param: HirId, ct: &'v AnonConst) {
371         walk_const_param_default(self, ct)
372     }
373     fn visit_generics(&mut self, g: &'v Generics<'v>) {
374         walk_generics(self, g)
375     }
376     fn visit_where_predicate(&mut self, predicate: &'v WherePredicate<'v>) {
377         walk_where_predicate(self, predicate)
378     }
379     fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) {
380         walk_fn_decl(self, fd)
381     }
382     fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, s: Span, id: HirId) {
383         walk_fn(self, fk, fd, b, s, id)
384     }
385     fn visit_use(&mut self, path: &'v Path<'v>, hir_id: HirId) {
386         walk_use(self, path, hir_id)
387     }
388     fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) {
389         walk_trait_item(self, ti)
390     }
391     fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) {
392         walk_trait_item_ref(self, ii)
393     }
394     fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) {
395         walk_impl_item(self, ii)
396     }
397     fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef) {
398         walk_foreign_item_ref(self, ii)
399     }
400     fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) {
401         walk_impl_item_ref(self, ii)
402     }
403     fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) {
404         walk_trait_ref(self, t)
405     }
406     fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) {
407         walk_param_bound(self, bounds)
408     }
409     fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>, m: TraitBoundModifier) {
410         walk_poly_trait_ref(self, t, m)
411     }
412     fn visit_variant_data(
413         &mut self,
414         s: &'v VariantData<'v>,
415         _: Symbol,
416         _: &'v Generics<'v>,
417         _parent_id: HirId,
418         _: Span,
419     ) {
420         walk_struct_def(self, s)
421     }
422     fn visit_field_def(&mut self, s: &'v FieldDef<'v>) {
423         walk_field_def(self, s)
424     }
425     fn visit_enum_def(
426         &mut self,
427         enum_definition: &'v EnumDef<'v>,
428         generics: &'v Generics<'v>,
429         item_id: HirId,
430         _: Span,
431     ) {
432         walk_enum_def(self, enum_definition, generics, item_id)
433     }
434     fn visit_variant(&mut self, v: &'v Variant<'v>, g: &'v Generics<'v>, item_id: HirId) {
435         walk_variant(self, v, g, item_id)
436     }
437     fn visit_label(&mut self, label: &'v Label) {
438         walk_label(self, label)
439     }
440     fn visit_infer(&mut self, inf: &'v InferArg) {
441         walk_inf(self, inf);
442     }
443     fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) {
444         match generic_arg {
445             GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
446             GenericArg::Type(ty) => self.visit_ty(ty),
447             GenericArg::Const(ct) => self.visit_anon_const(&ct.value),
448             GenericArg::Infer(inf) => self.visit_infer(inf),
449         }
450     }
451     fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
452         walk_lifetime(self, lifetime)
453     }
454     fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, span: Span) {
455         walk_qpath(self, qpath, id, span)
456     }
457     fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) {
458         walk_path(self, path)
459     }
460     fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment<'v>) {
461         walk_path_segment(self, path_span, path_segment)
462     }
463     fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<'v>) {
464         walk_generic_args(self, path_span, generic_args)
465     }
466     fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
467         walk_assoc_type_binding(self, type_binding)
468     }
469     fn visit_attribute(&mut self, _attr: &'v Attribute) {}
470     fn visit_associated_item_kind(&mut self, kind: &'v AssocItemKind) {
471         walk_associated_item_kind(self, kind);
472     }
473     fn visit_defaultness(&mut self, defaultness: &'v Defaultness) {
474         walk_defaultness(self, defaultness);
475     }
476     fn visit_inline_asm(&mut self, asm: &'v InlineAsm<'v>, id: HirId) {
477         walk_inline_asm(self, asm, id);
478     }
479 }
480
481 pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) {
482     visitor.visit_id(mod_hir_id);
483     for &item_id in module.item_ids {
484         visitor.visit_nested_item(item_id);
485     }
486 }
487
488 pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
489     walk_list!(visitor, visit_param, body.params);
490     visitor.visit_expr(&body.value);
491 }
492
493 pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
494     // Intentionally visiting the expr first - the initialization expr
495     // dominates the local's definition.
496     walk_list!(visitor, visit_expr, &local.init);
497     visitor.visit_id(local.hir_id);
498     visitor.visit_pat(&local.pat);
499     walk_list!(visitor, visit_ty, &local.ty);
500 }
501
502 pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
503     visitor.visit_name(ident.span, ident.name);
504 }
505
506 pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
507     visitor.visit_ident(label.ident);
508 }
509
510 pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
511     visitor.visit_id(lifetime.hir_id);
512     match lifetime.name {
513         LifetimeName::Param(_, ParamName::Plain(ident)) => {
514             visitor.visit_ident(ident);
515         }
516         LifetimeName::Param(_, ParamName::Fresh)
517         | LifetimeName::Param(_, ParamName::Error)
518         | LifetimeName::Static
519         | LifetimeName::Error
520         | LifetimeName::Implicit
521         | LifetimeName::ImplicitObjectLifetimeDefault
522         | LifetimeName::Underscore => {}
523     }
524 }
525
526 pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(
527     visitor: &mut V,
528     trait_ref: &'v PolyTraitRef<'v>,
529     _modifier: TraitBoundModifier,
530 ) {
531     walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
532     visitor.visit_trait_ref(&trait_ref.trait_ref);
533 }
534
535 pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) {
536     visitor.visit_id(trait_ref.hir_ref_id);
537     visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
538 }
539
540 pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
541     visitor.visit_id(param.hir_id);
542     visitor.visit_pat(&param.pat);
543 }
544
545 pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
546     visitor.visit_ident(item.ident);
547     match item.kind {
548         ItemKind::ExternCrate(orig_name) => {
549             visitor.visit_id(item.hir_id());
550             if let Some(orig_name) = orig_name {
551                 visitor.visit_name(item.span, orig_name);
552             }
553         }
554         ItemKind::Use(ref path, _) => {
555             visitor.visit_use(path, item.hir_id());
556         }
557         ItemKind::Static(ref typ, _, body) | ItemKind::Const(ref typ, body) => {
558             visitor.visit_id(item.hir_id());
559             visitor.visit_ty(typ);
560             visitor.visit_nested_body(body);
561         }
562         ItemKind::Fn(ref sig, ref generics, body_id) => visitor.visit_fn(
563             FnKind::ItemFn(item.ident, generics, sig.header),
564             &sig.decl,
565             body_id,
566             item.span,
567             item.hir_id(),
568         ),
569         ItemKind::Macro(..) => {
570             visitor.visit_id(item.hir_id());
571         }
572         ItemKind::Mod(ref module) => {
573             // `visit_mod()` takes care of visiting the `Item`'s `HirId`.
574             visitor.visit_mod(module, item.span, item.hir_id())
575         }
576         ItemKind::ForeignMod { abi: _, items } => {
577             visitor.visit_id(item.hir_id());
578             walk_list!(visitor, visit_foreign_item_ref, items);
579         }
580         ItemKind::GlobalAsm(asm) => {
581             visitor.visit_id(item.hir_id());
582             visitor.visit_inline_asm(asm, item.hir_id());
583         }
584         ItemKind::TyAlias(ref ty, ref generics) => {
585             visitor.visit_id(item.hir_id());
586             visitor.visit_ty(ty);
587             visitor.visit_generics(generics)
588         }
589         ItemKind::OpaqueTy(OpaqueTy { ref generics, bounds, .. }) => {
590             visitor.visit_id(item.hir_id());
591             walk_generics(visitor, generics);
592             walk_list!(visitor, visit_param_bound, bounds);
593         }
594         ItemKind::Enum(ref enum_definition, ref generics) => {
595             visitor.visit_generics(generics);
596             // `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
597             visitor.visit_enum_def(enum_definition, generics, item.hir_id(), item.span)
598         }
599         ItemKind::Impl(Impl {
600             unsafety: _,
601             defaultness: _,
602             polarity: _,
603             constness: _,
604             defaultness_span: _,
605             ref generics,
606             ref of_trait,
607             ref self_ty,
608             items,
609         }) => {
610             visitor.visit_id(item.hir_id());
611             visitor.visit_generics(generics);
612             walk_list!(visitor, visit_trait_ref, of_trait);
613             visitor.visit_ty(self_ty);
614             walk_list!(visitor, visit_impl_item_ref, *items);
615         }
616         ItemKind::Struct(ref struct_definition, ref generics)
617         | ItemKind::Union(ref struct_definition, ref generics) => {
618             visitor.visit_generics(generics);
619             visitor.visit_id(item.hir_id());
620             visitor.visit_variant_data(
621                 struct_definition,
622                 item.ident.name,
623                 generics,
624                 item.hir_id(),
625                 item.span,
626             );
627         }
628         ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
629             visitor.visit_id(item.hir_id());
630             visitor.visit_generics(generics);
631             walk_list!(visitor, visit_param_bound, bounds);
632             walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
633         }
634         ItemKind::TraitAlias(ref generics, bounds) => {
635             visitor.visit_id(item.hir_id());
636             visitor.visit_generics(generics);
637             walk_list!(visitor, visit_param_bound, bounds);
638         }
639     }
640 }
641
642 pub fn walk_inline_asm<'v, V: Visitor<'v>>(visitor: &mut V, asm: &'v InlineAsm<'v>, id: HirId) {
643     for (op, op_sp) in asm.operands {
644         match op {
645             InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => {
646                 visitor.visit_expr(expr)
647             }
648             InlineAsmOperand::Out { expr, .. } => {
649                 if let Some(expr) = expr {
650                     visitor.visit_expr(expr);
651                 }
652             }
653             InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
654                 visitor.visit_expr(in_expr);
655                 if let Some(out_expr) = out_expr {
656                     visitor.visit_expr(out_expr);
657                 }
658             }
659             InlineAsmOperand::Const { anon_const, .. }
660             | InlineAsmOperand::SymFn { anon_const, .. } => visitor.visit_anon_const(anon_const),
661             InlineAsmOperand::SymStatic { path, .. } => visitor.visit_qpath(path, id, *op_sp),
662         }
663     }
664 }
665
666 pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>, hir_id: HirId) {
667     visitor.visit_id(hir_id);
668     visitor.visit_path(path, hir_id);
669 }
670
671 pub fn walk_enum_def<'v, V: Visitor<'v>>(
672     visitor: &mut V,
673     enum_definition: &'v EnumDef<'v>,
674     generics: &'v Generics<'v>,
675     item_id: HirId,
676 ) {
677     visitor.visit_id(item_id);
678     walk_list!(visitor, visit_variant, enum_definition.variants, generics, item_id);
679 }
680
681 pub fn walk_variant<'v, V: Visitor<'v>>(
682     visitor: &mut V,
683     variant: &'v Variant<'v>,
684     generics: &'v Generics<'v>,
685     parent_item_id: HirId,
686 ) {
687     visitor.visit_ident(variant.ident);
688     visitor.visit_id(variant.id);
689     visitor.visit_variant_data(
690         &variant.data,
691         variant.ident.name,
692         generics,
693         parent_item_id,
694         variant.span,
695     );
696     walk_list!(visitor, visit_anon_const, &variant.disr_expr);
697 }
698
699 pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
700     visitor.visit_id(typ.hir_id);
701
702     match typ.kind {
703         TyKind::Slice(ref ty) => visitor.visit_ty(ty),
704         TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
705         TyKind::Rptr(ref lifetime, ref mutable_type) => {
706             visitor.visit_lifetime(lifetime);
707             visitor.visit_ty(&mutable_type.ty)
708         }
709         TyKind::Never => {}
710         TyKind::Tup(tuple_element_types) => {
711             walk_list!(visitor, visit_ty, tuple_element_types);
712         }
713         TyKind::BareFn(ref function_declaration) => {
714             walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
715             visitor.visit_fn_decl(&function_declaration.decl);
716         }
717         TyKind::Path(ref qpath) => {
718             visitor.visit_qpath(qpath, typ.hir_id, typ.span);
719         }
720         TyKind::OpaqueDef(item_id, lifetimes) => {
721             visitor.visit_nested_item(item_id);
722             walk_list!(visitor, visit_generic_arg, lifetimes);
723         }
724         TyKind::Array(ref ty, ref length) => {
725             visitor.visit_ty(ty);
726             visitor.visit_array_length(length)
727         }
728         TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
729             for bound in bounds {
730                 visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None);
731             }
732             visitor.visit_lifetime(lifetime);
733         }
734         TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
735         TyKind::Infer | TyKind::Err => {}
736     }
737 }
738
739 pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) {
740     visitor.visit_id(inf.hir_id);
741 }
742
743 pub fn walk_qpath<'v, V: Visitor<'v>>(
744     visitor: &mut V,
745     qpath: &'v QPath<'v>,
746     id: HirId,
747     span: Span,
748 ) {
749     match *qpath {
750         QPath::Resolved(ref maybe_qself, ref path) => {
751             walk_list!(visitor, visit_ty, maybe_qself);
752             visitor.visit_path(path, id)
753         }
754         QPath::TypeRelative(ref qself, ref segment) => {
755             visitor.visit_ty(qself);
756             visitor.visit_path_segment(span, segment);
757         }
758         QPath::LangItem(..) => {}
759     }
760 }
761
762 pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
763     for segment in path.segments {
764         visitor.visit_path_segment(path.span, segment);
765     }
766 }
767
768 pub fn walk_path_segment<'v, V: Visitor<'v>>(
769     visitor: &mut V,
770     path_span: Span,
771     segment: &'v PathSegment<'v>,
772 ) {
773     visitor.visit_ident(segment.ident);
774     walk_list!(visitor, visit_id, segment.hir_id);
775     if let Some(ref args) = segment.args {
776         visitor.visit_generic_args(path_span, args);
777     }
778 }
779
780 pub fn walk_generic_args<'v, V: Visitor<'v>>(
781     visitor: &mut V,
782     _path_span: Span,
783     generic_args: &'v GenericArgs<'v>,
784 ) {
785     walk_list!(visitor, visit_generic_arg, generic_args.args);
786     walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
787 }
788
789 pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
790     visitor: &mut V,
791     type_binding: &'v TypeBinding<'v>,
792 ) {
793     visitor.visit_id(type_binding.hir_id);
794     visitor.visit_ident(type_binding.ident);
795     visitor.visit_generic_args(type_binding.span, type_binding.gen_args);
796     match type_binding.kind {
797         TypeBindingKind::Equality { ref term } => match term {
798             Term::Ty(ref ty) => visitor.visit_ty(ty),
799             Term::Const(ref c) => visitor.visit_anon_const(c),
800         },
801         TypeBindingKind::Constraint { bounds } => walk_list!(visitor, visit_param_bound, bounds),
802     }
803 }
804
805 pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
806     visitor.visit_id(pattern.hir_id);
807     match pattern.kind {
808         PatKind::TupleStruct(ref qpath, children, _) => {
809             visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
810             walk_list!(visitor, visit_pat, children);
811         }
812         PatKind::Path(ref qpath) => {
813             visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
814         }
815         PatKind::Struct(ref qpath, fields, _) => {
816             visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
817             for field in fields {
818                 visitor.visit_id(field.hir_id);
819                 visitor.visit_ident(field.ident);
820                 visitor.visit_pat(&field.pat)
821             }
822         }
823         PatKind::Or(pats) => walk_list!(visitor, visit_pat, pats),
824         PatKind::Tuple(tuple_elements, _) => {
825             walk_list!(visitor, visit_pat, tuple_elements);
826         }
827         PatKind::Box(ref subpattern) | PatKind::Ref(ref subpattern, _) => {
828             visitor.visit_pat(subpattern)
829         }
830         PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => {
831             visitor.visit_ident(ident);
832             walk_list!(visitor, visit_pat, optional_subpattern);
833         }
834         PatKind::Lit(ref expression) => visitor.visit_expr(expression),
835         PatKind::Range(ref lower_bound, ref upper_bound, _) => {
836             walk_list!(visitor, visit_expr, lower_bound);
837             walk_list!(visitor, visit_expr, upper_bound);
838         }
839         PatKind::Wild => (),
840         PatKind::Slice(prepatterns, ref slice_pattern, postpatterns) => {
841             walk_list!(visitor, visit_pat, prepatterns);
842             walk_list!(visitor, visit_pat, slice_pattern);
843             walk_list!(visitor, visit_pat, postpatterns);
844         }
845     }
846 }
847
848 pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) {
849     visitor.visit_id(foreign_item.hir_id());
850     visitor.visit_ident(foreign_item.ident);
851
852     match foreign_item.kind {
853         ForeignItemKind::Fn(ref function_declaration, param_names, ref generics) => {
854             visitor.visit_generics(generics);
855             visitor.visit_fn_decl(function_declaration);
856             for &param_name in param_names {
857                 visitor.visit_ident(param_name);
858             }
859         }
860         ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ),
861         ForeignItemKind::Type => (),
862     }
863 }
864
865 pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
866     match *bound {
867         GenericBound::Trait(ref typ, modifier) => {
868             visitor.visit_poly_trait_ref(typ, modifier);
869         }
870         GenericBound::LangItemTrait(_, span, hir_id, args) => {
871             visitor.visit_id(hir_id);
872             visitor.visit_generic_args(span, args);
873         }
874         GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
875     }
876 }
877
878 pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam<'v>) {
879     visitor.visit_id(param.hir_id);
880     match param.name {
881         ParamName::Plain(ident) => visitor.visit_ident(ident),
882         ParamName::Error | ParamName::Fresh => {}
883     }
884     match param.kind {
885         GenericParamKind::Lifetime { .. } => {}
886         GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
887         GenericParamKind::Const { ref ty, ref default } => {
888             visitor.visit_ty(ty);
889             if let Some(ref default) = default {
890                 visitor.visit_const_param_default(param.hir_id, default);
891             }
892         }
893     }
894 }
895
896 pub fn walk_const_param_default<'v, V: Visitor<'v>>(visitor: &mut V, ct: &'v AnonConst) {
897     visitor.visit_anon_const(ct)
898 }
899
900 pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) {
901     walk_list!(visitor, visit_generic_param, generics.params);
902     walk_list!(visitor, visit_where_predicate, generics.predicates);
903 }
904
905 pub fn walk_where_predicate<'v, V: Visitor<'v>>(
906     visitor: &mut V,
907     predicate: &'v WherePredicate<'v>,
908 ) {
909     match *predicate {
910         WherePredicate::BoundPredicate(WhereBoundPredicate {
911             ref bounded_ty,
912             bounds,
913             bound_generic_params,
914             ..
915         }) => {
916             visitor.visit_ty(bounded_ty);
917             walk_list!(visitor, visit_param_bound, bounds);
918             walk_list!(visitor, visit_generic_param, bound_generic_params);
919         }
920         WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
921             visitor.visit_lifetime(lifetime);
922             walk_list!(visitor, visit_param_bound, bounds);
923         }
924         WherePredicate::EqPredicate(WhereEqPredicate {
925             hir_id, ref lhs_ty, ref rhs_ty, ..
926         }) => {
927             visitor.visit_id(hir_id);
928             visitor.visit_ty(lhs_ty);
929             visitor.visit_ty(rhs_ty);
930         }
931     }
932 }
933
934 pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) {
935     if let FnRetTy::Return(ref output_ty) = *ret_ty {
936         visitor.visit_ty(output_ty)
937     }
938 }
939
940 pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) {
941     for ty in function_declaration.inputs {
942         visitor.visit_ty(ty)
943     }
944     walk_fn_ret_ty(visitor, &function_declaration.output)
945 }
946
947 pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) {
948     match function_kind {
949         FnKind::ItemFn(_, generics, ..) => {
950             visitor.visit_generics(generics);
951         }
952         FnKind::Method(..) | FnKind::Closure => {}
953     }
954 }
955
956 pub fn walk_fn<'v, V: Visitor<'v>>(
957     visitor: &mut V,
958     function_kind: FnKind<'v>,
959     function_declaration: &'v FnDecl<'v>,
960     body_id: BodyId,
961     _span: Span,
962     id: HirId,
963 ) {
964     visitor.visit_id(id);
965     visitor.visit_fn_decl(function_declaration);
966     walk_fn_kind(visitor, function_kind);
967     visitor.visit_nested_body(body_id)
968 }
969
970 pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) {
971     visitor.visit_ident(trait_item.ident);
972     visitor.visit_generics(&trait_item.generics);
973     match trait_item.kind {
974         TraitItemKind::Const(ref ty, default) => {
975             visitor.visit_id(trait_item.hir_id());
976             visitor.visit_ty(ty);
977             walk_list!(visitor, visit_nested_body, default);
978         }
979         TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
980             visitor.visit_id(trait_item.hir_id());
981             visitor.visit_fn_decl(&sig.decl);
982             for &param_name in param_names {
983                 visitor.visit_ident(param_name);
984             }
985         }
986         TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
987             visitor.visit_fn(
988                 FnKind::Method(trait_item.ident, sig),
989                 &sig.decl,
990                 body_id,
991                 trait_item.span,
992                 trait_item.hir_id(),
993             );
994         }
995         TraitItemKind::Type(bounds, ref default) => {
996             visitor.visit_id(trait_item.hir_id());
997             walk_list!(visitor, visit_param_bound, bounds);
998             walk_list!(visitor, visit_ty, default);
999         }
1000     }
1001 }
1002
1003 pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) {
1004     // N.B., deliberately force a compilation error if/when new fields are added.
1005     let TraitItemRef { id, ident, ref kind, span: _, ref defaultness } = *trait_item_ref;
1006     visitor.visit_nested_trait_item(id);
1007     visitor.visit_ident(ident);
1008     visitor.visit_associated_item_kind(kind);
1009     visitor.visit_defaultness(defaultness);
1010 }
1011
1012 pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
1013     // N.B., deliberately force a compilation error if/when new fields are added.
1014     let ImplItem { def_id: _, ident, ref generics, ref kind, span: _, vis_span: _ } = *impl_item;
1015
1016     visitor.visit_ident(ident);
1017     visitor.visit_generics(generics);
1018     match *kind {
1019         ImplItemKind::Const(ref ty, body) => {
1020             visitor.visit_id(impl_item.hir_id());
1021             visitor.visit_ty(ty);
1022             visitor.visit_nested_body(body);
1023         }
1024         ImplItemKind::Fn(ref sig, body_id) => {
1025             visitor.visit_fn(
1026                 FnKind::Method(impl_item.ident, sig),
1027                 &sig.decl,
1028                 body_id,
1029                 impl_item.span,
1030                 impl_item.hir_id(),
1031             );
1032         }
1033         ImplItemKind::TyAlias(ref ty) => {
1034             visitor.visit_id(impl_item.hir_id());
1035             visitor.visit_ty(ty);
1036         }
1037     }
1038 }
1039
1040 pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(
1041     visitor: &mut V,
1042     foreign_item_ref: &'v ForeignItemRef,
1043 ) {
1044     // N.B., deliberately force a compilation error if/when new fields are added.
1045     let ForeignItemRef { id, ident, span: _ } = *foreign_item_ref;
1046     visitor.visit_nested_foreign_item(id);
1047     visitor.visit_ident(ident);
1048 }
1049
1050 pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) {
1051     // N.B., deliberately force a compilation error if/when new fields are added.
1052     let ImplItemRef { id, ident, ref kind, span: _, ref defaultness, trait_item_def_id: _ } =
1053         *impl_item_ref;
1054     visitor.visit_nested_impl_item(id);
1055     visitor.visit_ident(ident);
1056     visitor.visit_associated_item_kind(kind);
1057     visitor.visit_defaultness(defaultness);
1058 }
1059
1060 pub fn walk_struct_def<'v, V: Visitor<'v>>(
1061     visitor: &mut V,
1062     struct_definition: &'v VariantData<'v>,
1063 ) {
1064     walk_list!(visitor, visit_id, struct_definition.ctor_hir_id());
1065     walk_list!(visitor, visit_field_def, struct_definition.fields());
1066 }
1067
1068 pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) {
1069     visitor.visit_id(field.hir_id);
1070     visitor.visit_ident(field.ident);
1071     visitor.visit_ty(&field.ty);
1072 }
1073
1074 pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
1075     visitor.visit_id(block.hir_id);
1076     walk_list!(visitor, visit_stmt, block.stmts);
1077     walk_list!(visitor, visit_expr, &block.expr);
1078 }
1079
1080 pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
1081     visitor.visit_id(statement.hir_id);
1082     match statement.kind {
1083         StmtKind::Local(ref local) => visitor.visit_local(local),
1084         StmtKind::Item(item) => visitor.visit_nested_item(item),
1085         StmtKind::Expr(ref expression) | StmtKind::Semi(ref expression) => {
1086             visitor.visit_expr(expression)
1087         }
1088     }
1089 }
1090
1091 pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
1092     match len {
1093         &ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
1094         ArrayLen::Body(c) => visitor.visit_anon_const(c),
1095     }
1096 }
1097
1098 pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) {
1099     visitor.visit_id(constant.hir_id);
1100     visitor.visit_nested_body(constant.body);
1101 }
1102
1103 pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>) {
1104     // match the visit order in walk_local
1105     visitor.visit_expr(let_expr.init);
1106     visitor.visit_id(let_expr.hir_id);
1107     visitor.visit_pat(let_expr.pat);
1108     walk_list!(visitor, visit_ty, let_expr.ty);
1109 }
1110
1111 pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
1112     visitor.visit_id(expression.hir_id);
1113     match expression.kind {
1114         ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
1115         ExprKind::Array(subexpressions) => {
1116             walk_list!(visitor, visit_expr, subexpressions);
1117         }
1118         ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const),
1119         ExprKind::Repeat(ref element, ref count) => {
1120             visitor.visit_expr(element);
1121             visitor.visit_array_length(count)
1122         }
1123         ExprKind::Struct(ref qpath, fields, ref optional_base) => {
1124             visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1125             for field in fields {
1126                 visitor.visit_id(field.hir_id);
1127                 visitor.visit_ident(field.ident);
1128                 visitor.visit_expr(&field.expr)
1129             }
1130             walk_list!(visitor, visit_expr, optional_base);
1131         }
1132         ExprKind::Tup(subexpressions) => {
1133             walk_list!(visitor, visit_expr, subexpressions);
1134         }
1135         ExprKind::Call(ref callee_expression, arguments) => {
1136             visitor.visit_expr(callee_expression);
1137             walk_list!(visitor, visit_expr, arguments);
1138         }
1139         ExprKind::MethodCall(ref segment, arguments, _) => {
1140             visitor.visit_path_segment(expression.span, segment);
1141             walk_list!(visitor, visit_expr, arguments);
1142         }
1143         ExprKind::Binary(_, ref left_expression, ref right_expression) => {
1144             visitor.visit_expr(left_expression);
1145             visitor.visit_expr(right_expression)
1146         }
1147         ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
1148             visitor.visit_expr(subexpression)
1149         }
1150         ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
1151             visitor.visit_expr(subexpression);
1152             visitor.visit_ty(typ)
1153         }
1154         ExprKind::DropTemps(ref subexpression) => {
1155             visitor.visit_expr(subexpression);
1156         }
1157         ExprKind::Let(ref let_expr) => visitor.visit_let_expr(let_expr),
1158         ExprKind::If(ref cond, ref then, ref else_opt) => {
1159             visitor.visit_expr(cond);
1160             visitor.visit_expr(then);
1161             walk_list!(visitor, visit_expr, else_opt);
1162         }
1163         ExprKind::Loop(ref block, ref opt_label, _, _) => {
1164             walk_list!(visitor, visit_label, opt_label);
1165             visitor.visit_block(block);
1166         }
1167         ExprKind::Match(ref subexpression, arms, _) => {
1168             visitor.visit_expr(subexpression);
1169             walk_list!(visitor, visit_arm, arms);
1170         }
1171         ExprKind::Closure {
1172             bound_generic_params,
1173             ref fn_decl,
1174             body,
1175             capture_clause: _,
1176             fn_decl_span: _,
1177             movability: _,
1178         } => {
1179             walk_list!(visitor, visit_generic_param, bound_generic_params);
1180             visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, expression.hir_id)
1181         }
1182         ExprKind::Block(ref block, ref opt_label) => {
1183             walk_list!(visitor, visit_label, opt_label);
1184             visitor.visit_block(block);
1185         }
1186         ExprKind::Assign(ref lhs, ref rhs, _) => {
1187             visitor.visit_expr(rhs);
1188             visitor.visit_expr(lhs)
1189         }
1190         ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
1191             visitor.visit_expr(right_expression);
1192             visitor.visit_expr(left_expression);
1193         }
1194         ExprKind::Field(ref subexpression, ident) => {
1195             visitor.visit_expr(subexpression);
1196             visitor.visit_ident(ident);
1197         }
1198         ExprKind::Index(ref main_expression, ref index_expression) => {
1199             visitor.visit_expr(main_expression);
1200             visitor.visit_expr(index_expression)
1201         }
1202         ExprKind::Path(ref qpath) => {
1203             visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1204         }
1205         ExprKind::Break(ref destination, ref opt_expr) => {
1206             walk_list!(visitor, visit_label, &destination.label);
1207             walk_list!(visitor, visit_expr, opt_expr);
1208         }
1209         ExprKind::Continue(ref destination) => {
1210             walk_list!(visitor, visit_label, &destination.label);
1211         }
1212         ExprKind::Ret(ref optional_expression) => {
1213             walk_list!(visitor, visit_expr, optional_expression);
1214         }
1215         ExprKind::InlineAsm(ref asm) => {
1216             visitor.visit_inline_asm(asm, expression.hir_id);
1217         }
1218         ExprKind::Yield(ref subexpression, _) => {
1219             visitor.visit_expr(subexpression);
1220         }
1221         ExprKind::Lit(_) | ExprKind::Err => {}
1222     }
1223 }
1224
1225 pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
1226     visitor.visit_id(arm.hir_id);
1227     visitor.visit_pat(&arm.pat);
1228     if let Some(ref g) = arm.guard {
1229         match g {
1230             Guard::If(ref e) => visitor.visit_expr(e),
1231             Guard::IfLet(ref l) => {
1232                 visitor.visit_let_expr(l);
1233             }
1234         }
1235     }
1236     visitor.visit_expr(&arm.body);
1237 }
1238
1239 pub fn walk_associated_item_kind<'v, V: Visitor<'v>>(_: &mut V, _: &'v AssocItemKind) {
1240     // No visitable content here: this fn exists so you can call it if
1241     // the right thing to do, should content be added in the future,
1242     // would be to walk it.
1243 }
1244
1245 pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) {
1246     // No visitable content here: this fn exists so you can call it if
1247     // the right thing to do, should content be added in the future,
1248     // would be to walk it.
1249 }