@@ -13,7 +13,6 @@ pub use rustc_hir::definitions::{Definitions, DisambiguatedDefPathData};
1313use rustc_hir:: intravisit;
1414use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
1515use rustc_hir:: * ;
16- use rustc_hir_pretty:: Nested ;
1716use rustc_index:: vec:: IndexVec ;
1817use rustc_span:: hygiene:: MacroKind ;
1918use rustc_span:: source_map:: Spanned ;
@@ -954,20 +953,18 @@ impl<'hir> Map<'hir> {
954953 }
955954 }
956955
956+ /// Get a representation of this `id` for debugging purposes.
957+ /// NOTE: Do NOT use this in diagnostics!
957958 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)
967960 }
968961}
969962
970963impl < ' hir > intravisit:: Map < ' hir > for Map < ' hir > {
964+ fn find ( & self , hir_id : HirId ) -> Option < Node < ' hir > > {
965+ self . find ( hir_id)
966+ }
967+
971968 fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
972969 self . body ( id)
973970 }
@@ -1046,23 +1043,8 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
10461043 tcx. arena . alloc ( IndexedHir { crate_hash, map } )
10471044}
10481045
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 {
10641047 let id_str = format ! ( " (hir_id={})" , id) ;
1065- let id_str = if include_id { & id_str[ ..] } else { "" } ;
10661048
10671049 let path_str = || {
10681050 // 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 {
10831065 } )
10841066 } ;
10851067
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+
10861071 match map. find ( id) {
10871072 Some ( Node :: Item ( item) ) => {
10881073 let item_str = match item. kind {
@@ -1133,22 +1118,20 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
11331118 Some ( Node :: Field ( ref field) ) => {
11341119 format ! ( "field {} in {}{}" , field. ident, path_str( ) , id_str)
11351120 }
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" ) ,
11501133 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" ) ,
11521135 Some ( Node :: GenericParam ( ref param) ) => format ! ( "generic_param {:?}{}" , param, id_str) ,
11531136 Some ( Node :: Visibility ( ref vis) ) => format ! ( "visibility {:?}{}" , vis, id_str) ,
11541137 Some ( Node :: MacroDef ( _) ) => format ! ( "macro {}{}" , path_str( ) , id_str) ,
0 commit comments