@@ -13,7 +13,6 @@ pub use rustc_hir::definitions::{Definitions, DisambiguatedDefPathData};
13
13
use rustc_hir:: intravisit;
14
14
use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
15
15
use rustc_hir:: * ;
16
- use rustc_hir_pretty:: Nested ;
17
16
use rustc_index:: vec:: IndexVec ;
18
17
use rustc_span:: hygiene:: MacroKind ;
19
18
use rustc_span:: source_map:: Spanned ;
@@ -954,20 +953,18 @@ impl<'hir> Map<'hir> {
954
953
}
955
954
}
956
955
956
+ /// Get a representation of this `id` for debugging purposes.
957
+ /// NOTE: Do NOT use this in diagnostics!
957
958
pub fn node_to_string ( & self , id : HirId ) -> String {
958
- hir_id_to_string ( self , id, true )
959
- }
960
-
961
- pub fn hir_to_user_string ( & self , id : HirId ) -> String {
962
- hir_id_to_string ( self , id, false )
963
- }
964
-
965
- pub fn hir_to_pretty_string ( & self , id : HirId ) -> String {
966
- rustc_hir_pretty:: to_string ( self , |s| s. print_node ( self . get ( id) ) )
959
+ hir_id_to_string ( self , id)
967
960
}
968
961
}
969
962
970
963
impl < ' hir > intravisit:: Map < ' hir > for Map < ' hir > {
964
+ fn find ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
965
+ self . find ( hir_id)
966
+ }
967
+
971
968
fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
972
969
self . body ( id)
973
970
}
@@ -1046,23 +1043,8 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
1046
1043
tcx. arena . alloc ( IndexedHir { crate_hash, map } )
1047
1044
}
1048
1045
1049
- /// Identical to the `PpAnn` implementation for `hir::Crate`,
1050
- /// except it avoids creating a dependency on the whole crate.
1051
- impl < ' hir > rustc_hir_pretty:: PpAnn for Map < ' hir > {
1052
- fn nested ( & self , state : & mut rustc_hir_pretty:: State < ' _ > , nested : rustc_hir_pretty:: Nested ) {
1053
- match nested {
1054
- Nested :: Item ( id) => state. print_item ( self . expect_item ( id. id ) ) ,
1055
- Nested :: TraitItem ( id) => state. print_trait_item ( self . trait_item ( id) ) ,
1056
- Nested :: ImplItem ( id) => state. print_impl_item ( self . impl_item ( id) ) ,
1057
- Nested :: Body ( id) => state. print_expr ( & self . body ( id) . value ) ,
1058
- Nested :: BodyParamPat ( id, i) => state. print_pat ( & self . body ( id) . params [ i] . pat ) ,
1059
- }
1060
- }
1061
- }
1062
-
1063
- fn hir_id_to_string ( map : & Map < ' _ > , id : HirId , include_id : bool ) -> String {
1046
+ fn hir_id_to_string ( map : & Map < ' _ > , id : HirId ) -> String {
1064
1047
let id_str = format ! ( " (hir_id={})" , id) ;
1065
- let id_str = if include_id { & id_str[ ..] } else { "" } ;
1066
1048
1067
1049
let path_str = || {
1068
1050
// This functionality is used for debugging, try to use `TyCtxt` to get
@@ -1083,6 +1065,9 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
1083
1065
} )
1084
1066
} ;
1085
1067
1068
+ let span_str = || map. tcx . sess . source_map ( ) . span_to_snippet ( map. span ( id) ) . unwrap_or_default ( ) ;
1069
+ let node_str = |prefix| format ! ( "{} {}{}" , prefix, span_str( ) , id_str) ;
1070
+
1086
1071
match map. find ( id) {
1087
1072
Some ( Node :: Item ( item) ) => {
1088
1073
let item_str = match item. kind {
@@ -1133,22 +1118,20 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
1133
1118
Some ( Node :: Field ( ref field) ) => {
1134
1119
format ! ( "field {} in {}{}" , field. ident, path_str( ) , id_str)
1135
1120
}
1136
- Some ( Node :: AnonConst ( _) ) => format ! ( "const {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1137
- Some ( Node :: Expr ( _) ) => format ! ( "expr {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1138
- Some ( Node :: Stmt ( _) ) => format ! ( "stmt {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1139
- Some ( Node :: PathSegment ( _) ) => {
1140
- format ! ( "path segment {}{}" , map. hir_to_pretty_string( id) , id_str)
1141
- }
1142
- Some ( Node :: Ty ( _) ) => format ! ( "type {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1143
- Some ( Node :: TraitRef ( _) ) => format ! ( "trait_ref {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1144
- Some ( Node :: Binding ( _) ) => format ! ( "local {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1145
- Some ( Node :: Pat ( _) ) => format ! ( "pat {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1146
- Some ( Node :: Param ( _) ) => format ! ( "param {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1147
- Some ( Node :: Arm ( _) ) => format ! ( "arm {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1148
- Some ( Node :: Block ( _) ) => format ! ( "block {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1149
- Some ( Node :: Local ( _) ) => format ! ( "local {}{}" , map. hir_to_pretty_string( id) , id_str) ,
1121
+ Some ( Node :: AnonConst ( _) ) => node_str ( "const" ) ,
1122
+ Some ( Node :: Expr ( _) ) => node_str ( "expr" ) ,
1123
+ Some ( Node :: Stmt ( _) ) => node_str ( "stmt" ) ,
1124
+ Some ( Node :: PathSegment ( _) ) => node_str ( "path segment" ) ,
1125
+ Some ( Node :: Ty ( _) ) => node_str ( "type" ) ,
1126
+ Some ( Node :: TraitRef ( _) ) => node_str ( "trait ref" ) ,
1127
+ Some ( Node :: Binding ( _) ) => node_str ( "local" ) ,
1128
+ Some ( Node :: Pat ( _) ) => node_str ( "pat" ) ,
1129
+ Some ( Node :: Param ( _) ) => node_str ( "param" ) ,
1130
+ Some ( Node :: Arm ( _) ) => node_str ( "arm" ) ,
1131
+ Some ( Node :: Block ( _) ) => node_str ( "block" ) ,
1132
+ Some ( Node :: Local ( _) ) => node_str ( "local" ) ,
1150
1133
Some ( Node :: Ctor ( ..) ) => format ! ( "ctor {}{}" , path_str( ) , id_str) ,
1151
- Some ( Node :: Lifetime ( _) ) => format ! ( "lifetime {}{}" , map . hir_to_pretty_string ( id ) , id_str ) ,
1134
+ Some ( Node :: Lifetime ( _) ) => node_str ( "lifetime" ) ,
1152
1135
Some ( Node :: GenericParam ( ref param) ) => format ! ( "generic_param {:?}{}" , param, id_str) ,
1153
1136
Some ( Node :: Visibility ( ref vis) ) => format ! ( "visibility {:?}{}" , vis, id_str) ,
1154
1137
Some ( Node :: MacroDef ( _) ) => format ! ( "macro {}{}" , path_str( ) , id_str) ,
0 commit comments