@@ -21,7 +21,7 @@ use rustc_ast::walk_list;
21
21
use rustc_ast_pretty:: pprust:: { bounds_to_string, generic_params_to_string, ty_to_string} ;
22
22
use rustc_data_structures:: fx:: FxHashSet ;
23
23
use rustc_hir:: def:: { DefKind as HirDefKind , Res } ;
24
- use rustc_hir:: def_id:: DefId ;
24
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
25
25
use rustc_middle:: span_bug;
26
26
use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
27
27
use rustc_session:: config:: Input ;
@@ -103,12 +103,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
103
103
self . dumper . analysis ( )
104
104
}
105
105
106
- fn nest_tables < F > ( & mut self , item_id : NodeId , f : F )
106
+ fn nest_tables < F > ( & mut self , item_def_id : LocalDefId , f : F )
107
107
where
108
108
F : FnOnce ( & mut Self ) ,
109
109
{
110
- let item_def_id = self . tcx . hir ( ) . local_def_id_from_node_id ( item_id) ;
111
-
112
110
let tables = if self . tcx . has_typeck_tables ( item_def_id) {
113
111
self . tcx . typeck_tables_of ( item_def_id)
114
112
} else {
@@ -271,8 +269,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
271
269
) {
272
270
debug ! ( "process_method: {}:{}" , id, ident) ;
273
271
274
- let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( id) ;
275
- self . nest_tables ( id, |v| {
272
+ let map = & self . tcx . hir ( ) ;
273
+ let hir_id = map. node_id_to_hir_id ( id) ;
274
+ self . nest_tables ( map. local_def_id ( hir_id) , |v| {
276
275
if let Some ( mut method_data) = v. save_ctxt . get_method_data ( id, ident, span) {
277
276
v. process_formals ( & sig. decl . inputs , & method_data. qualname ) ;
278
277
v. process_generic_params ( & generics, & method_data. qualname , id) ;
@@ -295,7 +294,8 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
295
294
// start walking from the newly-created definition.
296
295
match sig. header . asyncness {
297
296
ast:: Async :: Yes { return_impl_trait_id, .. } => {
298
- v. nest_tables ( return_impl_trait_id, |v| v. visit_ty ( ret_ty) )
297
+ let hir_id = map. node_id_to_hir_id ( return_impl_trait_id) ;
298
+ v. nest_tables ( map. local_def_id ( hir_id) , |v| v. visit_ty ( ret_ty) )
299
299
}
300
300
_ => v. visit_ty ( ret_ty) ,
301
301
}
@@ -363,8 +363,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
363
363
ty_params : & ' l ast:: Generics ,
364
364
body : Option < & ' l ast:: Block > ,
365
365
) {
366
- let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( item. id ) ;
367
- self . nest_tables ( item. id , |v| {
366
+ let map = & self . tcx . hir ( ) ;
367
+ let hir_id = map. node_id_to_hir_id ( item. id ) ;
368
+ self . nest_tables ( map. local_def_id ( hir_id) , |v| {
368
369
if let Some ( fn_data) = v. save_ctxt . get_item_data ( item) {
369
370
down_cast_data ! ( fn_data, DefData , item. span) ;
370
371
v. process_formals ( & decl. inputs , & fn_data. qualname ) ;
@@ -388,7 +389,8 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
388
389
// start walking from the newly-created definition.
389
390
match header. asyncness {
390
391
ast:: Async :: Yes { return_impl_trait_id, .. } => {
391
- v. nest_tables ( return_impl_trait_id, |v| v. visit_ty ( ret_ty) )
392
+ let hir_id = map. node_id_to_hir_id ( return_impl_trait_id) ;
393
+ v. nest_tables ( map. local_def_id ( hir_id) , |v| v. visit_ty ( ret_ty) )
392
394
}
393
395
_ => v. visit_ty ( ret_ty) ,
394
396
}
@@ -406,7 +408,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
406
408
expr : Option < & ' l ast:: Expr > ,
407
409
) {
408
410
let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( item. id ) ;
409
- self . nest_tables ( item . id , |v| {
411
+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id ) , |v| {
410
412
if let Some ( var_data) = v. save_ctxt . get_item_data ( item) {
411
413
down_cast_data ! ( var_data, DefData , item. span) ;
412
414
v. dumper . dump_def ( & access_from ! ( v. save_ctxt, item, hir_id) , var_data) ;
@@ -426,15 +428,13 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
426
428
vis : ast:: Visibility ,
427
429
attrs : & ' l [ Attribute ] ,
428
430
) {
429
- let qualname = format ! (
430
- "::{}" ,
431
- self . tcx. def_path_str( self . tcx. hir( ) . local_def_id_from_node_id( id) . to_def_id( ) )
432
- ) ;
431
+ let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( id) ;
432
+ let qualname =
433
+ format ! ( "::{}" , self . tcx. def_path_str( self . tcx. hir( ) . local_def_id( hir_id) . to_def_id( ) ) ) ;
433
434
434
435
if !self . span . filter_generated ( ident. span ) {
435
436
let sig = sig:: assoc_const_signature ( id, ident. name , typ, expr, & self . save_ctxt ) ;
436
437
let span = self . span_from_span ( ident. span ) ;
437
- let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( id) ;
438
438
439
439
self . dumper . dump_def (
440
440
& access_from_vis ! ( self . save_ctxt, vis, hir_id) ,
@@ -456,7 +456,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
456
456
}
457
457
458
458
// walk type and init value
459
- self . nest_tables ( id , |v| {
459
+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id ) , |v| {
460
460
v. visit_ty ( typ) ;
461
461
if let Some ( expr) = expr {
462
462
v. visit_expr ( expr) ;
@@ -473,10 +473,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
473
473
) {
474
474
debug ! ( "process_struct {:?} {:?}" , item, item. span) ;
475
475
let name = item. ident . to_string ( ) ;
476
- let qualname = format ! (
477
- "::{}" ,
478
- self . tcx. def_path_str( self . tcx. hir( ) . local_def_id_from_node_id( item. id) . to_def_id( ) )
479
- ) ;
476
+ let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( item. id ) ;
477
+ let qualname =
478
+ format ! ( "::{}" , self . tcx. def_path_str( self . tcx. hir( ) . local_def_id( hir_id) . to_def_id( ) ) ) ;
480
479
481
480
let kind = match item. kind {
482
481
ast:: ItemKind :: Struct ( _, _) => DefKind :: Struct ,
@@ -508,7 +507,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
508
507
509
508
if !self . span . filter_generated ( item. ident . span ) {
510
509
let span = self . span_from_span ( item. ident . span ) ;
511
- let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( item. id ) ;
512
510
self . dumper . dump_def (
513
511
& access_from ! ( self . save_ctxt, item, hir_id) ,
514
512
Def {
@@ -528,7 +526,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
528
526
) ;
529
527
}
530
528
531
- self . nest_tables ( item . id , |v| {
529
+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id ) , |v| {
532
530
for field in def. fields ( ) {
533
531
v. process_struct_field_def ( field, item. id ) ;
534
532
v. visit_ty ( & field. ty ) ;
@@ -668,14 +666,15 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
668
666
}
669
667
670
668
let map = & self . tcx . hir ( ) ;
671
- self . nest_tables ( item. id , |v| {
669
+ let hir_id = map. node_id_to_hir_id ( item. id ) ;
670
+ self . nest_tables ( map. local_def_id ( hir_id) , |v| {
672
671
v. visit_ty ( & typ) ;
673
672
if let & Some ( ref trait_ref) = trait_ref {
674
673
v. process_path ( trait_ref. ref_id , & trait_ref. path ) ;
675
674
}
676
675
v. process_generic_params ( generics, "" , item. id ) ;
677
676
for impl_item in impl_items {
678
- v. process_impl_item ( impl_item, map. local_def_id_from_node_id ( item . id ) . to_def_id ( ) ) ;
677
+ v. process_impl_item ( impl_item, map. local_def_id ( hir_id ) . to_def_id ( ) ) ;
679
678
}
680
679
} ) ;
681
680
}
@@ -1410,7 +1409,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1410
1409
}
1411
1410
ast:: TyKind :: Array ( ref element, ref length) => {
1412
1411
self . visit_ty ( element) ;
1413
- self . nest_tables ( length. id , |v| v. visit_expr ( & length. value ) ) ;
1412
+ let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( length. id ) ;
1413
+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id) , |v| {
1414
+ v. visit_expr ( & length. value )
1415
+ } ) ;
1414
1416
}
1415
1417
ast:: TyKind :: ImplTrait ( id, ref bounds) => {
1416
1418
// FIXME: As of writing, the opaque type lowering introduces
@@ -1422,7 +1424,13 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1422
1424
// bounds...
1423
1425
// This will panic if called on return type `impl Trait`, which
1424
1426
// we guard against in `process_fn`.
1425
- self . nest_tables ( id, |v| v. process_bounds ( bounds) ) ;
1427
+ // FIXME(#71104) Should really be using just `node_id_to_hir_id` but
1428
+ // some `NodeId` do not seem to have a corresponding HirId.
1429
+ if let Some ( hir_id) = self . tcx . hir ( ) . opt_node_id_to_hir_id ( id) {
1430
+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id) , |v| {
1431
+ v. process_bounds ( bounds)
1432
+ } ) ;
1433
+ }
1426
1434
}
1427
1435
_ => visit:: walk_ty ( self , t) ,
1428
1436
}
@@ -1470,7 +1478,8 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1470
1478
}
1471
1479
1472
1480
// walk the body
1473
- self . nest_tables ( ex. id , |v| {
1481
+ let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( ex. id ) ;
1482
+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id) , |v| {
1474
1483
v. process_formals ( & decl. inputs , & id) ;
1475
1484
v. visit_expr ( body)
1476
1485
} ) ;
@@ -1487,7 +1496,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1487
1496
}
1488
1497
ast:: ExprKind :: Repeat ( ref element, ref count) => {
1489
1498
self . visit_expr ( element) ;
1490
- self . nest_tables ( count. id , |v| v. visit_expr ( & count. value ) ) ;
1499
+ let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( count. id ) ;
1500
+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id) , |v| {
1501
+ v. visit_expr ( & count. value )
1502
+ } ) ;
1491
1503
}
1492
1504
// In particular, we take this branch for call and path expressions,
1493
1505
// where we'll index the idents involved just by continuing to walk.
0 commit comments