@@ -54,7 +54,7 @@ use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
5454use rustc_hir:: def_id:: { DefId , DefPathHash , LocalDefId , CRATE_DEF_ID } ;
5555use rustc_hir:: definitions:: { DefKey , DefPathData , Definitions } ;
5656use rustc_hir:: intravisit;
57- use rustc_hir:: { ConstArg , GenericArg , ItemLocalId , ParamName } ;
57+ use rustc_hir:: { ConstArg , GenericArg , ItemLocalId , ParamName , TraitCandidate } ;
5858use rustc_index:: vec:: { Idx , IndexVec } ;
5959use rustc_query_system:: ich:: StableHashingContext ;
6060use rustc_session:: lint:: LintBuffer ;
@@ -156,6 +156,7 @@ struct LoweringContext<'a, 'hir: 'a> {
156156 current_hir_id_owner : LocalDefId ,
157157 item_local_id_counter : hir:: ItemLocalId ,
158158 local_id_to_def_id : SortedMap < ItemLocalId , LocalDefId > ,
159+ trait_map : FxHashMap < ItemLocalId , Box < [ TraitCandidate ] > > ,
159160
160161 /// NodeIds that are lowered inside the current HIR owner.
161162 node_id_to_local_id : FxHashMap < NodeId , hir:: ItemLocalId > ,
@@ -314,6 +315,7 @@ pub fn lower_crate<'a, 'hir>(
314315 item_local_id_counter : hir:: ItemLocalId :: new ( 0 ) ,
315316 node_id_to_local_id : FxHashMap :: default ( ) ,
316317 local_id_to_def_id : SortedMap :: new ( ) ,
318+ trait_map : FxHashMap :: default ( ) ,
317319 generator_kind : None ,
318320 task_context : None ,
319321 current_item : None ,
@@ -442,6 +444,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
442444 let current_bodies = std:: mem:: take ( & mut self . bodies ) ;
443445 let current_node_ids = std:: mem:: take ( & mut self . node_id_to_local_id ) ;
444446 let current_id_to_def_id = std:: mem:: take ( & mut self . local_id_to_def_id ) ;
447+ let current_trait_map = std:: mem:: take ( & mut self . trait_map ) ;
445448 let current_owner = std:: mem:: replace ( & mut self . current_hir_id_owner , def_id) ;
446449 let current_local_counter =
447450 std:: mem:: replace ( & mut self . item_local_id_counter , hir:: ItemLocalId :: new ( 1 ) ) ;
@@ -458,6 +461,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
458461 self . bodies = current_bodies;
459462 self . node_id_to_local_id = current_node_ids;
460463 self . local_id_to_def_id = current_id_to_def_id;
464+ self . trait_map = current_trait_map;
461465 self . current_hir_id_owner = current_owner;
462466 self . item_local_id_counter = current_local_counter;
463467
@@ -470,15 +474,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
470474 fn make_owner_info ( & mut self , node : hir:: OwnerNode < ' hir > ) -> hir:: OwnerInfo < ' hir > {
471475 let attrs = std:: mem:: take ( & mut self . attrs ) ;
472476 let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
473- let node_id_to_local_id = std:: mem:: take ( & mut self . node_id_to_local_id ) ;
474-
475- let trait_map = node_id_to_local_id
476- . into_iter ( )
477- . filter_map ( |( node_id, local_id) | {
478- let traits = self . resolver . take_trait_map ( node_id) ?;
479- Some ( ( local_id, traits. into_boxed_slice ( ) ) )
480- } )
481- . collect ( ) ;
482477
483478 #[ cfg( debug_assertions) ]
484479 for ( id, attrs) in attrs. iter ( ) {
@@ -508,7 +503,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
508503 hir:: AttributeMap { map : attrs, hash }
509504 } ;
510505
511- hir:: OwnerInfo { nodes, parenting, attrs, trait_map }
506+ hir:: OwnerInfo { nodes, parenting, attrs, trait_map : std :: mem :: take ( & mut self . trait_map ) }
512507 }
513508
514509 /// Hash the HIR node twice, one deep and one shallow hash. This allows to differentiate
@@ -563,6 +558,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
563558 }
564559 self . local_id_to_def_id . insert ( local_id, def_id) ;
565560 }
561+
562+ if let Some ( traits) = self . resolver . take_trait_map ( ast_node_id) {
563+ self . trait_map . insert ( hir_id. local_id , traits. into_boxed_slice ( ) ) ;
564+ }
566565 }
567566
568567 hir_id
0 commit comments