]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_hir/src/intravisit.rs
Auto merge of #96517 - ferrocene:pa-files-related-to-test, r=Mark-Simulacrum
[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),
104
105     /// `fn foo(&self)`
106     Method(Ident, &'a FnSig<'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. By "nested
167     /// things", we are referring to bits of HIR that are not directly embedded
168     /// within one another but rather indirectly, through a table in the crate.
169     /// This is done to control dependencies during incremental compilation: the
170     /// non-inline bits of HIR can be tracked and hashed separately.
171     ///
172     /// The most common choice is `OnlyBodies`, which will cause the visitor to
173     /// visit fn bodies for fns that it encounters, and closure bodies, but
174     /// skip over nested item-like things.
175     ///
176     /// See the comments on `ItemLikeVisitor` for more details on the overall
177     /// visit strategy.
178     pub trait NestedFilter<'hir> {
179         type Map: Map<'hir>;
180
181         /// Whether the visitor visits nested "item-like" things.
182         /// E.g., item, impl-item.
183         const INTER: bool;
184         /// Whether the visitor visits "intra item-like" things.
185         /// E.g., function body, closure, `AnonConst`
186         const INTRA: bool;
187     }
188
189     /// Do not visit any nested things. When you add a new
190     /// "non-nested" thing, you will want to audit such uses to see if
191     /// they remain valid.
192     ///
193     /// Use this if you are only walking some particular kind of tree
194     /// (i.e., a type, or fn signature) and you don't want to thread a
195     /// HIR map around.
196     pub struct None(());
197     impl NestedFilter<'_> for None {
198         type Map = !;
199         const INTER: bool = false;
200         const INTRA: bool = false;
201     }
202 }
203
204 use nested_filter::NestedFilter;
205
206 /// Each method of the Visitor trait is a hook to be potentially
207 /// overridden. Each method's default implementation recursively visits
208 /// the substructure of the input via the corresponding `walk` method;
209 /// e.g., the `visit_mod` method by default calls `intravisit::walk_mod`.
210 ///
211 /// Note that this visitor does NOT visit nested items by default
212 /// (this is why the module is called `intravisit`, to distinguish it
213 /// from the AST's `visit` module, which acts differently). If you
214 /// simply want to visit all items in the crate in some order, you
215 /// should call `Crate::visit_all_items`. Otherwise, see the comment
216 /// on `visit_nested_item` for details on how to visit nested items.
217 ///
218 /// If you want to ensure that your code handles every variant
219 /// explicitly, you need to override each method. (And you also need
220 /// to monitor future changes to `Visitor` in case a new method with a
221 /// new default implementation gets introduced.)
222 pub trait Visitor<'v>: Sized {
223     // this type should not be overridden, it exists for convenient usage as `Self::Map`
224     type Map: Map<'v> = <Self::NestedFilter as NestedFilter<'v>>::Map;
225
226     ///////////////////////////////////////////////////////////////////////////
227     // Nested items.
228
229     /// Override this type to control which nested HIR are visited; see
230     /// [`NestedFilter`] for details. If you override this type, you
231     /// must also override [`nested_visit_map`](Self::nested_visit_map).
232     ///
233     /// **If for some reason you want the nested behavior, but don't
234     /// have a `Map` at your disposal:** then override the
235     /// `visit_nested_XXX` methods. If a new `visit_nested_XXX` variant is
236     /// added in the future, it will cause a panic which can be detected
237     /// and fixed appropriately.
238     type NestedFilter: NestedFilter<'v> = nested_filter::None;
239
240     /// If `type NestedFilter` is set to visit nested items, this method
241     /// must also be overridden to provide a map to retrieve nested items.
242     fn nested_visit_map(&mut self) -> Self::Map {
243         panic!(
244             "nested_visit_map must be implemented or consider using \
245             `type NestedFilter = nested_filter::None` (the default)"
246         );
247     }
248
249     /// Invoked when a nested item is encountered. By default, when
250     /// `Self::NestedFilter` is `nested_filter::None`, this method does
251     /// nothing. **You probably don't want to override this method** --
252     /// instead, override [`Self::NestedFilter`] or use the "shallow" or
253     /// "deep" visit patterns described on
254     /// `itemlikevisit::ItemLikeVisitor`. The only reason to override
255     /// this method is if you want a nested pattern but cannot supply a
256     /// [`Map`]; see `nested_visit_map` for advice.
257     fn visit_nested_item(&mut self, id: ItemId) {
258         if Self::NestedFilter::INTER {
259             let item = self.nested_visit_map().item(id);
260             self.visit_item(item);
261         }
262     }
263
264     /// Like `visit_nested_item()`, but for trait items. See
265     /// `visit_nested_item()` for advice on when to override this
266     /// method.
267     fn visit_nested_trait_item(&mut self, id: TraitItemId) {
268         if Self::NestedFilter::INTER {
269             let item = self.nested_visit_map().trait_item(id);
270             self.visit_trait_item(item);
271         }
272     }
273
274     /// Like `visit_nested_item()`, but for impl items. See
275     /// `visit_nested_item()` for advice on when to override this
276     /// method.
277     fn visit_nested_impl_item(&mut self, id: ImplItemId) {
278         if Self::NestedFilter::INTER {
279             let item = self.nested_visit_map().impl_item(id);
280             self.visit_impl_item(item);
281         }
282     }
283
284     /// Like `visit_nested_item()`, but for foreign items. See
285     /// `visit_nested_item()` for advice on when to override this
286     /// method.
287     fn visit_nested_foreign_item(&mut self, id: ForeignItemId) {
288         if Self::NestedFilter::INTER {
289             let item = self.nested_visit_map().foreign_item(id);
290             self.visit_foreign_item(item);
291         }
292     }
293
294     /// Invoked to visit the body of a function, method or closure. Like
295     /// `visit_nested_item`, does nothing by default unless you override
296     /// `Self::NestedFilter`.
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_associated_item_kind(&mut self, kind: &'v AssocItemKind) {
479         walk_associated_item_kind(self, kind);
480     }
481     fn visit_defaultness(&mut self, defaultness: &'v Defaultness) {
482         walk_defaultness(self, defaultness);
483     }
484     fn visit_inline_asm(&mut self, asm: &'v InlineAsm<'v>, id: HirId) {
485         walk_inline_asm(self, asm, id);
486     }
487 }
488
489 pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) {
490     visitor.visit_id(mod_hir_id);
491     for &item_id in module.item_ids {
492         visitor.visit_nested_item(item_id);
493     }
494 }
495
496 pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
497     walk_list!(visitor, visit_param, body.params);
498     visitor.visit_expr(&body.value);
499 }
500
501 pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
502     // Intentionally visiting the expr first - the initialization expr
503     // dominates the local's definition.
504     walk_list!(visitor, visit_expr, &local.init);
505     visitor.visit_id(local.hir_id);
506     visitor.visit_pat(&local.pat);
507     walk_list!(visitor, visit_ty, &local.ty);
508 }
509
510 pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
511     visitor.visit_name(ident.span, ident.name);
512 }
513
514 pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
515     visitor.visit_ident(label.ident);
516 }
517
518 pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
519     visitor.visit_id(lifetime.hir_id);
520     match lifetime.name {
521         LifetimeName::Param(ParamName::Plain(ident)) => {
522             visitor.visit_ident(ident);
523         }
524         LifetimeName::Param(ParamName::Fresh(_))
525         | LifetimeName::Param(ParamName::Error)
526         | LifetimeName::Static
527         | LifetimeName::Error
528         | LifetimeName::Implicit
529         | LifetimeName::ImplicitObjectLifetimeDefault
530         | LifetimeName::Underscore => {}
531     }
532 }
533
534 pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(
535     visitor: &mut V,
536     trait_ref: &'v PolyTraitRef<'v>,
537     _modifier: TraitBoundModifier,
538 ) {
539     walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
540     visitor.visit_trait_ref(&trait_ref.trait_ref);
541 }
542
543 pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) {
544     visitor.visit_id(trait_ref.hir_ref_id);
545     visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
546 }
547
548 pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
549     visitor.visit_id(param.hir_id);
550     visitor.visit_pat(&param.pat);
551 }
552
553 pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
554     visitor.visit_ident(item.ident);
555     match item.kind {
556         ItemKind::ExternCrate(orig_name) => {
557             visitor.visit_id(item.hir_id());
558             if let Some(orig_name) = orig_name {
559                 visitor.visit_name(item.span, orig_name);
560             }
561         }
562         ItemKind::Use(ref path, _) => {
563             visitor.visit_use(path, item.hir_id());
564         }
565         ItemKind::Static(ref typ, _, body) | ItemKind::Const(ref typ, body) => {
566             visitor.visit_id(item.hir_id());
567             visitor.visit_ty(typ);
568             visitor.visit_nested_body(body);
569         }
570         ItemKind::Fn(ref sig, ref generics, body_id) => visitor.visit_fn(
571             FnKind::ItemFn(item.ident, generics, sig.header),
572             &sig.decl,
573             body_id,
574             item.span,
575             item.hir_id(),
576         ),
577         ItemKind::Macro(..) => {
578             visitor.visit_id(item.hir_id());
579         }
580         ItemKind::Mod(ref module) => {
581             // `visit_mod()` takes care of visiting the `Item`'s `HirId`.
582             visitor.visit_mod(module, item.span, item.hir_id())
583         }
584         ItemKind::ForeignMod { abi: _, items } => {
585             visitor.visit_id(item.hir_id());
586             walk_list!(visitor, visit_foreign_item_ref, items);
587         }
588         ItemKind::GlobalAsm(asm) => {
589             visitor.visit_id(item.hir_id());
590             visitor.visit_inline_asm(asm, item.hir_id());
591         }
592         ItemKind::TyAlias(ref ty, ref generics) => {
593             visitor.visit_id(item.hir_id());
594             visitor.visit_ty(ty);
595             visitor.visit_generics(generics)
596         }
597         ItemKind::OpaqueTy(OpaqueTy { ref generics, bounds, .. }) => {
598             visitor.visit_id(item.hir_id());
599             walk_generics(visitor, generics);
600             walk_list!(visitor, visit_param_bound, bounds);
601         }
602         ItemKind::Enum(ref enum_definition, ref generics) => {
603             visitor.visit_generics(generics);
604             // `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
605             visitor.visit_enum_def(enum_definition, generics, item.hir_id(), item.span)
606         }
607         ItemKind::Impl(Impl {
608             unsafety: _,
609             defaultness: _,
610             polarity: _,
611             constness: _,
612             defaultness_span: _,
613             ref generics,
614             ref of_trait,
615             ref self_ty,
616             items,
617         }) => {
618             visitor.visit_id(item.hir_id());
619             visitor.visit_generics(generics);
620             walk_list!(visitor, visit_trait_ref, of_trait);
621             visitor.visit_ty(self_ty);
622             walk_list!(visitor, visit_impl_item_ref, *items);
623         }
624         ItemKind::Struct(ref struct_definition, ref generics)
625         | ItemKind::Union(ref struct_definition, ref generics) => {
626             visitor.visit_generics(generics);
627             visitor.visit_id(item.hir_id());
628             visitor.visit_variant_data(
629                 struct_definition,
630                 item.ident.name,
631                 generics,
632                 item.hir_id(),
633                 item.span,
634             );
635         }
636         ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
637             visitor.visit_id(item.hir_id());
638             visitor.visit_generics(generics);
639             walk_list!(visitor, visit_param_bound, bounds);
640             walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
641         }
642         ItemKind::TraitAlias(ref generics, bounds) => {
643             visitor.visit_id(item.hir_id());
644             visitor.visit_generics(generics);
645             walk_list!(visitor, visit_param_bound, bounds);
646         }
647     }
648 }
649
650 pub fn walk_inline_asm<'v, V: Visitor<'v>>(visitor: &mut V, asm: &'v InlineAsm<'v>, id: HirId) {
651     for (op, op_sp) in asm.operands {
652         match op {
653             InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => {
654                 visitor.visit_expr(expr)
655             }
656             InlineAsmOperand::Out { expr, .. } => {
657                 if let Some(expr) = expr {
658                     visitor.visit_expr(expr);
659                 }
660             }
661             InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
662                 visitor.visit_expr(in_expr);
663                 if let Some(out_expr) = out_expr {
664                     visitor.visit_expr(out_expr);
665                 }
666             }
667             InlineAsmOperand::Const { anon_const, .. }
668             | InlineAsmOperand::SymFn { anon_const, .. } => visitor.visit_anon_const(anon_const),
669             InlineAsmOperand::SymStatic { path, .. } => visitor.visit_qpath(path, id, *op_sp),
670         }
671     }
672 }
673
674 pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>, hir_id: HirId) {
675     visitor.visit_id(hir_id);
676     visitor.visit_path(path, hir_id);
677 }
678
679 pub fn walk_enum_def<'v, V: Visitor<'v>>(
680     visitor: &mut V,
681     enum_definition: &'v EnumDef<'v>,
682     generics: &'v Generics<'v>,
683     item_id: HirId,
684 ) {
685     visitor.visit_id(item_id);
686     walk_list!(visitor, visit_variant, enum_definition.variants, generics, item_id);
687 }
688
689 pub fn walk_variant<'v, V: Visitor<'v>>(
690     visitor: &mut V,
691     variant: &'v Variant<'v>,
692     generics: &'v Generics<'v>,
693     parent_item_id: HirId,
694 ) {
695     visitor.visit_ident(variant.ident);
696     visitor.visit_id(variant.id);
697     visitor.visit_variant_data(
698         &variant.data,
699         variant.ident.name,
700         generics,
701         parent_item_id,
702         variant.span,
703     );
704     walk_list!(visitor, visit_anon_const, &variant.disr_expr);
705 }
706
707 pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
708     visitor.visit_id(typ.hir_id);
709
710     match typ.kind {
711         TyKind::Slice(ref ty) => visitor.visit_ty(ty),
712         TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
713         TyKind::Rptr(ref lifetime, ref mutable_type) => {
714             visitor.visit_lifetime(lifetime);
715             visitor.visit_ty(&mutable_type.ty)
716         }
717         TyKind::Never => {}
718         TyKind::Tup(tuple_element_types) => {
719             walk_list!(visitor, visit_ty, tuple_element_types);
720         }
721         TyKind::BareFn(ref function_declaration) => {
722             walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
723             visitor.visit_fn_decl(&function_declaration.decl);
724         }
725         TyKind::Path(ref qpath) => {
726             visitor.visit_qpath(qpath, typ.hir_id, typ.span);
727         }
728         TyKind::OpaqueDef(item_id, lifetimes) => {
729             visitor.visit_nested_item(item_id);
730             walk_list!(visitor, visit_generic_arg, lifetimes);
731         }
732         TyKind::Array(ref ty, ref length) => {
733             visitor.visit_ty(ty);
734             visitor.visit_array_length(length)
735         }
736         TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
737             for bound in bounds {
738                 visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None);
739             }
740             visitor.visit_lifetime(lifetime);
741         }
742         TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
743         TyKind::Infer | TyKind::Err => {}
744     }
745 }
746
747 pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) {
748     visitor.visit_id(inf.hir_id);
749 }
750
751 pub fn walk_qpath<'v, V: Visitor<'v>>(
752     visitor: &mut V,
753     qpath: &'v QPath<'v>,
754     id: HirId,
755     span: Span,
756 ) {
757     match *qpath {
758         QPath::Resolved(ref maybe_qself, ref path) => {
759             walk_list!(visitor, visit_ty, maybe_qself);
760             visitor.visit_path(path, id)
761         }
762         QPath::TypeRelative(ref qself, ref segment) => {
763             visitor.visit_ty(qself);
764             visitor.visit_path_segment(span, segment);
765         }
766         QPath::LangItem(..) => {}
767     }
768 }
769
770 pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
771     for segment in path.segments {
772         visitor.visit_path_segment(path.span, segment);
773     }
774 }
775
776 pub fn walk_path_segment<'v, V: Visitor<'v>>(
777     visitor: &mut V,
778     path_span: Span,
779     segment: &'v PathSegment<'v>,
780 ) {
781     visitor.visit_ident(segment.ident);
782     walk_list!(visitor, visit_id, segment.hir_id);
783     if let Some(ref args) = segment.args {
784         visitor.visit_generic_args(path_span, args);
785     }
786 }
787
788 pub fn walk_generic_args<'v, V: Visitor<'v>>(
789     visitor: &mut V,
790     _path_span: Span,
791     generic_args: &'v GenericArgs<'v>,
792 ) {
793     walk_list!(visitor, visit_generic_arg, generic_args.args);
794     walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
795 }
796
797 pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
798     visitor: &mut V,
799     type_binding: &'v TypeBinding<'v>,
800 ) {
801     visitor.visit_id(type_binding.hir_id);
802     visitor.visit_ident(type_binding.ident);
803     visitor.visit_generic_args(type_binding.span, type_binding.gen_args);
804     match type_binding.kind {
805         TypeBindingKind::Equality { ref term } => match term {
806             Term::Ty(ref ty) => visitor.visit_ty(ty),
807             Term::Const(ref c) => visitor.visit_anon_const(c),
808         },
809         TypeBindingKind::Constraint { bounds } => walk_list!(visitor, visit_param_bound, bounds),
810     }
811 }
812
813 pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
814     visitor.visit_id(pattern.hir_id);
815     match pattern.kind {
816         PatKind::TupleStruct(ref qpath, children, _) => {
817             visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
818             walk_list!(visitor, visit_pat, children);
819         }
820         PatKind::Path(ref qpath) => {
821             visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
822         }
823         PatKind::Struct(ref qpath, fields, _) => {
824             visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
825             for field in fields {
826                 visitor.visit_id(field.hir_id);
827                 visitor.visit_ident(field.ident);
828                 visitor.visit_pat(&field.pat)
829             }
830         }
831         PatKind::Or(pats) => walk_list!(visitor, visit_pat, pats),
832         PatKind::Tuple(tuple_elements, _) => {
833             walk_list!(visitor, visit_pat, tuple_elements);
834         }
835         PatKind::Box(ref subpattern) | PatKind::Ref(ref subpattern, _) => {
836             visitor.visit_pat(subpattern)
837         }
838         PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => {
839             visitor.visit_ident(ident);
840             walk_list!(visitor, visit_pat, optional_subpattern);
841         }
842         PatKind::Lit(ref expression) => visitor.visit_expr(expression),
843         PatKind::Range(ref lower_bound, ref upper_bound, _) => {
844             walk_list!(visitor, visit_expr, lower_bound);
845             walk_list!(visitor, visit_expr, upper_bound);
846         }
847         PatKind::Wild => (),
848         PatKind::Slice(prepatterns, ref slice_pattern, postpatterns) => {
849             walk_list!(visitor, visit_pat, prepatterns);
850             walk_list!(visitor, visit_pat, slice_pattern);
851             walk_list!(visitor, visit_pat, postpatterns);
852         }
853     }
854 }
855
856 pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) {
857     visitor.visit_id(foreign_item.hir_id());
858     visitor.visit_ident(foreign_item.ident);
859
860     match foreign_item.kind {
861         ForeignItemKind::Fn(ref function_declaration, param_names, ref generics) => {
862             visitor.visit_generics(generics);
863             visitor.visit_fn_decl(function_declaration);
864             for &param_name in param_names {
865                 visitor.visit_ident(param_name);
866             }
867         }
868         ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ),
869         ForeignItemKind::Type => (),
870     }
871 }
872
873 pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
874     match *bound {
875         GenericBound::Trait(ref typ, modifier) => {
876             visitor.visit_poly_trait_ref(typ, modifier);
877         }
878         GenericBound::LangItemTrait(_, span, hir_id, args) => {
879             visitor.visit_id(hir_id);
880             visitor.visit_generic_args(span, args);
881         }
882         GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
883     }
884 }
885
886 pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam<'v>) {
887     visitor.visit_id(param.hir_id);
888     match param.name {
889         ParamName::Plain(ident) => visitor.visit_ident(ident),
890         ParamName::Error | ParamName::Fresh(_) => {}
891     }
892     match param.kind {
893         GenericParamKind::Lifetime { .. } => {}
894         GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
895         GenericParamKind::Const { ref ty, ref default } => {
896             visitor.visit_ty(ty);
897             if let Some(ref default) = default {
898                 visitor.visit_const_param_default(param.hir_id, default);
899             }
900         }
901     }
902 }
903
904 pub fn walk_const_param_default<'v, V: Visitor<'v>>(visitor: &mut V, ct: &'v AnonConst) {
905     visitor.visit_anon_const(ct)
906 }
907
908 pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) {
909     walk_list!(visitor, visit_generic_param, generics.params);
910     walk_list!(visitor, visit_where_predicate, generics.predicates);
911 }
912
913 pub fn walk_where_predicate<'v, V: Visitor<'v>>(
914     visitor: &mut V,
915     predicate: &'v WherePredicate<'v>,
916 ) {
917     match *predicate {
918         WherePredicate::BoundPredicate(WhereBoundPredicate {
919             ref bounded_ty,
920             bounds,
921             bound_generic_params,
922             ..
923         }) => {
924             visitor.visit_ty(bounded_ty);
925             walk_list!(visitor, visit_param_bound, bounds);
926             walk_list!(visitor, visit_generic_param, bound_generic_params);
927         }
928         WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
929             visitor.visit_lifetime(lifetime);
930             walk_list!(visitor, visit_param_bound, bounds);
931         }
932         WherePredicate::EqPredicate(WhereEqPredicate {
933             hir_id, ref lhs_ty, ref rhs_ty, ..
934         }) => {
935             visitor.visit_id(hir_id);
936             visitor.visit_ty(lhs_ty);
937             visitor.visit_ty(rhs_ty);
938         }
939     }
940 }
941
942 pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) {
943     if let FnRetTy::Return(ref output_ty) = *ret_ty {
944         visitor.visit_ty(output_ty)
945     }
946 }
947
948 pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) {
949     for ty in function_declaration.inputs {
950         visitor.visit_ty(ty)
951     }
952     walk_fn_ret_ty(visitor, &function_declaration.output)
953 }
954
955 pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) {
956     match function_kind {
957         FnKind::ItemFn(_, generics, ..) => {
958             visitor.visit_generics(generics);
959         }
960         FnKind::Method(..) | FnKind::Closure => {}
961     }
962 }
963
964 pub fn walk_fn<'v, V: Visitor<'v>>(
965     visitor: &mut V,
966     function_kind: FnKind<'v>,
967     function_declaration: &'v FnDecl<'v>,
968     body_id: BodyId,
969     _span: Span,
970     id: HirId,
971 ) {
972     visitor.visit_id(id);
973     visitor.visit_fn_decl(function_declaration);
974     walk_fn_kind(visitor, function_kind);
975     visitor.visit_nested_body(body_id)
976 }
977
978 pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) {
979     visitor.visit_ident(trait_item.ident);
980     visitor.visit_generics(&trait_item.generics);
981     match trait_item.kind {
982         TraitItemKind::Const(ref ty, default) => {
983             visitor.visit_id(trait_item.hir_id());
984             visitor.visit_ty(ty);
985             walk_list!(visitor, visit_nested_body, default);
986         }
987         TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
988             visitor.visit_id(trait_item.hir_id());
989             visitor.visit_fn_decl(&sig.decl);
990             for &param_name in param_names {
991                 visitor.visit_ident(param_name);
992             }
993         }
994         TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
995             visitor.visit_fn(
996                 FnKind::Method(trait_item.ident, sig),
997                 &sig.decl,
998                 body_id,
999                 trait_item.span,
1000                 trait_item.hir_id(),
1001             );
1002         }
1003         TraitItemKind::Type(bounds, ref default) => {
1004             visitor.visit_id(trait_item.hir_id());
1005             walk_list!(visitor, visit_param_bound, bounds);
1006             walk_list!(visitor, visit_ty, default);
1007         }
1008     }
1009 }
1010
1011 pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) {
1012     // N.B., deliberately force a compilation error if/when new fields are added.
1013     let TraitItemRef { id, ident, ref kind, span: _, ref defaultness } = *trait_item_ref;
1014     visitor.visit_nested_trait_item(id);
1015     visitor.visit_ident(ident);
1016     visitor.visit_associated_item_kind(kind);
1017     visitor.visit_defaultness(defaultness);
1018 }
1019
1020 pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
1021     // N.B., deliberately force a compilation error if/when new fields are added.
1022     let ImplItem { def_id: _, ident, ref generics, ref kind, span: _, vis_span: _ } = *impl_item;
1023
1024     visitor.visit_ident(ident);
1025     visitor.visit_generics(generics);
1026     match *kind {
1027         ImplItemKind::Const(ref ty, body) => {
1028             visitor.visit_id(impl_item.hir_id());
1029             visitor.visit_ty(ty);
1030             visitor.visit_nested_body(body);
1031         }
1032         ImplItemKind::Fn(ref sig, body_id) => {
1033             visitor.visit_fn(
1034                 FnKind::Method(impl_item.ident, sig),
1035                 &sig.decl,
1036                 body_id,
1037                 impl_item.span,
1038                 impl_item.hir_id(),
1039             );
1040         }
1041         ImplItemKind::TyAlias(ref ty) => {
1042             visitor.visit_id(impl_item.hir_id());
1043             visitor.visit_ty(ty);
1044         }
1045     }
1046 }
1047
1048 pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(
1049     visitor: &mut V,
1050     foreign_item_ref: &'v ForeignItemRef,
1051 ) {
1052     // N.B., deliberately force a compilation error if/when new fields are added.
1053     let ForeignItemRef { id, ident, span: _ } = *foreign_item_ref;
1054     visitor.visit_nested_foreign_item(id);
1055     visitor.visit_ident(ident);
1056 }
1057
1058 pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) {
1059     // N.B., deliberately force a compilation error if/when new fields are added.
1060     let ImplItemRef { id, ident, ref kind, span: _, ref defaultness, trait_item_def_id: _ } =
1061         *impl_item_ref;
1062     visitor.visit_nested_impl_item(id);
1063     visitor.visit_ident(ident);
1064     visitor.visit_associated_item_kind(kind);
1065     visitor.visit_defaultness(defaultness);
1066 }
1067
1068 pub fn walk_struct_def<'v, V: Visitor<'v>>(
1069     visitor: &mut V,
1070     struct_definition: &'v VariantData<'v>,
1071 ) {
1072     walk_list!(visitor, visit_id, struct_definition.ctor_hir_id());
1073     walk_list!(visitor, visit_field_def, struct_definition.fields());
1074 }
1075
1076 pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'v>) {
1077     visitor.visit_id(field.hir_id);
1078     visitor.visit_ident(field.ident);
1079     visitor.visit_ty(&field.ty);
1080 }
1081
1082 pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
1083     visitor.visit_id(block.hir_id);
1084     walk_list!(visitor, visit_stmt, block.stmts);
1085     walk_list!(visitor, visit_expr, &block.expr);
1086 }
1087
1088 pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
1089     visitor.visit_id(statement.hir_id);
1090     match statement.kind {
1091         StmtKind::Local(ref local) => visitor.visit_local(local),
1092         StmtKind::Item(item) => visitor.visit_nested_item(item),
1093         StmtKind::Expr(ref expression) | StmtKind::Semi(ref expression) => {
1094             visitor.visit_expr(expression)
1095         }
1096     }
1097 }
1098
1099 pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
1100     match len {
1101         &ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
1102         ArrayLen::Body(c) => visitor.visit_anon_const(c),
1103     }
1104 }
1105
1106 pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) {
1107     visitor.visit_id(constant.hir_id);
1108     visitor.visit_nested_body(constant.body);
1109 }
1110
1111 pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>) {
1112     // match the visit order in walk_local
1113     visitor.visit_expr(let_expr.init);
1114     visitor.visit_id(let_expr.hir_id);
1115     visitor.visit_pat(let_expr.pat);
1116     walk_list!(visitor, visit_ty, let_expr.ty);
1117 }
1118
1119 pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
1120     visitor.visit_id(expression.hir_id);
1121     match expression.kind {
1122         ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
1123         ExprKind::Array(subexpressions) => {
1124             walk_list!(visitor, visit_expr, subexpressions);
1125         }
1126         ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const),
1127         ExprKind::Repeat(ref element, ref count) => {
1128             visitor.visit_expr(element);
1129             visitor.visit_array_length(count)
1130         }
1131         ExprKind::Struct(ref qpath, fields, ref optional_base) => {
1132             visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1133             for field in fields {
1134                 visitor.visit_id(field.hir_id);
1135                 visitor.visit_ident(field.ident);
1136                 visitor.visit_expr(&field.expr)
1137             }
1138             walk_list!(visitor, visit_expr, optional_base);
1139         }
1140         ExprKind::Tup(subexpressions) => {
1141             walk_list!(visitor, visit_expr, subexpressions);
1142         }
1143         ExprKind::Call(ref callee_expression, arguments) => {
1144             visitor.visit_expr(callee_expression);
1145             walk_list!(visitor, visit_expr, arguments);
1146         }
1147         ExprKind::MethodCall(ref segment, arguments, _) => {
1148             visitor.visit_path_segment(expression.span, segment);
1149             walk_list!(visitor, visit_expr, arguments);
1150         }
1151         ExprKind::Binary(_, ref left_expression, ref right_expression) => {
1152             visitor.visit_expr(left_expression);
1153             visitor.visit_expr(right_expression)
1154         }
1155         ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
1156             visitor.visit_expr(subexpression)
1157         }
1158         ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
1159             visitor.visit_expr(subexpression);
1160             visitor.visit_ty(typ)
1161         }
1162         ExprKind::DropTemps(ref subexpression) => {
1163             visitor.visit_expr(subexpression);
1164         }
1165         ExprKind::Let(ref let_expr) => visitor.visit_let_expr(let_expr),
1166         ExprKind::If(ref cond, ref then, ref else_opt) => {
1167             visitor.visit_expr(cond);
1168             visitor.visit_expr(then);
1169             walk_list!(visitor, visit_expr, else_opt);
1170         }
1171         ExprKind::Loop(ref block, ref opt_label, _, _) => {
1172             walk_list!(visitor, visit_label, opt_label);
1173             visitor.visit_block(block);
1174         }
1175         ExprKind::Match(ref subexpression, arms, _) => {
1176             visitor.visit_expr(subexpression);
1177             walk_list!(visitor, visit_arm, arms);
1178         }
1179         ExprKind::Closure(_, ref function_declaration, body, _fn_decl_span, _gen) => visitor
1180             .visit_fn(
1181                 FnKind::Closure,
1182                 function_declaration,
1183                 body,
1184                 expression.span,
1185                 expression.hir_id,
1186             ),
1187         ExprKind::Block(ref block, ref opt_label) => {
1188             walk_list!(visitor, visit_label, opt_label);
1189             visitor.visit_block(block);
1190         }
1191         ExprKind::Assign(ref lhs, ref rhs, _) => {
1192             visitor.visit_expr(rhs);
1193             visitor.visit_expr(lhs)
1194         }
1195         ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
1196             visitor.visit_expr(right_expression);
1197             visitor.visit_expr(left_expression);
1198         }
1199         ExprKind::Field(ref subexpression, ident) => {
1200             visitor.visit_expr(subexpression);
1201             visitor.visit_ident(ident);
1202         }
1203         ExprKind::Index(ref main_expression, ref index_expression) => {
1204             visitor.visit_expr(main_expression);
1205             visitor.visit_expr(index_expression)
1206         }
1207         ExprKind::Path(ref qpath) => {
1208             visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1209         }
1210         ExprKind::Break(ref destination, ref opt_expr) => {
1211             walk_list!(visitor, visit_label, &destination.label);
1212             walk_list!(visitor, visit_expr, opt_expr);
1213         }
1214         ExprKind::Continue(ref destination) => {
1215             walk_list!(visitor, visit_label, &destination.label);
1216         }
1217         ExprKind::Ret(ref optional_expression) => {
1218             walk_list!(visitor, visit_expr, optional_expression);
1219         }
1220         ExprKind::InlineAsm(ref asm) => {
1221             visitor.visit_inline_asm(asm, expression.hir_id);
1222         }
1223         ExprKind::Yield(ref subexpression, _) => {
1224             visitor.visit_expr(subexpression);
1225         }
1226         ExprKind::Lit(_) | ExprKind::Err => {}
1227     }
1228 }
1229
1230 pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
1231     visitor.visit_id(arm.hir_id);
1232     visitor.visit_pat(&arm.pat);
1233     if let Some(ref g) = arm.guard {
1234         match g {
1235             Guard::If(ref e) => visitor.visit_expr(e),
1236             Guard::IfLet(ref pat, ref e) => {
1237                 visitor.visit_pat(pat);
1238                 visitor.visit_expr(e);
1239             }
1240         }
1241     }
1242     visitor.visit_expr(&arm.body);
1243 }
1244
1245 pub fn walk_associated_item_kind<'v, V: Visitor<'v>>(_: &mut V, _: &'v AssocItemKind) {
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 }
1250
1251 pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) {
1252     // No visitable content here: this fn exists so you can call it if
1253     // the right thing to do, should content be added in the future,
1254     // would be to walk it.
1255 }