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