@@ -54,7 +54,7 @@ use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
54
54
use rustc_hir:: def_id:: { DefId , DefPathHash , LocalDefId , CRATE_DEF_ID } ;
55
55
use rustc_hir:: definitions:: { DefKey , DefPathData , Definitions } ;
56
56
use rustc_hir:: intravisit;
57
- use rustc_hir:: { ConstArg , GenericArg , ItemLocalId , ParamName } ;
57
+ use rustc_hir:: { ConstArg , GenericArg , ItemLocalId , ParamName , TraitCandidate } ;
58
58
use rustc_index:: vec:: { Idx , IndexVec } ;
59
59
use rustc_query_system:: ich:: StableHashingContext ;
60
60
use rustc_session:: lint:: LintBuffer ;
@@ -156,6 +156,7 @@ struct LoweringContext<'a, 'hir: 'a> {
156
156
current_hir_id_owner : LocalDefId ,
157
157
item_local_id_counter : hir:: ItemLocalId ,
158
158
local_id_to_def_id : SortedMap < ItemLocalId , LocalDefId > ,
159
+ trait_map : FxHashMap < ItemLocalId , Box < [ TraitCandidate ] > > ,
159
160
160
161
/// NodeIds that are lowered inside the current HIR owner.
161
162
node_id_to_local_id : FxHashMap < NodeId , hir:: ItemLocalId > ,
@@ -314,6 +315,7 @@ pub fn lower_crate<'a, 'hir>(
314
315
item_local_id_counter : hir:: ItemLocalId :: new ( 0 ) ,
315
316
node_id_to_local_id : FxHashMap :: default ( ) ,
316
317
local_id_to_def_id : SortedMap :: new ( ) ,
318
+ trait_map : FxHashMap :: default ( ) ,
317
319
generator_kind : None ,
318
320
task_context : None ,
319
321
current_item : None ,
@@ -442,6 +444,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
442
444
let current_bodies = std:: mem:: take ( & mut self . bodies ) ;
443
445
let current_node_ids = std:: mem:: take ( & mut self . node_id_to_local_id ) ;
444
446
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 ) ;
445
448
let current_owner = std:: mem:: replace ( & mut self . current_hir_id_owner , def_id) ;
446
449
let current_local_counter =
447
450
std:: mem:: replace ( & mut self . item_local_id_counter , hir:: ItemLocalId :: new ( 1 ) ) ;
@@ -458,6 +461,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
458
461
self . bodies = current_bodies;
459
462
self . node_id_to_local_id = current_node_ids;
460
463
self . local_id_to_def_id = current_id_to_def_id;
464
+ self . trait_map = current_trait_map;
461
465
self . current_hir_id_owner = current_owner;
462
466
self . item_local_id_counter = current_local_counter;
463
467
@@ -470,15 +474,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
470
474
fn make_owner_info ( & mut self , node : hir:: OwnerNode < ' hir > ) -> hir:: OwnerInfo < ' hir > {
471
475
let attrs = std:: mem:: take ( & mut self . attrs ) ;
472
476
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 ( ) ;
482
477
483
478
#[ cfg( debug_assertions) ]
484
479
for ( id, attrs) in attrs. iter ( ) {
@@ -508,7 +503,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
508
503
hir:: AttributeMap { map : attrs, hash }
509
504
} ;
510
505
511
- hir:: OwnerInfo { nodes, parenting, attrs, trait_map }
506
+ hir:: OwnerInfo { nodes, parenting, attrs, trait_map : std :: mem :: take ( & mut self . trait_map ) }
512
507
}
513
508
514
509
/// 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> {
563
558
}
564
559
self . local_id_to_def_id . insert ( local_id, def_id) ;
565
560
}
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
+ }
566
565
}
567
566
568
567
hir_id
0 commit comments