@@ -40,6 +40,7 @@ pub const REGULAR_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High;
40
40
#[ derive( Copy , Clone , Debug ) ]
41
41
pub struct Entry < ' hir > {
42
42
parent : NodeId ,
43
+ parent_hir : HirId ,
43
44
dep_node : DepNodeIndex ,
44
45
node : Node < ' hir > ,
45
46
}
@@ -208,6 +209,12 @@ impl<'hir> Map<'hir> {
208
209
}
209
210
}
210
211
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
+
211
218
#[ inline]
212
219
pub fn definitions ( & self ) -> & ' hir Definitions {
213
220
self . definitions
@@ -224,6 +231,11 @@ impl<'hir> Map<'hir> {
224
231
} )
225
232
}
226
233
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
+
227
239
pub fn def_path ( & self , def_id : DefId ) -> DefPath {
228
240
assert ! ( def_id. is_local( ) ) ;
229
241
self . definitions . def_path ( def_id. index )
@@ -237,6 +249,23 @@ impl<'hir> Map<'hir> {
237
249
} )
238
250
}
239
251
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
+
240
269
#[ inline]
241
270
pub fn opt_local_def_id ( & self , node : NodeId ) -> Option < DefId > {
242
271
self . definitions . opt_local_def_id ( node)
@@ -247,6 +276,12 @@ impl<'hir> Map<'hir> {
247
276
self . definitions . as_local_node_id ( def_id)
248
277
}
249
278
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
+
250
285
#[ inline]
251
286
pub fn hir_to_node_id ( & self , hir_id : HirId ) -> NodeId {
252
287
self . hir_to_node_id [ & hir_id]
@@ -566,6 +601,12 @@ impl<'hir> Map<'hir> {
566
601
self . find ( id) . unwrap_or_else ( || bug ! ( "couldn't find node id {} in the AST map" , id) )
567
602
}
568
603
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
+
569
610
pub fn get_if_local ( & self , id : DefId ) -> Option < Node < ' hir > > {
570
611
self . as_local_node_id ( id) . map ( |id| self . get ( id) ) // read recorded by `get`
571
612
}
@@ -613,6 +654,12 @@ impl<'hir> Map<'hir> {
613
654
result
614
655
}
615
656
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
+
616
663
/// Similar to `get_parent`; returns the parent node-id, or own `id` if there is
617
664
/// no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself
618
665
/// present in the map -- so passing the return value of get_parent_node to
@@ -633,6 +680,13 @@ impl<'hir> Map<'hir> {
633
680
self . find_entry ( id) . and_then ( |x| x. parent_node ( ) ) . unwrap_or ( id)
634
681
}
635
682
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
+
636
690
/// Check if the node is an argument. An argument is a local variable whose
637
691
/// immediate parent is an item or a closure.
638
692
pub fn is_argument ( & self , id : NodeId ) -> bool {
@@ -757,6 +811,13 @@ impl<'hir> Map<'hir> {
757
811
}
758
812
}
759
813
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
+
760
821
/// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
761
822
/// module parent is in this map.
762
823
pub fn get_module_parent ( & self , id : NodeId ) -> DefId {
@@ -814,6 +875,12 @@ impl<'hir> Map<'hir> {
814
875
}
815
876
}
816
877
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
+
817
884
pub fn expect_impl_item ( & self , id : NodeId ) -> & ' hir ImplItem {
818
885
match self . find ( id) {
819
886
Some ( Node :: ImplItem ( item) ) => item,
@@ -960,13 +1027,28 @@ impl<'hir> Map<'hir> {
960
1027
node_id_to_string ( self , id, true )
961
1028
}
962
1029
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
+
963
1035
pub fn node_to_user_string ( & self , id : NodeId ) -> String {
964
1036
node_id_to_string ( self , id, false )
965
1037
}
966
1038
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
+
967
1044
pub fn node_to_pretty_string ( & self , id : NodeId ) -> String {
968
1045
print:: to_string ( self , |s| s. print_node ( self . get ( id) ) )
969
1046
}
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
+ }
970
1052
}
971
1053
972
1054
pub struct NodesMatchingSuffix < ' a , ' hir : ' a > {
@@ -1310,6 +1392,12 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
1310
1392
}
1311
1393
}
1312
1394
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
+
1313
1401
pub fn describe_def ( tcx : TyCtxt < ' _ , ' _ , ' _ > , def_id : DefId ) -> Option < Def > {
1314
1402
if let Some ( node_id) = tcx. hir ( ) . as_local_node_id ( def_id) {
1315
1403
tcx. hir ( ) . describe_def ( node_id)
0 commit comments