@@ -163,10 +163,15 @@ impl<'hir> Map<'hir> for ! {
163163pub mod nested_filter {
164164 use super :: Map ;
165165
166- /// Specifies what nested things a visitor wants to visit. The most
167- /// common choice is `OnlyBodies`, which will cause the visitor to
168- /// visit fn bodies for fns that it encounters, but skip over nested
169- /// item-like things.
166+ /// Specifies what nested things a visitor wants to visit. By "nested
167+ /// things", we are referring to bits of HIR that are not directly embedded
168+ /// within one another but rather indirectly, through a table in the crate.
169+ /// This is done to control dependencies during incremental compilation: the
170+ /// non-inline bits of HIR can be tracked and hashed separately.
171+ ///
172+ /// The most common choice is `OnlyBodies`, which will cause the visitor to
173+ /// visit fn bodies for fns that it encounters, and closure bodies, but
174+ /// skip over nested item-like things.
170175 ///
171176 /// See the comments on `ItemLikeVisitor` for more details on the overall
172177 /// visit strategy.
@@ -217,42 +222,38 @@ use nested_filter::NestedFilter;
217222pub trait Visitor < ' v > : Sized {
218223 // this type should not be overridden, it exists for convenient usage as `Self::Map`
219224 type Map : Map < ' v > = <Self :: NestedFilter as NestedFilter < ' v > >:: Map ;
220- type NestedFilter : NestedFilter < ' v > = nested_filter:: None ;
221225
222226 ///////////////////////////////////////////////////////////////////////////
223227 // Nested items.
224228
225- /// The default versions of the `visit_nested_XXX` routines invoke
226- /// this method to get a map to use. By selecting an enum variant,
227- /// you control which kinds of nested HIR are visited; see
228- /// `NestedVisitorMap` for details. By "nested HIR", we are
229- /// referring to bits of HIR that are not directly embedded within
230- /// one another but rather indirectly, through a table in the
231- /// crate. This is done to control dependencies during incremental
232- /// compilation: the non-inline bits of HIR can be tracked and
233- /// hashed separately.
229+ /// Override this type to control which nested HIR are visited; see
230+ /// [`NestedFilter`] for details. If you override this type, you
231+ /// must also override [`nested_visit_map`](Self::nested_visit_map).
234232 ///
235233 /// **If for some reason you want the nested behavior, but don't
236- /// have a `Map` at your disposal:** then you should override the
237- /// `visit_nested_XXX` methods, and override this method to
238- /// `panic!()`. This way, if a new `visit_nested_XXX` variant is
239- /// added in the future, we will see the panic in your code and
240- /// fix it appropriately.
234+ /// have a `Map` at your disposal:** then override the
235+ /// `visit_nested_XXX` methods. If a new `visit_nested_XXX` variant is
236+ /// added in the future, it will cause a panic which can be detected
237+ /// and fixed appropriately.
238+ type NestedFilter : NestedFilter < ' v > = nested_filter:: None ;
239+
240+ /// If `type NestedFilter` is set to visit nested items, this method
241+ /// must also be overridden to provide a map to retrieve nested items.
241242 fn nested_visit_map ( & mut self ) -> Self :: Map {
242243 panic ! (
243244 "nested_visit_map must be implemented or consider using \
244245 `type NestedFilter = nested_filter::None` (the default)"
245246 ) ;
246247 }
247248
248- /// Invoked when a nested item is encountered. By default does
249- /// nothing unless you override `nested_visit_map` to return other than
250- /// `None`, in which case it will walk the item. **You probably
251- /// don't want to override this method** -- instead, override
252- /// `nested_visit_map` or use the "shallow" or " deep" visit
253- /// patterns described on `itemlikevisit::ItemLikeVisitor`. The only
254- /// reason to override this method is if you want a nested pattern
255- /// but cannot supply a `Map`; see `nested_visit_map` for advice.
249+ /// Invoked when a nested item is encountered. By default, when
250+ /// `Self::NestedFilter` is `nested_filter::None`, this method does
251+ /// nothing. **You probably don't want to override this method** --
252+ /// instead, override [`Self::NestedFilter`] or use the "shallow" or
253+ /// " deep" visit patterns described on
254+ /// `itemlikevisit::ItemLikeVisitor`. The only reason to override
255+ /// this method is if you want a nested pattern but cannot supply a
256+ /// [ `Map`] ; see `nested_visit_map` for advice.
256257 fn visit_nested_item ( & mut self , id : ItemId ) {
257258 if Self :: NestedFilter :: INTER {
258259 let item = self . nested_visit_map ( ) . item ( id) ;
@@ -291,9 +292,8 @@ pub trait Visitor<'v>: Sized {
291292 }
292293
293294 /// Invoked to visit the body of a function, method or closure. Like
294- /// visit_nested_item, does nothing by default unless you override
295- /// `nested_visit_map` to return other than `None`, in which case it will walk
296- /// the body.
295+ /// `visit_nested_item`, does nothing by default unless you override
296+ /// `Self::NestedFilter`.
297297 fn visit_nested_body ( & mut self , id : BodyId ) {
298298 if Self :: NestedFilter :: INTRA {
299299 let body = self . nested_visit_map ( ) . body ( id) ;
0 commit comments