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