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