@@ -292,7 +292,7 @@ impl<'hir> Map<'hir> {
292
292
}
293
293
294
294
fn def_kind ( & self , hir_id : HirId ) -> Option < DefKind > {
295
- let node = if let Some ( node) = self . find_by_hir_id ( hir_id) {
295
+ let node = if let Some ( node) = self . find ( hir_id) {
296
296
node
297
297
} else {
298
298
return None
@@ -347,7 +347,7 @@ impl<'hir> Map<'hir> {
347
347
if variant_data. ctor_hir_id ( ) . is_none ( ) {
348
348
return None ;
349
349
}
350
- let ctor_of = match self . find_by_hir_id ( self . get_parent_node_by_hir_id ( hir_id) ) {
350
+ let ctor_of = match self . find ( self . get_parent_node ( hir_id) ) {
351
351
Some ( Node :: Item ( ..) ) => def:: CtorOf :: Struct ,
352
352
Some ( Node :: Variant ( ..) ) => def:: CtorOf :: Variant ,
353
353
_ => unreachable ! ( ) ,
@@ -424,7 +424,7 @@ impl<'hir> Map<'hir> {
424
424
/// which this is the body of, i.e., a `fn`, `const` or `static`
425
425
/// item (possibly associated), a closure, or a `hir::AnonConst`.
426
426
pub fn body_owner ( & self , BodyId { hir_id } : BodyId ) -> HirId {
427
- let parent = self . get_parent_node_by_hir_id ( hir_id) ;
427
+ let parent = self . get_parent_node ( hir_id) ;
428
428
assert ! ( self . lookup( parent) . map_or( false , |e| e. is_body_owner( hir_id) ) ) ;
429
429
parent
430
430
}
@@ -485,7 +485,7 @@ impl<'hir> Map<'hir> {
485
485
match self . get ( id) {
486
486
Node :: Item ( & Item { node : ItemKind :: Trait ( ..) , .. } ) |
487
487
Node :: Item ( & Item { node : ItemKind :: TraitAlias ( ..) , .. } ) => id,
488
- Node :: GenericParam ( _) => self . get_parent_node_by_hir_id ( id) ,
488
+ Node :: GenericParam ( _) => self . get_parent_node ( id) ,
489
489
_ => bug ! ( "ty_param_owner: {} not a type parameter" , self . node_to_string( id) )
490
490
}
491
491
}
@@ -563,7 +563,7 @@ impl<'hir> Map<'hir> {
563
563
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
564
564
pub fn get ( & self , id : HirId ) -> Node < ' hir > {
565
565
// read recorded by `find`
566
- self . find_by_hir_id ( id) . unwrap_or_else ( ||
566
+ self . find ( id) . unwrap_or_else ( ||
567
567
bug ! ( "couldn't find hir id {} in the HIR map" , id) )
568
568
}
569
569
@@ -595,13 +595,7 @@ impl<'hir> Map<'hir> {
595
595
}
596
596
597
597
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
598
- pub fn find ( & self , id : NodeId ) -> Option < Node < ' hir > > {
599
- let hir_id = self . node_to_hir_id ( id) ;
600
- self . find_by_hir_id ( hir_id)
601
- }
602
-
603
- // FIXME(@ljedrz): replace the `NodeId` variant.
604
- pub fn find_by_hir_id ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
598
+ pub fn find ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
605
599
let result = self . find_entry ( hir_id) . and_then ( |entry| {
606
600
if let Node :: Crate = entry. node {
607
601
None
@@ -615,24 +609,17 @@ impl<'hir> Map<'hir> {
615
609
result
616
610
}
617
611
618
- /// Similar to `get_parent`; returns the parent node-ID , or just `hir_id` if there
619
- /// is no parent. Note that the parent may be `CRATE_NODE_ID `, which is not itself
612
+ /// Similar to `get_parent`; returns the parent HIR Id , or just `hir_id` if there
613
+ /// is no parent. Note that the parent may be `CRATE_HIR_ID `, which is not itself
620
614
/// present in the map, so passing the return value of `get_parent_node` to
621
615
/// `get` may in fact panic.
622
- /// This function returns the immediate parent in the AST , whereas `get_parent`
616
+ /// This function returns the immediate parent in the HIR , whereas `get_parent`
623
617
/// returns the enclosing item. Note that this might not be the actual parent
624
- /// node in the AST -- some kinds of nodes are not in the map and these will
618
+ /// node in the HIR -- some kinds of nodes are not in the map and these will
625
619
/// never appear as the parent node. Thus, you can always walk the parent nodes
626
- /// from a node to the root of the AST (unless you get back the same ID here,
620
+ /// from a node to the root of the HIR (unless you get back the same ID here,
627
621
/// which can happen if the ID is not in the map itself or is just weird).
628
- pub fn get_parent_node ( & self , id : NodeId ) -> NodeId {
629
- let hir_id = self . node_to_hir_id ( id) ;
630
- let parent_hir_id = self . get_parent_node_by_hir_id ( hir_id) ;
631
- self . hir_to_node_id ( parent_hir_id)
632
- }
633
-
634
- // FIXME(@ljedrz): replace the `NodeId` variant.
635
- pub fn get_parent_node_by_hir_id ( & self , hir_id : HirId ) -> HirId {
622
+ pub fn get_parent_node ( & self , hir_id : HirId ) -> HirId {
636
623
if self . dep_graph . is_fully_enabled ( ) {
637
624
let hir_id_owner = hir_id. owner ;
638
625
let def_path_hash = self . definitions . def_path_hash ( hir_id_owner) ;
@@ -646,7 +633,7 @@ impl<'hir> Map<'hir> {
646
633
647
634
/// Check if the node is an argument. An argument is a local variable whose
648
635
/// immediate parent is an item or a closure.
649
- pub fn is_argument ( & self , id : NodeId ) -> bool {
636
+ pub fn is_argument ( & self , id : HirId ) -> bool {
650
637
match self . find ( id) {
651
638
Some ( Node :: Binding ( _) ) => ( ) ,
652
639
_ => return false ,
@@ -687,7 +674,7 @@ impl<'hir> Map<'hir> {
687
674
{
688
675
let mut id = start_id;
689
676
loop {
690
- let parent_id = self . get_parent_node_by_hir_id ( id) ;
677
+ let parent_id = self . get_parent_node ( id) ;
691
678
if parent_id == CRATE_HIR_ID {
692
679
return Ok ( CRATE_HIR_ID ) ;
693
680
}
@@ -872,28 +859,28 @@ impl<'hir> Map<'hir> {
872
859
}
873
860
874
861
pub fn expect_item ( & self , id : HirId ) -> & ' hir Item {
875
- match self . find_by_hir_id ( id) { // read recorded by `find`
862
+ match self . find ( id) { // read recorded by `find`
876
863
Some ( Node :: Item ( item) ) => item,
877
864
_ => bug ! ( "expected item, found {}" , self . node_to_string( id) )
878
865
}
879
866
}
880
867
881
868
pub fn expect_impl_item ( & self , id : HirId ) -> & ' hir ImplItem {
882
- match self . find_by_hir_id ( id) {
869
+ match self . find ( id) {
883
870
Some ( Node :: ImplItem ( item) ) => item,
884
871
_ => bug ! ( "expected impl item, found {}" , self . node_to_string( id) )
885
872
}
886
873
}
887
874
888
875
pub fn expect_trait_item ( & self , id : HirId ) -> & ' hir TraitItem {
889
- match self . find_by_hir_id ( id) {
876
+ match self . find ( id) {
890
877
Some ( Node :: TraitItem ( item) ) => item,
891
878
_ => bug ! ( "expected trait item, found {}" , self . node_to_string( id) )
892
879
}
893
880
}
894
881
895
882
pub fn expect_variant_data ( & self , id : HirId ) -> & ' hir VariantData {
896
- match self . find_by_hir_id ( id) {
883
+ match self . find ( id) {
897
884
Some ( Node :: Item ( i) ) => {
898
885
match i. node {
899
886
ItemKind :: Struct ( ref struct_def, _) |
@@ -908,21 +895,21 @@ impl<'hir> Map<'hir> {
908
895
}
909
896
910
897
pub fn expect_variant ( & self , id : HirId ) -> & ' hir Variant {
911
- match self . find_by_hir_id ( id) {
898
+ match self . find ( id) {
912
899
Some ( Node :: Variant ( variant) ) => variant,
913
900
_ => bug ! ( "expected variant, found {}" , self . node_to_string( id) ) ,
914
901
}
915
902
}
916
903
917
904
pub fn expect_foreign_item ( & self , id : HirId ) -> & ' hir ForeignItem {
918
- match self . find_by_hir_id ( id) {
905
+ match self . find ( id) {
919
906
Some ( Node :: ForeignItem ( item) ) => item,
920
907
_ => bug ! ( "expected foreign item, found {}" , self . node_to_string( id) )
921
908
}
922
909
}
923
910
924
911
pub fn expect_expr ( & self , id : HirId ) -> & ' hir Expr {
925
- match self . find_by_hir_id ( id) { // read recorded by find
912
+ match self . find ( id) { // read recorded by find
926
913
Some ( Node :: Expr ( expr) ) => expr,
927
914
_ => bug ! ( "expected expr, found {}" , self . node_to_string( id) )
928
915
}
@@ -1028,8 +1015,8 @@ impl<'hir> Map<'hir> {
1028
1015
Some ( Node :: Pat ( pat) ) => pat. span ,
1029
1016
Some ( Node :: Arm ( arm) ) => arm. span ,
1030
1017
Some ( Node :: Block ( block) ) => block. span ,
1031
- Some ( Node :: Ctor ( ..) ) => match self . find_by_hir_id (
1032
- self . get_parent_node_by_hir_id ( hir_id) )
1018
+ Some ( Node :: Ctor ( ..) ) => match self . find (
1019
+ self . get_parent_node ( hir_id) )
1033
1020
{
1034
1021
Some ( Node :: Item ( item) ) => item. span ,
1035
1022
Some ( Node :: Variant ( variant) ) => variant. span ,
@@ -1100,7 +1087,7 @@ impl<'a> NodesMatchingSuffix<'a> {
1100
1087
// chain, then returns `None`.
1101
1088
fn find_first_mod_parent < ' a > ( map : & ' a Map < ' _ > , mut id : HirId ) -> Option < ( HirId , Name ) > {
1102
1089
loop {
1103
- if let Node :: Item ( item) = map. find_by_hir_id ( id) ? {
1090
+ if let Node :: Item ( item) = map. find ( id) ? {
1104
1091
if item_is_mod ( & item) {
1105
1092
return Some ( ( id, item. ident . name ) )
1106
1093
}
@@ -1273,7 +1260,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
1273
1260
} )
1274
1261
} ;
1275
1262
1276
- match map. find_by_hir_id ( id) {
1263
+ match map. find ( id) {
1277
1264
Some ( Node :: Item ( item) ) => {
1278
1265
let item_str = match item. node {
1279
1266
ItemKind :: ExternCrate ( ..) => "extern crate" ,
0 commit comments