@@ -290,7 +290,7 @@ impl<'hir> Map<'hir> {
290
290
#[ track_caller]
291
291
pub fn parent_id ( self , hir_id : HirId ) -> HirId {
292
292
self . opt_parent_id ( hir_id)
293
- . unwrap_or_else ( || bug ! ( "No parent for node {:? }" , self . node_to_string( hir_id) ) )
293
+ . unwrap_or_else ( || bug ! ( "No parent for node {}" , self . node_to_string( hir_id) ) )
294
294
}
295
295
296
296
pub fn get_parent ( self , hir_id : HirId ) -> Node < ' hir > {
@@ -1191,12 +1191,10 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
1191
1191
}
1192
1192
1193
1193
fn hir_id_to_string ( map : Map < ' _ > , id : HirId ) -> String {
1194
- let id_str = format ! ( " (hir_id={})" , id) ;
1195
-
1196
1194
let path_str = |def_id : LocalDefId | map. tcx . def_path_str ( def_id. to_def_id ( ) ) ;
1197
1195
1198
1196
let span_str = || map. tcx . sess . source_map ( ) . span_to_snippet ( map. span ( id) ) . unwrap_or_default ( ) ;
1199
- let node_str = |prefix| format ! ( "{} {}{} " , prefix , span_str( ) , id_str ) ;
1197
+ let node_str = |prefix| format ! ( "{id} ({prefix} `{}`) " , span_str( ) ) ;
1200
1198
1201
1199
match map. find ( id) {
1202
1200
Some ( Node :: Item ( item) ) => {
@@ -1225,18 +1223,18 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
1225
1223
ItemKind :: TraitAlias ( ..) => "trait alias" ,
1226
1224
ItemKind :: Impl { .. } => "impl" ,
1227
1225
} ;
1228
- format ! ( "{} {}{} " , item_str , path_str( item. owner_id. def_id) , id_str )
1226
+ format ! ( "{id} ({item_str} {}) " , path_str( item. owner_id. def_id) )
1229
1227
}
1230
1228
Some ( Node :: ForeignItem ( item) ) => {
1231
- format ! ( "foreign item {}{} " , path_str( item. owner_id. def_id) , id_str )
1229
+ format ! ( "{id} ( foreign item {}) " , path_str( item. owner_id. def_id) )
1232
1230
}
1233
1231
Some ( Node :: ImplItem ( ii) ) => {
1234
1232
let kind = match ii. kind {
1235
1233
ImplItemKind :: Const ( ..) => "assoc const" ,
1236
1234
ImplItemKind :: Fn ( ..) => "method" ,
1237
1235
ImplItemKind :: Type ( _) => "assoc type" ,
1238
1236
} ;
1239
- format ! ( "{} {} in {}{} " , kind , ii. ident, path_str( ii. owner_id. def_id) , id_str )
1237
+ format ! ( "{id} ({kind} `{}` in {}) " , ii. ident, path_str( ii. owner_id. def_id) )
1240
1238
}
1241
1239
Some ( Node :: TraitItem ( ti) ) => {
1242
1240
let kind = match ti. kind {
@@ -1245,13 +1243,13 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
1245
1243
TraitItemKind :: Type ( ..) => "assoc type" ,
1246
1244
} ;
1247
1245
1248
- format ! ( "{} {} in {}{} " , kind , ti. ident, path_str( ti. owner_id. def_id) , id_str )
1246
+ format ! ( "{id} ({kind} `{}` in {}) " , ti. ident, path_str( ti. owner_id. def_id) )
1249
1247
}
1250
1248
Some ( Node :: Variant ( ref variant) ) => {
1251
- format ! ( "variant {} in {}{} " , variant. ident, path_str( variant. def_id) , id_str )
1249
+ format ! ( "{id} ( variant `{}` in {}) " , variant. ident, path_str( variant. def_id) )
1252
1250
}
1253
1251
Some ( Node :: Field ( ref field) ) => {
1254
- format ! ( "field {} in {}{} " , field. ident, path_str( field. def_id) , id_str )
1252
+ format ! ( "{id} ( field `{}` in {}) " , field. ident, path_str( field. def_id) )
1255
1253
}
1256
1254
Some ( Node :: AnonConst ( _) ) => node_str ( "const" ) ,
1257
1255
Some ( Node :: Expr ( _) ) => node_str ( "expr" ) ,
@@ -1269,16 +1267,15 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
1269
1267
Some ( Node :: Infer ( _) ) => node_str ( "infer" ) ,
1270
1268
Some ( Node :: Local ( _) ) => node_str ( "local" ) ,
1271
1269
Some ( Node :: Ctor ( ctor) ) => format ! (
1272
- "ctor {}{} " ,
1270
+ "{id} ( ctor {}) " ,
1273
1271
ctor. ctor_def_id( ) . map_or( "<missing path>" . into( ) , |def_id| path_str( def_id) ) ,
1274
- id_str
1275
1272
) ,
1276
1273
Some ( Node :: Lifetime ( _) ) => node_str ( "lifetime" ) ,
1277
1274
Some ( Node :: GenericParam ( ref param) ) => {
1278
- format ! ( "generic_param {}{} " , path_str( param. def_id) , id_str )
1275
+ format ! ( "{id} ( generic_param {}) " , path_str( param. def_id) )
1279
1276
}
1280
- Some ( Node :: Crate ( ..) ) => String :: from ( "root_crate" ) ,
1281
- None => format ! ( "unknown node{}" , id_str ) ,
1277
+ Some ( Node :: Crate ( ..) ) => String :: from ( "( root_crate) " ) ,
1278
+ None => format ! ( "{id} ( unknown node)" ) ,
1282
1279
}
1283
1280
}
1284
1281
0 commit comments