1818//! within one another.
1919//! - Example: Examine each expression to look for its type and do some check or other.
2020//! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
21- //! `nested_filter::OnlyBodies` (and implement `nested_visit_map `), and use
21+ //! `nested_filter::OnlyBodies` (and implement `nested_visit_cx `), and use
2222//! `tcx.hir().visit_all_item_likes_in_crate(&mut visitor)`. Within your
2323//! `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke
2424//! `intravisit::walk_expr()` to keep walking the subparts).
3030//! - Example: Lifetime resolution, which wants to bring lifetimes declared on the
3131//! impl into scope while visiting the impl-items, and then back out again.
3232//! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
33- //! `nested_filter::All` (and implement `nested_visit_map `). Walk your crate with
33+ //! `nested_filter::All` (and implement `nested_visit_cx `). Walk your crate with
3434//! `tcx.hir().walk_toplevel_module(visitor)` invoked on `tcx.hir().krate()`.
3535//! - Pro: Visitor methods for any kind of HIR node, not just item-like things.
3636//! - Pro: Preserves nesting information
@@ -106,20 +106,20 @@ impl<'a> FnKind<'a> {
106106 }
107107}
108108
109- /// An abstract representation of the HIR `rustc_middle::hir::map::Map `.
110- pub trait Map < ' hir > {
109+ /// An abstract representation of HIR things retrievable from `TyCtxt `.
110+ pub trait HirCtxt < ' hir > {
111111 /// Retrieves the `Node` corresponding to `id`.
112- fn hir_node ( & self , hir_id : HirId ) -> Node < ' hir > ;
112+ fn node ( & self , hir_id : HirId ) -> Node < ' hir > ;
113113 fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > ;
114114 fn item ( & self , id : ItemId ) -> & ' hir Item < ' hir > ;
115115 fn trait_item ( & self , id : TraitItemId ) -> & ' hir TraitItem < ' hir > ;
116116 fn impl_item ( & self , id : ImplItemId ) -> & ' hir ImplItem < ' hir > ;
117117 fn foreign_item ( & self , id : ForeignItemId ) -> & ' hir ForeignItem < ' hir > ;
118118}
119119
120- // Used when no map is actually available, forcing manual implementation of nested visitors.
121- impl < ' hir > Map < ' hir > for ! {
122- fn hir_node ( & self , _: HirId ) -> Node < ' hir > {
120+ // Used when no tcx is actually available, forcing manual implementation of nested visitors.
121+ impl < ' hir > HirCtxt < ' hir > for ! {
122+ fn node ( & self , _: HirId ) -> Node < ' hir > {
123123 unreachable ! ( ) ;
124124 }
125125 fn body ( & self , _: BodyId ) -> & ' hir Body < ' hir > {
@@ -140,7 +140,7 @@ impl<'hir> Map<'hir> for ! {
140140}
141141
142142pub mod nested_filter {
143- use super :: Map ;
143+ use super :: HirCtxt ;
144144
145145 /// Specifies what nested things a visitor wants to visit. By "nested
146146 /// things", we are referring to bits of HIR that are not directly embedded
@@ -155,7 +155,7 @@ pub mod nested_filter {
155155 /// See the comments at [`rustc_hir::intravisit`] for more details on the overall
156156 /// visit strategy.
157157 pub trait NestedFilter < ' hir > {
158- type Map : Map < ' hir > ;
158+ type Cx : HirCtxt < ' hir > ;
159159
160160 /// Whether the visitor visits nested "item-like" things.
161161 /// E.g., item, impl-item.
@@ -171,10 +171,10 @@ pub mod nested_filter {
171171 ///
172172 /// Use this if you are only walking some particular kind of tree
173173 /// (i.e., a type, or fn signature) and you don't want to thread a
174- /// HIR map around.
174+ /// `tcx` around.
175175 pub struct None ( ( ) ) ;
176176 impl NestedFilter < ' _ > for None {
177- type Map = !;
177+ type Cx = !;
178178 const INTER : bool = false ;
179179 const INTRA : bool = false ;
180180 }
@@ -199,18 +199,18 @@ use nested_filter::NestedFilter;
199199/// to monitor future changes to `Visitor` in case a new method with a
200200/// new default implementation gets introduced.)
201201pub trait Visitor < ' v > : Sized {
202- // This type should not be overridden, it exists for convenient usage as `Self::Map `.
203- type Map : Map < ' v > = <Self :: NestedFilter as NestedFilter < ' v > >:: Map ;
202+ // This type should not be overridden, it exists for convenient usage as `Self::Cx `.
203+ type Cx : HirCtxt < ' v > = <Self :: NestedFilter as NestedFilter < ' v > >:: Cx ;
204204
205205 ///////////////////////////////////////////////////////////////////////////
206206 // Nested items.
207207
208208 /// Override this type to control which nested HIR are visited; see
209209 /// [`NestedFilter`] for details. If you override this type, you
210- /// must also override [`nested_visit_map `](Self::nested_visit_map ).
210+ /// must also override [`nested_visit_cx `](Self::nested_visit_cx ).
211211 ///
212212 /// **If for some reason you want the nested behavior, but don't
213- /// have a `Map ` at your disposal:** then override the
213+ /// have a `tcx ` at your disposal:** then override the
214214 /// `visit_nested_XXX` methods. If a new `visit_nested_XXX` variant is
215215 /// added in the future, it will cause a panic which can be detected
216216 /// and fixed appropriately.
@@ -222,9 +222,9 @@ pub trait Visitor<'v>: Sized {
222222
223223 /// If `type NestedFilter` is set to visit nested items, this method
224224 /// must also be overridden to provide a map to retrieve nested items.
225- fn nested_visit_map ( & mut self ) -> Self :: Map {
225+ fn nested_visit_cx ( & mut self ) -> Self :: Cx {
226226 panic ! (
227- "nested_visit_map must be implemented or consider using \
227+ "nested_visit_cx must be implemented or consider using \
228228 `type NestedFilter = nested_filter::None` (the default)"
229229 ) ;
230230 }
@@ -236,10 +236,10 @@ pub trait Visitor<'v>: Sized {
236236 /// "deep" visit patterns described at
237237 /// [`rustc_hir::intravisit`]. The only reason to override
238238 /// this method is if you want a nested pattern but cannot supply a
239- /// [`Map`]; see `nested_visit_map ` for advice.
239+ /// [`Map`]; see `nested_visit_cx ` for advice.
240240 fn visit_nested_item ( & mut self , id : ItemId ) -> Self :: Result {
241241 if Self :: NestedFilter :: INTER {
242- let item = self . nested_visit_map ( ) . item ( id) ;
242+ let item = self . nested_visit_cx ( ) . item ( id) ;
243243 try_visit ! ( self . visit_item( item) ) ;
244244 }
245245 Self :: Result :: output ( )
@@ -250,7 +250,7 @@ pub trait Visitor<'v>: Sized {
250250 /// method.
251251 fn visit_nested_trait_item ( & mut self , id : TraitItemId ) -> Self :: Result {
252252 if Self :: NestedFilter :: INTER {
253- let item = self . nested_visit_map ( ) . trait_item ( id) ;
253+ let item = self . nested_visit_cx ( ) . trait_item ( id) ;
254254 try_visit ! ( self . visit_trait_item( item) ) ;
255255 }
256256 Self :: Result :: output ( )
@@ -261,7 +261,7 @@ pub trait Visitor<'v>: Sized {
261261 /// method.
262262 fn visit_nested_impl_item ( & mut self , id : ImplItemId ) -> Self :: Result {
263263 if Self :: NestedFilter :: INTER {
264- let item = self . nested_visit_map ( ) . impl_item ( id) ;
264+ let item = self . nested_visit_cx ( ) . impl_item ( id) ;
265265 try_visit ! ( self . visit_impl_item( item) ) ;
266266 }
267267 Self :: Result :: output ( )
@@ -272,7 +272,7 @@ pub trait Visitor<'v>: Sized {
272272 /// method.
273273 fn visit_nested_foreign_item ( & mut self , id : ForeignItemId ) -> Self :: Result {
274274 if Self :: NestedFilter :: INTER {
275- let item = self . nested_visit_map ( ) . foreign_item ( id) ;
275+ let item = self . nested_visit_cx ( ) . foreign_item ( id) ;
276276 try_visit ! ( self . visit_foreign_item( item) ) ;
277277 }
278278 Self :: Result :: output ( )
@@ -283,7 +283,7 @@ pub trait Visitor<'v>: Sized {
283283 /// `Self::NestedFilter`.
284284 fn visit_nested_body ( & mut self , id : BodyId ) -> Self :: Result {
285285 if Self :: NestedFilter :: INTRA {
286- let body = self . nested_visit_map ( ) . body ( id) ;
286+ let body = self . nested_visit_cx ( ) . body ( id) ;
287287 try_visit ! ( self . visit_body( body) ) ;
288288 }
289289 Self :: Result :: output ( )
0 commit comments