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