@@ -10,7 +10,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
10
10
use rustc_hir:: definitions:: { DefKey , DefPath , Definitions } ;
11
11
use rustc_hir:: intravisit;
12
12
use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
13
- use rustc_hir:: print:: Nested ;
14
13
use rustc_hir:: * ;
15
14
use rustc_index:: vec:: IndexVec ;
16
15
use rustc_span:: hygiene:: MacroKind ;
@@ -890,20 +889,18 @@ impl<'hir> Map<'hir> {
890
889
}
891
890
}
892
891
892
+ /// Get a representation of this `id` for debugging purposes.
893
+ /// NOTE: Do NOT use this in diagnostics!
893
894
pub fn node_to_string ( & self , id : HirId ) -> String {
894
- hir_id_to_string ( self , id, true )
895
- }
896
-
897
- pub fn hir_to_user_string ( & self , id : HirId ) -> String {
898
- hir_id_to_string ( self , id, false )
899
- }
900
-
901
- pub fn hir_to_pretty_string ( & self , id : HirId ) -> String {
902
- print:: to_string ( self , |s| s. print_node ( self . get ( id) ) )
895
+ hir_id_to_string ( self , id)
903
896
}
904
897
}
905
898
906
899
impl < ' hir > intravisit:: Map < ' hir > for Map < ' hir > {
900
+ fn find ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
901
+ self . find ( hir_id)
902
+ }
903
+
907
904
fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
908
905
self . body ( id)
909
906
}
@@ -982,23 +979,8 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
982
979
tcx. arena . alloc ( IndexedHir { crate_hash, map } )
983
980
}
984
981
985
- /// Identical to the `PpAnn` implementation for `hir::Crate`,
986
- /// except it avoids creating a dependency on the whole crate.
987
- impl < ' hir > print:: PpAnn for Map < ' hir > {
988
- fn nested ( & self , state : & mut print:: State < ' _ > , nested : print:: Nested ) {
989
- match nested {
990
- Nested :: Item ( id) => state. print_item ( self . expect_item ( id. id ) ) ,
991
- Nested :: TraitItem ( id) => state. print_trait_item ( self . trait_item ( id) ) ,
992
- Nested :: ImplItem ( id) => state. print_impl_item ( self . impl_item ( id) ) ,
993
- Nested :: Body ( id) => state. print_expr ( & self . body ( id) . value ) ,
994
- Nested :: BodyParamPat ( id, i) => state. print_pat ( & self . body ( id) . params [ i] . pat ) ,
995
- }
996
- }
997
- }
998
-
999
- fn hir_id_to_string ( map : & Map < ' _ > , id : HirId , include_id : bool ) -> String {
982
+ fn hir_id_to_string ( map : & Map < ' _ > , id : HirId ) -> String {
1000
983
let id_str = format ! ( " (hir_id={})" , id) ;
1001
- let id_str = if include_id { & id_str[ ..] } else { "" } ;
1002
984
1003
985
let path_str = || {
1004
986
// This functionality is used for debugging, try to use `TyCtxt` to get
@@ -1019,6 +1001,9 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
1019
1001
} )
1020
1002
} ;
1021
1003
1004
+ let span_str = || map. tcx . sess . source_map ( ) . span_to_snippet ( map. span ( id) ) . unwrap_or_default ( ) ;
1005
+ let node_str = |prefix| format ! ( "{} {}{}" , prefix, span_str( ) , id_str) ;
1006
+
1022
1007
match map. find ( id) {
1023
1008
Some ( Node :: Item ( item) ) => {
1024
1009
let item_str = match item. kind {
@@ -1069,22 +1054,20 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
1069
1054
Some ( Node :: Field ( ref field) ) => {
1070
1055
format ! ( "field {} in {}{}" , field. ident, path_str( ) , id_str)
1071
1056
}
1072
- Some ( Node :: AnonConst ( _) ) => format ! ( "const {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1073
- Some ( Node :: Expr ( _) ) => format ! ( "expr {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1074
- Some ( Node :: Stmt ( _) ) => format ! ( "stmt {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1075
- Some ( Node :: PathSegment ( _) ) => {
1076
- format ! ( "path segment {}{}" , map. hir_to_pretty_string( id) , id_str)
1077
- }
1078
- Some ( Node :: Ty ( _) ) => format ! ( "type {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1079
- Some ( Node :: TraitRef ( _) ) => format ! ( "trait_ref {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1080
- Some ( Node :: Binding ( _) ) => format ! ( "local {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1081
- Some ( Node :: Pat ( _) ) => format ! ( "pat {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1082
- Some ( Node :: Param ( _) ) => format ! ( "param {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1083
- Some ( Node :: Arm ( _) ) => format ! ( "arm {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1084
- Some ( Node :: Block ( _) ) => format ! ( "block {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1085
- Some ( Node :: Local ( _) ) => format ! ( "local {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1057
+ Some ( Node :: AnonConst ( _) ) => node_str ( "const" ) ,
1058
+ Some ( Node :: Expr ( _) ) => node_str ( "expr" ) ,
1059
+ Some ( Node :: Stmt ( _) ) => node_str ( "stmt" ) ,
1060
+ Some ( Node :: PathSegment ( _) ) => node_str ( "path segment" ) ,
1061
+ Some ( Node :: Ty ( _) ) => node_str ( "type" ) ,
1062
+ Some ( Node :: TraitRef ( _) ) => node_str ( "trait ref" ) ,
1063
+ Some ( Node :: Binding ( _) ) => node_str ( "local" ) ,
1064
+ Some ( Node :: Pat ( _) ) => node_str ( "pat" ) ,
1065
+ Some ( Node :: Param ( _) ) => node_str ( "param" ) ,
1066
+ Some ( Node :: Arm ( _) ) => node_str ( "arm" ) ,
1067
+ Some ( Node :: Block ( _) ) => node_str ( "block" ) ,
1068
+ Some ( Node :: Local ( _) ) => node_str ( "local" ) ,
1086
1069
Some ( Node :: Ctor ( ..) ) => format ! ( "ctor {}{}" , path_str( ) , id_str) ,
1087
- Some ( Node :: Lifetime ( _) ) => format ! ( "lifetime {}{}" , map . hir_to_pretty_string ( id ) , id_str ) ,
1070
+ Some ( Node :: Lifetime ( _) ) => node_str ( "lifetime" ) ,
1088
1071
Some ( Node :: GenericParam ( ref param) ) => format ! ( "generic_param {:?}{}" , param, id_str) ,
1089
1072
Some ( Node :: Visibility ( ref vis) ) => format ! ( "visibility {:?}{}" , vis, id_str) ,
1090
1073
Some ( Node :: MacroDef ( _) ) => format ! ( "macro {}{}" , path_str( ) , id_str) ,
0 commit comments