@@ -168,7 +168,7 @@ struct LoweringContext<'a, 'hir: 'a> {
168168
169169 current_hir_id_owner : Vec < ( LocalDefId , u32 ) > ,
170170 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 > > ,
172172
173173 allow_try_trait : Option < Lrc < [ Symbol ] > > ,
174174 allow_gen_future : Option < Lrc < [ Symbol ] > > ,
@@ -522,15 +522,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
522522 }
523523
524524 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 ) ) ;
526526
527527 visit:: walk_crate ( & mut MiscCollector { lctx : & mut self , hir_id_owner : None } , c) ;
528528 visit:: walk_crate ( & mut item:: ItemLowerer { lctx : & mut self } , c) ;
529529
530530 let module = self . lower_mod ( & c. module ) ;
531531 let attrs = self . lower_attrs ( & c. attrs ) ;
532532 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 ( ) ;
534535
535536 self . resolver . definitions ( ) . init_node_id_to_hir_id_mapping ( self . node_id_to_hir_id ) ;
536537
@@ -571,26 +572,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
571572 ast_node_id : NodeId ,
572573 alloc_hir_id : impl FnOnce ( & mut Self ) -> hir:: HirId ,
573574 ) -> 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 ) ;
577576
578577 let min_size = ast_node_id. as_usize ( ) + 1 ;
579578
580579 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 ) ;
582581 }
583582
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 {
587586 // Generate a new `HirId`.
588587 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) ;
590589
591590 hir_id
592- } else {
593- existing_hir_id
594591 }
595592 }
596593
0 commit comments