@@ -114,71 +114,65 @@ pub trait HirTyCtxt<'hir> {
114114 fn hir_foreign_item ( & self , id : ForeignItemId ) -> & ' hir ForeignItem < ' hir > ;
115115}
116116
117- // Used when no tcx is actually available, forcing manual implementation of nested visitors.
117+ /// Used when no tcx is actually available, forcing manual implementation of nested visitors.
118118impl < ' hir > HirTyCtxt < ' hir > for ! {
119119 fn hir_node ( & self , _: HirId ) -> Node < ' hir > {
120- unreachable ! ( ) ;
120+ * self
121121 }
122122 fn hir_body ( & self , _: BodyId ) -> & ' hir Body < ' hir > {
123- unreachable ! ( ) ;
123+ * self
124124 }
125125 fn hir_item ( & self , _: ItemId ) -> & ' hir Item < ' hir > {
126- unreachable ! ( ) ;
126+ * self
127127 }
128128 fn hir_trait_item ( & self , _: TraitItemId ) -> & ' hir TraitItem < ' hir > {
129- unreachable ! ( ) ;
129+ * self
130130 }
131131 fn hir_impl_item ( & self , _: ImplItemId ) -> & ' hir ImplItem < ' hir > {
132- unreachable ! ( ) ;
132+ * self
133133 }
134134 fn hir_foreign_item ( & self , _: ForeignItemId ) -> & ' hir ForeignItem < ' hir > {
135- unreachable ! ( ) ;
135+ * self
136136 }
137137}
138138
139- pub mod nested_filter {
140- use super :: HirTyCtxt ;
141-
142- /// Specifies what nested things a visitor wants to visit. By "nested
143- /// things", we are referring to bits of HIR that are not directly embedded
144- /// within one another but rather indirectly, through a table in the crate.
145- /// This is done to control dependencies during incremental compilation: the
146- /// non-inline bits of HIR can be tracked and hashed separately.
147- ///
148- /// The most common choice is `OnlyBodies`, which will cause the visitor to
149- /// visit fn bodies for fns that it encounters, and closure bodies, but
150- /// skip over nested item-like things.
151- ///
152- /// See the comments at [`rustc_hir::intravisit`] for more details on the overall
153- /// visit strategy.
154- pub trait NestedFilter < ' hir > {
155- type MaybeTyCtxt : HirTyCtxt < ' hir > ;
156-
157- /// Whether the visitor visits nested "item-like" things.
158- /// E.g., item, impl-item.
159- const INTER : bool ;
160- /// Whether the visitor visits "intra item-like" things.
161- /// E.g., function body, closure, `AnonConst`
162- const INTRA : bool ;
163- }
164-
165- /// Do not visit any nested things. When you add a new
166- /// "non-nested" thing, you will want to audit such uses to see if
167- /// they remain valid.
168- ///
169- /// Use this if you are only walking some particular kind of tree
170- /// (i.e., a type, or fn signature) and you don't want to thread a
171- /// `tcx` around.
172- pub struct None ( ( ) ) ;
173- impl NestedFilter < ' _ > for None {
174- type MaybeTyCtxt = !;
175- const INTER : bool = false ;
176- const INTRA : bool = false ;
177- }
139+ /// Specifies what nested things a visitor wants to visit. By "nested
140+ /// things", we are referring to bits of HIR that are not directly embedded
141+ /// within one another but rather indirectly, through a table in the crate.
142+ /// This is done to control dependencies during incremental compilation: the
143+ /// non-inline bits of HIR can be tracked and hashed separately.
144+ ///
145+ /// The most common choice is `OnlyBodies`, which will cause the visitor to
146+ /// visit fn bodies for fns that it encounters, and closure bodies, but
147+ /// skip over nested item-like things.
148+ ///
149+ /// See the [module level documentation](self) for more details on the overall
150+ /// visit strategy.
151+ pub trait NestedFilter < ' hir > {
152+ type MaybeTyCtxt : HirTyCtxt < ' hir > ;
153+
154+ /// Whether the visitor visits nested "item-like" things.
155+ /// E.g., item, impl-item.
156+ const INTER : bool ;
157+ /// Whether the visitor visits "intra item-like" things.
158+ /// E.g., function body, closure, `AnonConst`
159+ const INTRA : bool ;
160+ }
161+
162+ /// Do not visit any nested things. When you add a new
163+ /// "non-nested" thing, you will want to audit such uses to see if
164+ /// they remain valid.
165+ ///
166+ /// Use this if you are only walking some particular kind of tree
167+ /// (i.e., a type, or fn signature) and you don't want to thread a
168+ /// `tcx` around.
169+ pub struct IgnoreNested ( ( ) ) ;
170+ impl NestedFilter < ' _ > for IgnoreNested {
171+ type MaybeTyCtxt = !;
172+ const INTER : bool = false ;
173+ const INTRA : bool = false ;
178174}
179175
180- use nested_filter:: NestedFilter ;
181-
182176/// Each method of the Visitor trait is a hook to be potentially
183177/// overridden. Each method's default implementation recursively visits
184178/// the substructure of the input via the corresponding `walk` method;
@@ -215,7 +209,7 @@ pub trait Visitor<'v>: Sized {
215209 /// `visit_nested_XXX` methods. If a new `visit_nested_XXX` variant is
216210 /// added in the future, it will cause a panic which can be detected
217211 /// and fixed appropriately.
218- type NestedFilter : NestedFilter < ' v > = nested_filter :: None ;
212+ type NestedFilter : NestedFilter < ' v > = IgnoreNested ;
219213
220214 /// The result type of the `visit_*` methods. Can be either `()`,
221215 /// or `ControlFlow<T>`.
@@ -226,16 +220,16 @@ pub trait Visitor<'v>: Sized {
226220 fn maybe_tcx ( & mut self ) -> Self :: MaybeTyCtxt {
227221 panic ! (
228222 "maybe_tcx must be implemented or consider using \
229- `type NestedFilter = nested_filter::None ` (the default)"
223+ `type NestedFilter = Skip ` (the default)"
230224 ) ;
231225 }
232226
233227 /// Invoked when a nested item is encountered. By default, when
234- /// `Self::NestedFilter` is `nested_filter::None `, this method does
228+ /// `Self::NestedFilter` is `Skip `, this method does
235229 /// nothing. **You probably don't want to override this method** --
236230 /// instead, override [`Self::NestedFilter`] or use the "shallow" or
237231 /// "deep" visit patterns described at
238- /// [`rustc_hir:: intravisit`]. The only reason to override
232+ /// [`intravisit`](self) . The only reason to override
239233 /// this method is if you want a nested pattern but cannot supply a
240234 /// `TyCtxt`; see `maybe_tcx` for advice.
241235 fn visit_nested_item ( & mut self , id : ItemId ) -> Self :: Result {
0 commit comments