@@ -1198,20 +1198,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
1198
1198
fn hir_id_to_string ( map : Map < ' _ > , id : HirId ) -> String {
1199
1199
let id_str = format ! ( " (hir_id={})" , id) ;
1200
1200
1201
- let path_str = || {
1202
- // This functionality is used for debugging, try to use `TyCtxt` to get
1203
- // the user-friendly path, otherwise fall back to stringifying `DefPath`.
1204
- crate :: ty:: tls:: with_opt ( |tcx| {
1205
- if let Some ( tcx) = tcx {
1206
- let def_id = map. local_def_id ( id) ;
1207
- tcx. def_path_str ( def_id. to_def_id ( ) )
1208
- } else if let Some ( path) = map. def_path_from_hir_id ( id) {
1209
- path. data . into_iter ( ) . map ( |elem| elem. to_string ( ) ) . collect :: < Vec < _ > > ( ) . join ( "::" )
1210
- } else {
1211
- String :: from ( "<missing path>" )
1212
- }
1213
- } )
1214
- } ;
1201
+ let path_str = |def_id : LocalDefId | map. tcx . def_path_str ( def_id. to_def_id ( ) ) ;
1215
1202
1216
1203
let span_str = || map. tcx . sess . source_map ( ) . span_to_snippet ( map. span ( id) ) . unwrap_or_default ( ) ;
1217
1204
let node_str = |prefix| format ! ( "{} {}{}" , prefix, span_str( ) , id_str) ;
@@ -1243,32 +1230,33 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
1243
1230
ItemKind :: TraitAlias ( ..) => "trait alias" ,
1244
1231
ItemKind :: Impl { .. } => "impl" ,
1245
1232
} ;
1246
- format ! ( "{} {}{}" , item_str, path_str( ) , id_str)
1233
+ format ! ( "{} {}{}" , item_str, path_str( item. owner_id. def_id) , id_str)
1234
+ }
1235
+ Some ( Node :: ForeignItem ( item) ) => {
1236
+ format ! ( "foreign item {}{}" , path_str( item. owner_id. def_id) , id_str)
1237
+ }
1238
+ Some ( Node :: ImplItem ( ii) ) => {
1239
+ let kind = match ii. kind {
1240
+ ImplItemKind :: Const ( ..) => "assoc const" ,
1241
+ ImplItemKind :: Fn ( ..) => "method" ,
1242
+ ImplItemKind :: Type ( _) => "assoc type" ,
1243
+ } ;
1244
+ format ! ( "{} {} in {}{}" , kind, ii. ident, path_str( ii. owner_id. def_id) , id_str)
1247
1245
}
1248
- Some ( Node :: ForeignItem ( _) ) => format ! ( "foreign item {}{}" , path_str( ) , id_str) ,
1249
- Some ( Node :: ImplItem ( ii) ) => match ii. kind {
1250
- ImplItemKind :: Const ( ..) => {
1251
- format ! ( "assoc const {} in {}{}" , ii. ident, path_str( ) , id_str)
1252
- }
1253
- ImplItemKind :: Fn ( ..) => format ! ( "method {} in {}{}" , ii. ident, path_str( ) , id_str) ,
1254
- ImplItemKind :: Type ( _) => {
1255
- format ! ( "assoc type {} in {}{}" , ii. ident, path_str( ) , id_str)
1256
- }
1257
- } ,
1258
1246
Some ( Node :: TraitItem ( ti) ) => {
1259
1247
let kind = match ti. kind {
1260
1248
TraitItemKind :: Const ( ..) => "assoc constant" ,
1261
1249
TraitItemKind :: Fn ( ..) => "trait method" ,
1262
1250
TraitItemKind :: Type ( ..) => "assoc type" ,
1263
1251
} ;
1264
1252
1265
- format ! ( "{} {} in {}{}" , kind, ti. ident, path_str( ) , id_str)
1253
+ format ! ( "{} {} in {}{}" , kind, ti. ident, path_str( ti . owner_id . def_id ) , id_str)
1266
1254
}
1267
1255
Some ( Node :: Variant ( ref variant) ) => {
1268
- format ! ( "variant {} in {}{}" , variant. ident, path_str( ) , id_str)
1256
+ format ! ( "variant {} in {}{}" , variant. ident, path_str( variant . def_id ) , id_str)
1269
1257
}
1270
1258
Some ( Node :: Field ( ref field) ) => {
1271
- format ! ( "field {} in {}{}" , field. ident, path_str( ) , id_str)
1259
+ format ! ( "field {} in {}{}" , field. ident, path_str( field . def_id ) , id_str)
1272
1260
}
1273
1261
Some ( Node :: AnonConst ( _) ) => node_str ( "const" ) ,
1274
1262
Some ( Node :: Expr ( _) ) => node_str ( "expr" ) ,
@@ -1285,9 +1273,15 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
1285
1273
Some ( Node :: Block ( _) ) => node_str ( "block" ) ,
1286
1274
Some ( Node :: Infer ( _) ) => node_str ( "infer" ) ,
1287
1275
Some ( Node :: Local ( _) ) => node_str ( "local" ) ,
1288
- Some ( Node :: Ctor ( ..) ) => format ! ( "ctor {}{}" , path_str( ) , id_str) ,
1276
+ Some ( Node :: Ctor ( ctor) ) => format ! (
1277
+ "ctor {}{}" ,
1278
+ ctor. ctor_def_id( ) . map_or( "<missing path>" . into( ) , |def_id| path_str( def_id) ) ,
1279
+ id_str
1280
+ ) ,
1289
1281
Some ( Node :: Lifetime ( _) ) => node_str ( "lifetime" ) ,
1290
- Some ( Node :: GenericParam ( ref param) ) => format ! ( "generic_param {:?}{}" , param, id_str) ,
1282
+ Some ( Node :: GenericParam ( ref param) ) => {
1283
+ format ! ( "generic_param {}{}" , path_str( param. def_id) , id_str)
1284
+ }
1291
1285
Some ( Node :: Crate ( ..) ) => String :: from ( "root_crate" ) ,
1292
1286
None => format ! ( "unknown node{}" , id_str) ,
1293
1287
}
0 commit comments