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