@@ -208,17 +208,12 @@ impl<'hir> Map<'hir> {
208
208
self . definitions . def_key ( def_id. index )
209
209
}
210
210
211
- pub fn def_path_from_id ( & self , id : NodeId ) -> Option < DefPath > {
212
- self . opt_local_def_id ( id) . map ( |def_id| {
211
+ pub fn def_path_from_hir_id ( & self , id : HirId ) -> Option < DefPath > {
212
+ self . opt_local_def_id_from_hir_id ( id) . map ( |def_id| {
213
213
self . def_path ( def_id)
214
214
} )
215
215
}
216
216
217
- // FIXME(@ljedrz): replace the NodeId variant
218
- pub fn def_path_from_hir_id ( & self , id : HirId ) -> DefPath {
219
- self . def_path ( self . local_def_id_from_hir_id ( id) )
220
- }
221
-
222
217
pub fn def_path ( & self , def_id : DefId ) -> DefPath {
223
218
assert ! ( def_id. is_local( ) ) ;
224
219
self . definitions . def_path ( def_id. index )
@@ -1075,7 +1070,7 @@ impl<'hir> Map<'hir> {
1075
1070
}
1076
1071
1077
1072
pub fn node_to_string ( & self , id : NodeId ) -> String {
1078
- node_id_to_string ( self , id , true )
1073
+ hir_id_to_string ( self , self . node_to_hir_id ( id ) , true )
1079
1074
}
1080
1075
1081
1076
// FIXME(@ljedrz): replace the NodeId variant
@@ -1084,7 +1079,7 @@ impl<'hir> Map<'hir> {
1084
1079
}
1085
1080
1086
1081
pub fn node_to_user_string ( & self , id : NodeId ) -> String {
1087
- node_id_to_string ( self , id , false )
1082
+ hir_id_to_string ( self , self . node_to_hir_id ( id ) , false )
1088
1083
}
1089
1084
1090
1085
// FIXME(@ljedrz): replace the NodeId variant
@@ -1303,18 +1298,18 @@ impl<'a> print::State<'a> {
1303
1298
}
1304
1299
}
1305
1300
1306
- fn node_id_to_string ( map : & Map < ' _ > , id : NodeId , include_id : bool ) -> String {
1307
- let id_str = format ! ( " (id ={})" , id) ;
1301
+ fn hir_id_to_string ( map : & Map < ' _ > , id : HirId , include_id : bool ) -> String {
1302
+ let id_str = format ! ( " (hir_id ={})" , id) ;
1308
1303
let id_str = if include_id { & id_str[ ..] } else { "" } ;
1309
1304
1310
1305
let path_str = || {
1311
1306
// This functionality is used for debugging, try to use TyCtxt to get
1312
1307
// the user-friendly path, otherwise fall back to stringifying DefPath.
1313
1308
crate :: ty:: tls:: with_opt ( |tcx| {
1314
1309
if let Some ( tcx) = tcx {
1315
- let def_id = map. local_def_id ( id) ;
1310
+ let def_id = map. local_def_id_from_hir_id ( id) ;
1316
1311
tcx. def_path_str ( def_id)
1317
- } else if let Some ( path) = map. def_path_from_id ( id) {
1312
+ } else if let Some ( path) = map. def_path_from_hir_id ( id) {
1318
1313
path. data . into_iter ( ) . map ( |elem| {
1319
1314
elem. data . to_string ( )
1320
1315
} ) . collect :: < Vec < _ > > ( ) . join ( "::" )
@@ -1324,7 +1319,7 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
1324
1319
} )
1325
1320
} ;
1326
1321
1327
- match map. find ( id) {
1322
+ match map. find_by_hir_id ( id) {
1328
1323
Some ( Node :: Item ( item) ) => {
1329
1324
let item_str = match item. node {
1330
1325
ItemKind :: ExternCrate ( ..) => "extern crate" ,
@@ -1385,40 +1380,40 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
1385
1380
path_str( ) , id_str)
1386
1381
}
1387
1382
Some ( Node :: AnonConst ( _) ) => {
1388
- format ! ( "const {}{}" , map. node_to_pretty_string ( id) , id_str)
1383
+ format ! ( "const {}{}" , map. hir_to_pretty_string ( id) , id_str)
1389
1384
}
1390
1385
Some ( Node :: Expr ( _) ) => {
1391
- format ! ( "expr {}{}" , map. node_to_pretty_string ( id) , id_str)
1386
+ format ! ( "expr {}{}" , map. hir_to_pretty_string ( id) , id_str)
1392
1387
}
1393
1388
Some ( Node :: Stmt ( _) ) => {
1394
- format ! ( "stmt {}{}" , map. node_to_pretty_string ( id) , id_str)
1389
+ format ! ( "stmt {}{}" , map. hir_to_pretty_string ( id) , id_str)
1395
1390
}
1396
1391
Some ( Node :: PathSegment ( _) ) => {
1397
- format ! ( "path segment {}{}" , map. node_to_pretty_string ( id) , id_str)
1392
+ format ! ( "path segment {}{}" , map. hir_to_pretty_string ( id) , id_str)
1398
1393
}
1399
1394
Some ( Node :: Ty ( _) ) => {
1400
- format ! ( "type {}{}" , map. node_to_pretty_string ( id) , id_str)
1395
+ format ! ( "type {}{}" , map. hir_to_pretty_string ( id) , id_str)
1401
1396
}
1402
1397
Some ( Node :: TraitRef ( _) ) => {
1403
- format ! ( "trait_ref {}{}" , map. node_to_pretty_string ( id) , id_str)
1398
+ format ! ( "trait_ref {}{}" , map. hir_to_pretty_string ( id) , id_str)
1404
1399
}
1405
1400
Some ( Node :: Binding ( _) ) => {
1406
- format ! ( "local {}{}" , map. node_to_pretty_string ( id) , id_str)
1401
+ format ! ( "local {}{}" , map. hir_to_pretty_string ( id) , id_str)
1407
1402
}
1408
1403
Some ( Node :: Pat ( _) ) => {
1409
- format ! ( "pat {}{}" , map. node_to_pretty_string ( id) , id_str)
1404
+ format ! ( "pat {}{}" , map. hir_to_pretty_string ( id) , id_str)
1410
1405
}
1411
1406
Some ( Node :: Block ( _) ) => {
1412
- format ! ( "block {}{}" , map. node_to_pretty_string ( id) , id_str)
1407
+ format ! ( "block {}{}" , map. hir_to_pretty_string ( id) , id_str)
1413
1408
}
1414
1409
Some ( Node :: Local ( _) ) => {
1415
- format ! ( "local {}{}" , map. node_to_pretty_string ( id) , id_str)
1410
+ format ! ( "local {}{}" , map. hir_to_pretty_string ( id) , id_str)
1416
1411
}
1417
1412
Some ( Node :: Ctor ( ..) ) => {
1418
1413
format ! ( "ctor {}{}" , path_str( ) , id_str)
1419
1414
}
1420
1415
Some ( Node :: Lifetime ( _) ) => {
1421
- format ! ( "lifetime {}{}" , map. node_to_pretty_string ( id) , id_str)
1416
+ format ! ( "lifetime {}{}" , map. hir_to_pretty_string ( id) , id_str)
1422
1417
}
1423
1418
Some ( Node :: GenericParam ( ref param) ) => {
1424
1419
format ! ( "generic_param {:?}{}" , param, id_str)
@@ -1434,12 +1429,6 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
1434
1429
}
1435
1430
}
1436
1431
1437
- // FIXME(@ljedrz): replace the NodeId variant
1438
- fn hir_id_to_string ( map : & Map < ' _ > , id : HirId , include_id : bool ) -> String {
1439
- let node_id = map. hir_to_node_id ( id) ;
1440
- node_id_to_string ( map, node_id, include_id)
1441
- }
1442
-
1443
1432
pub fn def_kind ( tcx : TyCtxt < ' _ , ' _ , ' _ > , def_id : DefId ) -> Option < DefKind > {
1444
1433
if let Some ( node_id) = tcx. hir ( ) . as_local_node_id ( def_id) {
1445
1434
tcx. hir ( ) . def_kind ( node_id)
0 commit comments