@@ -51,7 +51,6 @@ use rustc_data_structures::thin_vec::ThinVec;
51
51
use rustc_data_structures:: sync:: Lrc ;
52
52
53
53
use std:: collections:: { BTreeSet , BTreeMap } ;
54
- use std:: fmt:: Debug ;
55
54
use std:: mem;
56
55
use smallvec:: SmallVec ;
57
56
use syntax:: attr;
@@ -378,13 +377,13 @@ impl<'a> LoweringContext<'a> {
378
377
Mark :: root ( ) ,
379
378
tree. prefix . span ,
380
379
) ;
381
- self . lctx . allocate_hir_id_counter ( id, & tree ) ;
380
+ self . lctx . allocate_hir_id_counter ( id) ;
382
381
}
383
382
}
384
383
UseTreeKind :: Glob => ( ) ,
385
384
UseTreeKind :: Nested ( ref trees) => {
386
385
for & ( ref use_tree, id) in trees {
387
- let hir_id = self . lctx . allocate_hir_id_counter ( id, & use_tree ) . hir_id ;
386
+ let hir_id = self . lctx . allocate_hir_id_counter ( id) . hir_id ;
388
387
self . allocate_use_tree_hir_id_counters ( use_tree, hir_id. owner ) ;
389
388
}
390
389
}
@@ -394,7 +393,7 @@ impl<'a> LoweringContext<'a> {
394
393
395
394
impl < ' lcx , ' interner > Visitor < ' lcx > for MiscCollector < ' lcx , ' interner > {
396
395
fn visit_item ( & mut self , item : & ' lcx Item ) {
397
- let hir_id = self . lctx . allocate_hir_id_counter ( item. id , item ) . hir_id ;
396
+ let hir_id = self . lctx . allocate_hir_id_counter ( item. id ) . hir_id ;
398
397
399
398
match item. node {
400
399
ItemKind :: Struct ( _, ref generics)
@@ -423,12 +422,12 @@ impl<'a> LoweringContext<'a> {
423
422
}
424
423
425
424
fn visit_trait_item ( & mut self , item : & ' lcx TraitItem ) {
426
- self . lctx . allocate_hir_id_counter ( item. id , item ) ;
425
+ self . lctx . allocate_hir_id_counter ( item. id ) ;
427
426
visit:: walk_trait_item ( self , item) ;
428
427
}
429
428
430
429
fn visit_impl_item ( & mut self , item : & ' lcx ImplItem ) {
431
- self . lctx . allocate_hir_id_counter ( item. id , item ) ;
430
+ self . lctx . allocate_hir_id_counter ( item. id ) ;
432
431
visit:: walk_impl_item ( self , item) ;
433
432
}
434
433
}
@@ -557,15 +556,13 @@ impl<'a> LoweringContext<'a> {
557
556
self . modules . get_mut ( & self . current_module ) . unwrap ( ) . items . insert ( id) ;
558
557
}
559
558
560
- fn allocate_hir_id_counter < T : Debug > ( & mut self , owner : NodeId , debug : & T ) -> LoweredNodeId {
561
- if self . item_local_id_counters . insert ( owner, 0 ) . is_some ( ) {
562
- bug ! (
563
- "Tried to allocate item_local_id_counter for {:?} twice" ,
564
- debug
565
- ) ;
566
- }
559
+ fn allocate_hir_id_counter ( & mut self , owner : NodeId ) -> LoweredNodeId {
560
+ // Setup the counter if needed
561
+ self . item_local_id_counters . entry ( owner) . or_insert ( 0 ) ;
567
562
// Always allocate the first `HirId` for the owner itself.
568
- self . lower_node_id_with_owner ( owner, owner)
563
+ let lowered = self . lower_node_id_with_owner ( owner, owner) ;
564
+ debug_assert_eq ! ( lowered. hir_id. local_id. as_u32( ) , 0 ) ;
565
+ lowered
569
566
}
570
567
571
568
fn lower_node_id_generic < F > ( & mut self , ast_node_id : NodeId , alloc_hir_id : F ) -> LoweredNodeId
@@ -1417,7 +1414,7 @@ impl<'a> LoweringContext<'a> {
1417
1414
. opt_def_index ( exist_ty_node_id)
1418
1415
. unwrap ( ) ;
1419
1416
1420
- self . allocate_hir_id_counter ( exist_ty_node_id, & "existential impl trait" ) ;
1417
+ self . allocate_hir_id_counter ( exist_ty_node_id) ;
1421
1418
1422
1419
let hir_bounds = self . with_hir_id_owner ( exist_ty_node_id, lower_bounds) ;
1423
1420
@@ -3495,9 +3492,7 @@ impl<'a> LoweringContext<'a> {
3495
3492
} ;
3496
3493
3497
3494
node_ids. into_iter ( ) . map ( |node_id| hir:: ItemId {
3498
- id : self . lower_node_id_generic ( node_id, |_| {
3499
- panic ! ( "expected node_id to be lowered already {:#?}" , i)
3500
- } ) . hir_id
3495
+ id : self . allocate_hir_id_counter ( node_id) . hir_id
3501
3496
} ) . collect ( )
3502
3497
}
3503
3498
0 commit comments