@@ -53,8 +53,8 @@ use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
53
53
use rustc_hir:: def_id:: { DefId , DefIdMap , LocalDefId , CRATE_DEF_INDEX } ;
54
54
use rustc_hir:: definitions:: { DefKey , DefPathData , Definitions } ;
55
55
use rustc_hir:: intravisit;
56
- use rustc_hir:: { ConstArg , GenericArg , ParamName } ;
57
- use rustc_index:: vec:: IndexVec ;
56
+ use rustc_hir:: { ConstArg , GenericArg , HirIdVec , ParamName } ;
57
+ use rustc_index:: vec:: { Idx , IndexVec } ;
58
58
use rustc_session:: config:: nightly_options;
59
59
use rustc_session:: lint:: { builtin:: BARE_TRAIT_OBJECTS , BuiltinLintDiagnostics , LintBuffer } ;
60
60
use rustc_session:: parse:: ParseSess ;
@@ -115,7 +115,7 @@ struct LoweringContext<'a, 'hir: 'a> {
115
115
modules : BTreeMap < hir:: HirId , hir:: ModuleItems > ,
116
116
117
117
/// Collected spans from the AST.
118
- spans : BTreeMap < hir :: HirId , Span > ,
118
+ spans : HirIdVec < Span > ,
119
119
120
120
generator_kind : Option < hir:: GeneratorKind > ,
121
121
@@ -307,7 +307,7 @@ pub fn lower_crate<'a, 'hir>(
307
307
bodies : BTreeMap :: new ( ) ,
308
308
trait_impls : BTreeMap :: new ( ) ,
309
309
modules : BTreeMap :: new ( ) ,
310
- spans : BTreeMap :: new ( ) ,
310
+ spans : Default :: default ( ) ,
311
311
exported_macros : Vec :: new ( ) ,
312
312
non_exported_macro_attrs : Vec :: new ( ) ,
313
313
catch_scopes : Vec :: new ( ) ,
@@ -570,6 +570,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
570
570
571
571
self . resolver . definitions ( ) . init_node_id_to_hir_id_mapping ( self . node_id_to_hir_id ) ;
572
572
573
+ //FIXME(cjgillot) Ideally, each LocalDefId would be a HIR owner.
574
+ // In the mean time, allocate the missing empty vectors.
575
+ self . spans . push_owner ( Idx :: new ( self . resolver . definitions ( ) . def_index_count ( ) - 1 ) ) ;
576
+
573
577
hir:: Crate {
574
578
item : hir:: CrateItem { module, attrs, span : c. span } ,
575
579
exported_macros : self . arena . alloc_from_iter ( self . exported_macros ) ,
@@ -619,22 +623,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
619
623
}
620
624
621
625
let hir_id = if let Some ( existing_hir_id) = self . node_id_to_hir_id [ ast_node_id] {
626
+ if span != DUMMY_SP {
627
+ debug_assert ! (
628
+ self . spans[ existing_hir_id] == DUMMY_SP || self . spans[ existing_hir_id] == span
629
+ ) ;
630
+ self . spans [ existing_hir_id] = span;
631
+ }
622
632
existing_hir_id
623
633
} else {
624
634
// Generate a new `HirId`.
625
635
let hir_id = alloc_hir_id ( self ) ;
626
636
self . node_id_to_hir_id [ ast_node_id] = Some ( hir_id) ;
637
+ self . spans . push ( hir_id, span) ;
627
638
628
639
hir_id
629
640
} ;
630
641
631
- let stored_span = self . spans . entry ( hir_id) . or_insert ( span) ;
632
- if * stored_span == DUMMY_SP {
633
- * stored_span = span;
634
- } else if span != DUMMY_SP {
635
- assert_eq ! ( * stored_span, span) ;
636
- }
637
-
638
642
hir_id
639
643
}
640
644
0 commit comments