@@ -1198,20 +1198,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
11981198fn hir_id_to_string ( map : Map < ' _ > , id : HirId ) -> String {
11991199 let id_str = format ! ( " (hir_id={})" , id) ;
12001200
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 ( ) ) ;
12151202
12161203 let span_str = || map. tcx . sess . source_map ( ) . span_to_snippet ( map. span ( id) ) . unwrap_or_default ( ) ;
12171204 let node_str = |prefix| format ! ( "{} {}{}" , prefix, span_str( ) , id_str) ;
@@ -1243,32 +1230,33 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12431230 ItemKind :: TraitAlias ( ..) => "trait alias" ,
12441231 ItemKind :: Impl { .. } => "impl" ,
12451232 } ;
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)
12471245 }
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- } ,
12581246 Some ( Node :: TraitItem ( ti) ) => {
12591247 let kind = match ti. kind {
12601248 TraitItemKind :: Const ( ..) => "assoc constant" ,
12611249 TraitItemKind :: Fn ( ..) => "trait method" ,
12621250 TraitItemKind :: Type ( ..) => "assoc type" ,
12631251 } ;
12641252
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)
12661254 }
12671255 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)
12691257 }
12701258 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)
12721260 }
12731261 Some ( Node :: AnonConst ( _) ) => node_str ( "const" ) ,
12741262 Some ( Node :: Expr ( _) ) => node_str ( "expr" ) ,
@@ -1285,9 +1273,15 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12851273 Some ( Node :: Block ( _) ) => node_str ( "block" ) ,
12861274 Some ( Node :: Infer ( _) ) => node_str ( "infer" ) ,
12871275 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+ ) ,
12891281 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+ }
12911285 Some ( Node :: Crate ( ..) ) => String :: from ( "root_crate" ) ,
12921286 None => format ! ( "unknown node{}" , id_str) ,
12931287 }
0 commit comments