@@ -168,7 +168,7 @@ struct LoweringContext<'a, 'hir: 'a> {
168
168
169
169
current_hir_id_owner : Vec < ( LocalDefId , u32 ) > ,
170
170
item_local_id_counters : NodeMap < u32 > ,
171
- node_id_to_hir_id : IndexVec < NodeId , hir:: HirId > ,
171
+ node_id_to_hir_id : IndexVec < NodeId , Option < hir:: HirId > > ,
172
172
173
173
allow_try_trait : Option < Lrc < [ Symbol ] > > ,
174
174
allow_gen_future : Option < Lrc < [ Symbol ] > > ,
@@ -522,15 +522,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
522
522
}
523
523
524
524
self . lower_node_id ( CRATE_NODE_ID ) ;
525
- debug_assert ! ( self . node_id_to_hir_id[ CRATE_NODE_ID ] == hir:: CRATE_HIR_ID ) ;
525
+ debug_assert ! ( self . node_id_to_hir_id[ CRATE_NODE_ID ] == Some ( hir:: CRATE_HIR_ID ) ) ;
526
526
527
527
visit:: walk_crate ( & mut MiscCollector { lctx : & mut self , hir_id_owner : None } , c) ;
528
528
visit:: walk_crate ( & mut item:: ItemLowerer { lctx : & mut self } , c) ;
529
529
530
530
let module = self . lower_mod ( & c. module ) ;
531
531
let attrs = self . lower_attrs ( & c. attrs ) ;
532
532
let body_ids = body_ids ( & self . bodies ) ;
533
- let proc_macros = c. proc_macros . iter ( ) . map ( |id| self . node_id_to_hir_id [ * id] ) . collect ( ) ;
533
+ let proc_macros =
534
+ c. proc_macros . iter ( ) . map ( |id| self . node_id_to_hir_id [ * id] . unwrap ( ) ) . collect ( ) ;
534
535
535
536
self . resolver . definitions ( ) . init_node_id_to_hir_id_mapping ( self . node_id_to_hir_id ) ;
536
537
@@ -571,26 +572,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
571
572
ast_node_id : NodeId ,
572
573
alloc_hir_id : impl FnOnce ( & mut Self ) -> hir:: HirId ,
573
574
) -> hir:: HirId {
574
- if ast_node_id == DUMMY_NODE_ID {
575
- return hir:: DUMMY_HIR_ID ;
576
- }
575
+ assert_ne ! ( ast_node_id, DUMMY_NODE_ID ) ;
577
576
578
577
let min_size = ast_node_id. as_usize ( ) + 1 ;
579
578
580
579
if min_size > self . node_id_to_hir_id . len ( ) {
581
- self . node_id_to_hir_id . resize ( min_size, hir :: DUMMY_HIR_ID ) ;
580
+ self . node_id_to_hir_id . resize ( min_size, None ) ;
582
581
}
583
582
584
- let existing_hir_id = self . node_id_to_hir_id [ ast_node_id] ;
585
-
586
- if existing_hir_id == hir :: DUMMY_HIR_ID {
583
+ if let Some ( existing_hir_id) = self . node_id_to_hir_id [ ast_node_id] {
584
+ existing_hir_id
585
+ } else {
587
586
// Generate a new `HirId`.
588
587
let hir_id = alloc_hir_id ( self ) ;
589
- self . node_id_to_hir_id [ ast_node_id] = hir_id;
588
+ self . node_id_to_hir_id [ ast_node_id] = Some ( hir_id) ;
590
589
591
590
hir_id
592
- } else {
593
- existing_hir_id
594
591
}
595
592
}
596
593
0 commit comments