@@ -21,7 +21,7 @@ use rustc_ast::walk_list;
2121use rustc_ast_pretty:: pprust:: { bounds_to_string, generic_params_to_string, ty_to_string} ;
2222use rustc_data_structures:: fx:: FxHashSet ;
2323use rustc_hir:: def:: { DefKind as HirDefKind , Res } ;
24- use rustc_hir:: def_id:: DefId ;
24+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
2525use rustc_middle:: span_bug;
2626use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
2727use rustc_session:: config:: Input ;
@@ -104,12 +104,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
104104 self . dumper . analysis ( )
105105 }
106106
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 )
108108 where
109109 F : FnOnce ( & mut Self ) ,
110110 {
111- let item_def_id = self . tcx . hir ( ) . local_def_id_from_node_id ( item_id) ;
112-
113111 let tables = if self . tcx . has_typeck_tables ( item_def_id) {
114112 self . tcx . typeck_tables_of ( item_def_id)
115113 } else {
@@ -272,8 +270,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
272270 ) {
273271 debug ! ( "process_method: {}:{}" , id, ident) ;
274272
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| {
277276 if let Some ( mut method_data) = v. save_ctxt . get_method_data ( id, ident, span) {
278277 v. process_formals ( & sig. decl . inputs , & method_data. qualname ) ;
279278 v. process_generic_params ( & generics, & method_data. qualname , id) ;
@@ -296,7 +295,8 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
296295 // start walking from the newly-created definition.
297296 match sig. header . asyncness {
298297 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) )
300300 }
301301 _ => v. visit_ty ( ret_ty) ,
302302 }
@@ -364,8 +364,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
364364 ty_params : & ' l ast:: Generics ,
365365 body : Option < & ' l ast:: Block > ,
366366 ) {
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| {
369370 if let Some ( fn_data) = v. save_ctxt . get_item_data ( item) {
370371 down_cast_data ! ( fn_data, DefData , item. span) ;
371372 v. process_formals ( & decl. inputs , & fn_data. qualname ) ;
@@ -389,7 +390,8 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
389390 // start walking from the newly-created definition.
390391 match header. asyncness {
391392 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) )
393395 }
394396 _ => v. visit_ty ( ret_ty) ,
395397 }
@@ -407,7 +409,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
407409 expr : Option < & ' l ast:: Expr > ,
408410 ) {
409411 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| {
411413 if let Some ( var_data) = v. save_ctxt . get_item_data ( item) {
412414 down_cast_data ! ( var_data, DefData , item. span) ;
413415 v. dumper . dump_def ( & access_from ! ( v. save_ctxt, item, hir_id) , var_data) ;
@@ -427,15 +429,13 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
427429 vis : ast:: Visibility ,
428430 attrs : & ' l [ Attribute ] ,
429431 ) {
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( ) ) ) ;
434435
435436 if !self . span . filter_generated ( ident. span ) {
436437 let sig = sig:: assoc_const_signature ( id, ident. name , typ, expr, & self . save_ctxt ) ;
437438 let span = self . span_from_span ( ident. span ) ;
438- let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( id) ;
439439
440440 self . dumper . dump_def (
441441 & access_from_vis ! ( self . save_ctxt, vis, hir_id) ,
@@ -457,7 +457,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
457457 }
458458
459459 // walk type and init value
460- self . nest_tables ( id , |v| {
460+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id ) , |v| {
461461 v. visit_ty ( typ) ;
462462 if let Some ( expr) = expr {
463463 v. visit_expr ( expr) ;
@@ -474,10 +474,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
474474 ) {
475475 debug ! ( "process_struct {:?} {:?}" , item, item. span) ;
476476 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( ) ) ) ;
481480
482481 let kind = match item. kind {
483482 ast:: ItemKind :: Struct ( _, _) => DefKind :: Struct ,
@@ -509,7 +508,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
509508
510509 if !self . span . filter_generated ( item. ident . span ) {
511510 let span = self . span_from_span ( item. ident . span ) ;
512- let hir_id = self . tcx . hir ( ) . node_id_to_hir_id ( item. id ) ;
513511 self . dumper . dump_def (
514512 & access_from ! ( self . save_ctxt, item, hir_id) ,
515513 Def {
@@ -529,7 +527,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
529527 ) ;
530528 }
531529
532- self . nest_tables ( item . id , |v| {
530+ self . nest_tables ( self . tcx . hir ( ) . local_def_id ( hir_id ) , |v| {
533531 for field in def. fields ( ) {
534532 v. process_struct_field_def ( field, item. id ) ;
535533 v. visit_ty ( & field. ty ) ;
@@ -669,14 +667,15 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
669667 }
670668
671669 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| {
673672 v. visit_ty ( & typ) ;
674673 if let & Some ( ref trait_ref) = trait_ref {
675674 v. process_path ( trait_ref. ref_id , & trait_ref. path ) ;
676675 }
677676 v. process_generic_params ( generics, "" , item. id ) ;
678677 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 ( ) ) ;
680679 }
681680 } ) ;
682681 }
@@ -1411,7 +1410,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14111410 }
14121411 ast:: TyKind :: Array ( ref element, ref length) => {
14131412 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+ } ) ;
14151417 }
14161418 ast:: TyKind :: ImplTrait ( id, ref bounds) => {
14171419 // FIXME: As of writing, the opaque type lowering introduces
@@ -1423,7 +1425,13 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14231425 // bounds...
14241426 // This will panic if called on return type `impl Trait`, which
14251427 // 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+ }
14271435 }
14281436 _ => visit:: walk_ty ( self , t) ,
14291437 }
@@ -1471,7 +1479,8 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14711479 }
14721480
14731481 // 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| {
14751484 v. process_formals ( & decl. inputs , & id) ;
14761485 v. visit_expr ( body)
14771486 } ) ;
@@ -1488,7 +1497,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14881497 }
14891498 ast:: ExprKind :: Repeat ( ref element, ref count) => {
14901499 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+ } ) ;
14921504 }
14931505 // In particular, we take this branch for call and path expressions,
14941506 // where we'll index the idents involved just by continuing to walk.
0 commit comments