@@ -67,22 +67,37 @@ impl<'a> FnKind<'a> {
67
67
}
68
68
}
69
69
70
- /// Specifies what nested things a visitor wants to visit. Currently there are
71
- /// two modes: `OnlyBodies` descends into item bodies, but not into nested
72
- /// items; `All` descends into item bodies and nested items.
70
+ /// Specifies what nested things a visitor wants to visit. The most
71
+ /// common choice is `OnlyBodies`, which will cause the visitor to
72
+ /// visit fn bodies for fns that it encounters, but skip over nested
73
+ /// item-like things.
74
+ ///
75
+ /// See the comments on `ItemLikeVisitor` for more details on the overall
76
+ /// visit strategy.
73
77
pub enum NestedVisitorMap < ' this , ' tcx : ' this > {
74
78
/// Do not visit any nested things. When you add a new
75
79
/// "non-nested" thing, you will want to audit such uses to see if
76
80
/// they remain valid.
81
+ ///
82
+ /// Use this if you are only walking some particular kind of tree
83
+ /// (i.e., a type, or fn signature) and you don't want to thread a
84
+ /// HIR map around.
77
85
None ,
78
86
79
87
/// Do not visit nested item-like things, but visit nested things
80
88
/// that are inside of an item-like.
81
89
///
82
- /// **This is the default mode.**
90
+ /// **This is the most common choice.** A very commmon pattern is
91
+ /// to use `tcx.visit_all_item_likes_in_krate()` as an outer loop,
92
+ /// and to have the visitor that visits the contents of each item
93
+ /// using this setting.
83
94
OnlyBodies ( & ' this Map < ' tcx > ) ,
84
95
85
96
/// Visit all nested things, including item-likes.
97
+ ///
98
+ /// **This is an unusual choice.** It is used when you want to
99
+ /// process everything within their lexical context. Typically you
100
+ /// kick off the visit by doing `walk_krate()`.
86
101
All ( & ' this Map < ' tcx > ) ,
87
102
}
88
103
@@ -128,13 +143,15 @@ pub trait Visitor<'v> : Sized {
128
143
///////////////////////////////////////////////////////////////////////////
129
144
// Nested items.
130
145
131
- /// The default versions of the `visit_nested_XXX` routines invoke this
132
- /// method to get a map to use; if they get back `None`, they just skip
133
- /// nested things. Otherwise, they will lookup the nested thing in the map
134
- /// and visit it depending on what `nested_visit_mode` returns. So the best
135
- /// way to implement a nested visitor is to override this method to return a
136
- /// `Map`; one advantage of this is that if we add more types of nested
137
- /// things in the future, they will automatically work.
146
+ /// The default versions of the `visit_nested_XXX` routines invoke
147
+ /// this method to get a map to use. By selecting an enum variant,
148
+ /// you control which kinds of nested HIR are visited; see
149
+ /// `NestedVisitorMap` for details. By "nested HIR", we are
150
+ /// referring to bits of HIR that are not directly embedded within
151
+ /// one another but rather indirectly, through a table in the
152
+ /// crate. This is done to control dependencies during incremental
153
+ /// compilation: the non-inline bits of HIR can be tracked and
154
+ /// hashed separately.
138
155
///
139
156
/// **If for some reason you want the nested behavior, but don't
140
157
/// have a `Map` are your disposal:** then you should override the
0 commit comments