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