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