@@ -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,22 @@ 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
+ 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
+
240
268
#[ inline]
241
269
pub fn opt_local_def_id ( & self , node : NodeId ) -> Option < DefId > {
242
270
self . definitions . opt_local_def_id ( node)
@@ -247,6 +275,12 @@ impl<'hir> Map<'hir> {
247
275
self . definitions . as_local_node_id ( def_id)
248
276
}
249
277
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
+
250
284
#[ inline]
251
285
pub fn hir_to_node_id ( & self , hir_id : HirId ) -> NodeId {
252
286
self . hir_to_node_id [ & hir_id]
@@ -566,6 +600,12 @@ impl<'hir> Map<'hir> {
566
600
self . find ( id) . unwrap_or_else ( || bug ! ( "couldn't find node id {} in the AST map" , id) )
567
601
}
568
602
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
+
569
609
pub fn get_if_local ( & self , id : DefId ) -> Option < Node < ' hir > > {
570
610
self . as_local_node_id ( id) . map ( |id| self . get ( id) ) // read recorded by `get`
571
611
}
@@ -613,6 +653,12 @@ impl<'hir> Map<'hir> {
613
653
result
614
654
}
615
655
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
+
616
662
/// Similar to `get_parent`; returns the parent node-id, or own `id` if there is
617
663
/// no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself
618
664
/// present in the map -- so passing the return value of get_parent_node to
@@ -633,6 +679,13 @@ impl<'hir> Map<'hir> {
633
679
self . find_entry ( id) . and_then ( |x| x. parent_node ( ) ) . unwrap_or ( id)
634
680
}
635
681
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
+
636
689
/// Check if the node is an argument. An argument is a local variable whose
637
690
/// immediate parent is an item or a closure.
638
691
pub fn is_argument ( & self , id : NodeId ) -> bool {
@@ -757,6 +810,13 @@ impl<'hir> Map<'hir> {
757
810
}
758
811
}
759
812
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
+
760
820
/// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
761
821
/// module parent is in this map.
762
822
pub fn get_module_parent ( & self , id : NodeId ) -> DefId {
@@ -814,6 +874,12 @@ impl<'hir> Map<'hir> {
814
874
}
815
875
}
816
876
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
+
817
883
pub fn expect_impl_item ( & self , id : NodeId ) -> & ' hir ImplItem {
818
884
match self . find ( id) {
819
885
Some ( Node :: ImplItem ( item) ) => item,
@@ -960,13 +1026,28 @@ impl<'hir> Map<'hir> {
960
1026
node_id_to_string ( self , id, true )
961
1027
}
962
1028
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
+
963
1034
pub fn node_to_user_string ( & self , id : NodeId ) -> String {
964
1035
node_id_to_string ( self , id, false )
965
1036
}
966
1037
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
+
967
1043
pub fn node_to_pretty_string ( & self , id : NodeId ) -> String {
968
1044
print:: to_string ( self , |s| s. print_node ( self . get ( id) ) )
969
1045
}
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
+ }
970
1051
}
971
1052
972
1053
pub struct NodesMatchingSuffix < ' a , ' hir : ' a > {
@@ -1310,6 +1391,12 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
1310
1391
}
1311
1392
}
1312
1393
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
+
1313
1400
pub fn describe_def ( tcx : TyCtxt < ' _ , ' _ , ' _ > , def_id : DefId ) -> Option < Def > {
1314
1401
if let Some ( node_id) = tcx. hir ( ) . as_local_node_id ( def_id) {
1315
1402
tcx. hir ( ) . describe_def ( node_id)
0 commit comments