@@ -40,6 +40,7 @@ pub const REGULAR_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High;
4040#[ derive( Copy , Clone , Debug ) ]
4141pub struct Entry < ' hir > {
4242 parent : NodeId ,
43+ parent_hir : HirId ,
4344 dep_node : DepNodeIndex ,
4445 node : Node < ' hir > ,
4546}
@@ -208,6 +209,12 @@ impl<'hir> Map<'hir> {
208209 }
209210 }
210211
212+ // FIXME(@ljedrz): replace the NodeId variant
213+ pub fn read_by_hir_id ( & self , hir_id : HirId ) {
214+ let node_id = self . hir_to_node_id ( hir_id) ;
215+ self . read ( node_id) ;
216+ }
217+
211218 #[ inline]
212219 pub fn definitions ( & self ) -> & ' hir Definitions {
213220 self . definitions
@@ -224,6 +231,11 @@ impl<'hir> Map<'hir> {
224231 } )
225232 }
226233
234+ // FIXME(@ljedrz): replace the NodeId variant
235+ pub fn def_path_from_hir_id ( & self , id : HirId ) -> DefPath {
236+ self . def_path ( self . local_def_id_from_hir_id ( id) )
237+ }
238+
227239 pub fn def_path ( & self , def_id : DefId ) -> DefPath {
228240 assert ! ( def_id. is_local( ) ) ;
229241 self . definitions . def_path ( def_id. index )
@@ -237,6 +249,22 @@ impl<'hir> Map<'hir> {
237249 } )
238250 }
239251
252+ // FIXME(@ljedrz): replace the NodeId variant
253+ #[ inline]
254+ pub fn local_def_id_from_hir_id ( & self , hir_id : HirId ) -> DefId {
255+ self . opt_local_def_id_from_hir_id ( hir_id) . unwrap_or_else ( || {
256+ let node_id = self . hir_to_node_id ( hir_id) ;
257+ bug ! ( "local_def_id_from_hir_id: no entry for `{:?}`, which has a map of `{:?}`" ,
258+ hir_id, self . find_entry( node_id) )
259+ } )
260+ }
261+
262+ // FIXME(@ljedrz): replace the NodeId variant
263+ #[ inline]
264+ pub fn opt_local_def_id_from_hir_id ( & self , hir_id : HirId ) -> Option < DefId > {
265+ self . definitions . opt_local_def_id_from_hir_id ( hir_id)
266+ }
267+
240268 #[ inline]
241269 pub fn opt_local_def_id ( & self , node : NodeId ) -> Option < DefId > {
242270 self . definitions . opt_local_def_id ( node)
@@ -247,6 +275,12 @@ impl<'hir> Map<'hir> {
247275 self . definitions . as_local_node_id ( def_id)
248276 }
249277
278+ // FIXME(@ljedrz): replace the NodeId variant
279+ #[ inline]
280+ pub fn as_local_hir_id ( & self , def_id : DefId ) -> Option < HirId > {
281+ self . definitions . as_local_hir_id ( def_id)
282+ }
283+
250284 #[ inline]
251285 pub fn hir_to_node_id ( & self , hir_id : HirId ) -> NodeId {
252286 self . hir_to_node_id [ & hir_id]
@@ -566,6 +600,12 @@ impl<'hir> Map<'hir> {
566600 self . find ( id) . unwrap_or_else ( || bug ! ( "couldn't find node id {} in the AST map" , id) )
567601 }
568602
603+ // FIXME(@ljedrz): replace the NodeId variant
604+ pub fn get_by_hir_id ( & self , id : HirId ) -> Node < ' hir > {
605+ let node_id = self . hir_to_node_id ( id) ;
606+ self . get ( node_id)
607+ }
608+
569609 pub fn get_if_local ( & self , id : DefId ) -> Option < Node < ' hir > > {
570610 self . as_local_node_id ( id) . map ( |id| self . get ( id) ) // read recorded by `get`
571611 }
@@ -613,6 +653,12 @@ impl<'hir> Map<'hir> {
613653 result
614654 }
615655
656+ // FIXME(@ljedrz): replace the NodeId variant
657+ pub fn find_by_hir_id ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
658+ let node_id = self . hir_to_node_id ( hir_id) ;
659+ self . find ( node_id)
660+ }
661+
616662 /// Similar to `get_parent`; returns the parent node-id, or own `id` if there is
617663 /// no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself
618664 /// present in the map -- so passing the return value of get_parent_node to
@@ -633,6 +679,13 @@ impl<'hir> Map<'hir> {
633679 self . find_entry ( id) . and_then ( |x| x. parent_node ( ) ) . unwrap_or ( id)
634680 }
635681
682+ // FIXME(@ljedrz): replace the NodeId variant
683+ pub fn get_parent_node_by_hir_id ( & self , id : HirId ) -> HirId {
684+ let node_id = self . hir_to_node_id ( id) ;
685+ let parent_node_id = self . get_parent_node ( node_id) ;
686+ self . node_to_hir_id ( parent_node_id)
687+ }
688+
636689 /// Check if the node is an argument. An argument is a local variable whose
637690 /// immediate parent is an item or a closure.
638691 pub fn is_argument ( & self , id : NodeId ) -> bool {
@@ -757,6 +810,13 @@ impl<'hir> Map<'hir> {
757810 }
758811 }
759812
813+ // FIXME(@ljedrz): replace the NodeId variant
814+ pub fn get_parent_item ( & self , id : HirId ) -> HirId {
815+ let node_id = self . hir_to_node_id ( id) ;
816+ let parent_node_id = self . get_parent ( node_id) ;
817+ self . node_to_hir_id ( parent_node_id)
818+ }
819+
760820 /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
761821 /// module parent is in this map.
762822 pub fn get_module_parent ( & self , id : NodeId ) -> DefId {
@@ -814,6 +874,12 @@ impl<'hir> Map<'hir> {
814874 }
815875 }
816876
877+ // FIXME(@ljedrz): replace the NodeId variant
878+ pub fn expect_item_by_hir_id ( & self , id : HirId ) -> & ' hir Item {
879+ let node_id = self . hir_to_node_id ( id) ;
880+ self . expect_item ( node_id)
881+ }
882+
817883 pub fn expect_impl_item ( & self , id : NodeId ) -> & ' hir ImplItem {
818884 match self . find ( id) {
819885 Some ( Node :: ImplItem ( item) ) => item,
@@ -960,13 +1026,28 @@ impl<'hir> Map<'hir> {
9601026 node_id_to_string ( self , id, true )
9611027 }
9621028
1029+ // FIXME(@ljedrz): replace the NodeId variant
1030+ pub fn hir_to_string ( & self , id : HirId ) -> String {
1031+ hir_id_to_string ( self , id, true )
1032+ }
1033+
9631034 pub fn node_to_user_string ( & self , id : NodeId ) -> String {
9641035 node_id_to_string ( self , id, false )
9651036 }
9661037
1038+ // FIXME(@ljedrz): replace the NodeId variant
1039+ pub fn hir_to_user_string ( & self , id : HirId ) -> String {
1040+ hir_id_to_string ( self , id, false )
1041+ }
1042+
9671043 pub fn node_to_pretty_string ( & self , id : NodeId ) -> String {
9681044 print:: to_string ( self , |s| s. print_node ( self . get ( id) ) )
9691045 }
1046+
1047+ // FIXME(@ljedrz): replace the NodeId variant
1048+ pub fn hir_to_pretty_string ( & self , id : HirId ) -> String {
1049+ print:: to_string ( self , |s| s. print_node ( self . get_by_hir_id ( id) ) )
1050+ }
9701051}
9711052
9721053pub struct NodesMatchingSuffix < ' a , ' hir : ' a > {
@@ -1310,6 +1391,12 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
13101391 }
13111392}
13121393
1394+ // FIXME(@ljedrz): replace the NodeId variant
1395+ fn hir_id_to_string ( map : & Map < ' _ > , id : HirId , include_id : bool ) -> String {
1396+ let node_id = map. hir_to_node_id ( id) ;
1397+ node_id_to_string ( map, node_id, include_id)
1398+ }
1399+
13131400pub fn describe_def ( tcx : TyCtxt < ' _ , ' _ , ' _ > , def_id : DefId ) -> Option < Def > {
13141401 if let Some ( node_id) = tcx. hir ( ) . as_local_node_id ( def_id) {
13151402 tcx. hir ( ) . describe_def ( node_id)
0 commit comments