@@ -56,7 +56,6 @@ use rustc_hir::def::{
5656} ;
5757use rustc_hir:: def_id:: { CRATE_DEF_ID , CrateNum , DefId , LOCAL_CRATE , LocalDefId , LocalDefIdMap } ;
5858use rustc_hir:: { PrimTy , TraitCandidate } ;
59- use rustc_index:: IndexVec ;
6059use rustc_metadata:: creader:: { CStore , CrateLoader } ;
6160use rustc_middle:: metadata:: ModChild ;
6261use rustc_middle:: middle:: privacy:: EffectiveVisibilities ;
@@ -1184,7 +1183,6 @@ pub struct Resolver<'ra, 'tcx> {
11841183 next_node_id : NodeId ,
11851184
11861185 node_id_to_def_id : NodeMap < Feed < ' tcx , LocalDefId > > ,
1187- def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
11881186
11891187 /// Indices of unnamed struct or variant fields with unresolved attributes.
11901188 placeholder_field_indices : FxHashMap < NodeId , usize > ,
@@ -1369,7 +1367,6 @@ impl<'tcx> Resolver<'_, 'tcx> {
13691367 debug ! ( "create_def: def_id_to_node_id[{:?}] <-> {:?}" , def_id, node_id) ;
13701368 self . node_id_to_def_id . insert ( node_id, feed. downgrade ( ) ) ;
13711369 }
1372- assert_eq ! ( self . def_id_to_node_id. push( node_id) , def_id) ;
13731370
13741371 feed
13751372 }
@@ -1385,6 +1382,19 @@ impl<'tcx> Resolver<'_, 'tcx> {
13851382 pub fn tcx ( & self ) -> TyCtxt < ' tcx > {
13861383 self . tcx
13871384 }
1385+
1386+ /// This function is very slow, as it iterates over the entire
1387+ /// [Resolver::node_id_to_def_id] map just to find the [NodeId]
1388+ /// that corresponds to the given [LocalDefId]. Only use this in
1389+ /// diagnostics code paths.
1390+ fn def_id_to_node_id ( & self , def_id : LocalDefId ) -> NodeId {
1391+ self . node_id_to_def_id
1392+ . items ( )
1393+ . filter ( |( _, v) | v. key ( ) == def_id)
1394+ . map ( |( k, _) | * k)
1395+ . get_only ( )
1396+ . unwrap ( )
1397+ }
13881398}
13891399
13901400impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
@@ -1417,8 +1427,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14171427 & mut Default :: default ( ) ,
14181428 ) ;
14191429
1420- let mut def_id_to_node_id = IndexVec :: default ( ) ;
1421- assert_eq ! ( def_id_to_node_id. push( CRATE_NODE_ID ) , CRATE_DEF_ID ) ;
14221430 let mut node_id_to_def_id = NodeMap :: default ( ) ;
14231431 let crate_feed = tcx. create_local_crate_def_id ( crate_span) ;
14241432
@@ -1553,7 +1561,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15531561 lint_buffer : LintBuffer :: default ( ) ,
15541562 next_node_id : CRATE_NODE_ID ,
15551563 node_id_to_def_id,
1556- def_id_to_node_id,
15571564 placeholder_field_indices : Default :: default ( ) ,
15581565 invocation_parents,
15591566 legacy_const_generic_args : Default :: default ( ) ,
0 commit comments