@@ -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,23 @@ 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+ let node_id = self . hir_to_node_id ( hir_id) ;
256+ self . opt_local_def_id ( node_id) . unwrap_or_else ( || {
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+ let node_id = self . hir_to_node_id ( hir_id) ;
266+ self . definitions . opt_local_def_id ( node_id)
267+ }
268+
240269 #[ inline]
241270 pub fn opt_local_def_id ( & self , node : NodeId ) -> Option < DefId > {
242271 self . definitions . opt_local_def_id ( node)
@@ -247,6 +276,12 @@ impl<'hir> Map<'hir> {
247276 self . definitions . as_local_node_id ( def_id)
248277 }
249278
279+ // FIXME(@ljedrz): replace the NodeId variant
280+ #[ inline]
281+ pub fn as_local_hir_id ( & self , def_id : DefId ) -> Option < HirId > {
282+ self . definitions . as_local_hir_id ( def_id)
283+ }
284+
250285 #[ inline]
251286 pub fn hir_to_node_id ( & self , hir_id : HirId ) -> NodeId {
252287 self . hir_to_node_id [ & hir_id]
@@ -566,6 +601,12 @@ impl<'hir> Map<'hir> {
566601 self . find ( id) . unwrap_or_else ( || bug ! ( "couldn't find node id {} in the AST map" , id) )
567602 }
568603
604+ // FIXME(@ljedrz): replace the NodeId variant
605+ pub fn get_by_hir_id ( & self , id : HirId ) -> Node < ' hir > {
606+ let node_id = self . hir_to_node_id ( id) ;
607+ self . get ( node_id)
608+ }
609+
569610 pub fn get_if_local ( & self , id : DefId ) -> Option < Node < ' hir > > {
570611 self . as_local_node_id ( id) . map ( |id| self . get ( id) ) // read recorded by `get`
571612 }
@@ -613,6 +654,12 @@ impl<'hir> Map<'hir> {
613654 result
614655 }
615656
657+ // FIXME(@ljedrz): replace the NodeId variant
658+ pub fn find_by_hir_id ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
659+ let node_id = self . hir_to_node_id ( hir_id) ;
660+ self . find ( node_id)
661+ }
662+
616663 /// Similar to `get_parent`; returns the parent node-id, or own `id` if there is
617664 /// no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself
618665 /// present in the map -- so passing the return value of get_parent_node to
@@ -633,6 +680,13 @@ impl<'hir> Map<'hir> {
633680 self . find_entry ( id) . and_then ( |x| x. parent_node ( ) ) . unwrap_or ( id)
634681 }
635682
683+ // FIXME(@ljedrz): replace the NodeId variant
684+ pub fn get_parent_node_by_hir_id ( & self , id : HirId ) -> HirId {
685+ let node_id = self . hir_to_node_id ( id) ;
686+ let parent_node_id = self . get_parent_node ( node_id) ;
687+ self . node_to_hir_id ( parent_node_id)
688+ }
689+
636690 /// Check if the node is an argument. An argument is a local variable whose
637691 /// immediate parent is an item or a closure.
638692 pub fn is_argument ( & self , id : NodeId ) -> bool {
@@ -757,6 +811,13 @@ impl<'hir> Map<'hir> {
757811 }
758812 }
759813
814+ // FIXME(@ljedrz): replace the NodeId variant
815+ pub fn get_parent_item ( & self , id : HirId ) -> HirId {
816+ let node_id = self . hir_to_node_id ( id) ;
817+ let parent_node_id = self . get_parent ( node_id) ;
818+ self . node_to_hir_id ( parent_node_id)
819+ }
820+
760821 /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
761822 /// module parent is in this map.
762823 pub fn get_module_parent ( & self , id : NodeId ) -> DefId {
@@ -814,6 +875,12 @@ impl<'hir> Map<'hir> {
814875 }
815876 }
816877
878+ // FIXME(@ljedrz): replace the NodeId variant
879+ pub fn expect_item_by_hir_id ( & self , id : HirId ) -> & ' hir Item {
880+ let node_id = self . hir_to_node_id ( id) ;
881+ self . expect_item ( node_id)
882+ }
883+
817884 pub fn expect_impl_item ( & self , id : NodeId ) -> & ' hir ImplItem {
818885 match self . find ( id) {
819886 Some ( Node :: ImplItem ( item) ) => item,
@@ -960,13 +1027,28 @@ impl<'hir> Map<'hir> {
9601027 node_id_to_string ( self , id, true )
9611028 }
9621029
1030+ // FIXME(@ljedrz): replace the NodeId variant
1031+ pub fn hir_to_string ( & self , id : HirId ) -> String {
1032+ hir_id_to_string ( self , id, true )
1033+ }
1034+
9631035 pub fn node_to_user_string ( & self , id : NodeId ) -> String {
9641036 node_id_to_string ( self , id, false )
9651037 }
9661038
1039+ // FIXME(@ljedrz): replace the NodeId variant
1040+ pub fn hir_to_user_string ( & self , id : HirId ) -> String {
1041+ hir_id_to_string ( self , id, false )
1042+ }
1043+
9671044 pub fn node_to_pretty_string ( & self , id : NodeId ) -> String {
9681045 print:: to_string ( self , |s| s. print_node ( self . get ( id) ) )
9691046 }
1047+
1048+ // FIXME(@ljedrz): replace the NodeId variant
1049+ pub fn hir_to_pretty_string ( & self , id : HirId ) -> String {
1050+ print:: to_string ( self , |s| s. print_node ( self . get_by_hir_id ( id) ) )
1051+ }
9701052}
9711053
9721054pub struct NodesMatchingSuffix < ' a , ' hir : ' a > {
@@ -1310,6 +1392,12 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
13101392 }
13111393}
13121394
1395+ // FIXME(@ljedrz): replace the NodeId variant
1396+ fn hir_id_to_string ( map : & Map < ' _ > , id : HirId , include_id : bool ) -> String {
1397+ let node_id = map. hir_to_node_id ( id) ;
1398+ node_id_to_string ( map, node_id, include_id)
1399+ }
1400+
13131401pub fn describe_def ( tcx : TyCtxt < ' _ , ' _ , ' _ > , def_id : DefId ) -> Option < Def > {
13141402 if let Some ( node_id) = tcx. hir ( ) . as_local_node_id ( def_id) {
13151403 tcx. hir ( ) . describe_def ( node_id)
0 commit comments