1
- use rustc_data_structures:: fx:: FxHashSet ;
2
1
use rustc_data_structures:: sync:: Lock ;
3
2
use rustc_hir as hir;
4
3
use rustc_hir:: def_id:: { LocalDefId , CRATE_DEF_ID } ;
5
4
use rustc_hir:: intravisit;
6
5
use rustc_hir:: { HirId , ItemLocalId } ;
6
+ use rustc_index:: bit_set:: GrowableBitSet ;
7
7
use rustc_middle:: hir:: map:: Map ;
8
8
use rustc_middle:: hir:: nested_filter;
9
9
use rustc_middle:: ty:: TyCtxt ;
@@ -15,32 +15,35 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
15
15
crate :: hir_stats:: print_hir_stats ( tcx) ;
16
16
}
17
17
18
- let errors = Lock :: new ( Vec :: new ( ) ) ;
19
- let hir_map = tcx. hir ( ) ;
18
+ #[ cfg( debug_assertions) ]
19
+ {
20
+ let errors = Lock :: new ( Vec :: new ( ) ) ;
21
+ let hir_map = tcx. hir ( ) ;
20
22
21
- hir_map. par_for_each_module ( |module_id| {
22
- let mut v = HirIdValidator {
23
- hir_map,
24
- owner : None ,
25
- hir_ids_seen : Default :: default ( ) ,
26
- errors : & errors,
27
- } ;
23
+ hir_map. par_for_each_module ( |module_id| {
24
+ let mut v = HirIdValidator {
25
+ hir_map,
26
+ owner : None ,
27
+ hir_ids_seen : Default :: default ( ) ,
28
+ errors : & errors,
29
+ } ;
28
30
29
- tcx. hir ( ) . deep_visit_item_likes_in_module ( module_id, & mut v) ;
30
- } ) ;
31
+ tcx. hir ( ) . deep_visit_item_likes_in_module ( module_id, & mut v) ;
32
+ } ) ;
31
33
32
- let errors = errors. into_inner ( ) ;
34
+ let errors = errors. into_inner ( ) ;
33
35
34
- if !errors. is_empty ( ) {
35
- let message = errors. iter ( ) . fold ( String :: new ( ) , |s1, s2| s1 + "\n " + s2) ;
36
- tcx. sess . delay_span_bug ( rustc_span:: DUMMY_SP , & message) ;
36
+ if !errors. is_empty ( ) {
37
+ let message = errors. iter ( ) . fold ( String :: new ( ) , |s1, s2| s1 + "\n " + s2) ;
38
+ tcx. sess . delay_span_bug ( rustc_span:: DUMMY_SP , & message) ;
39
+ }
37
40
}
38
41
}
39
42
40
43
struct HirIdValidator < ' a , ' hir > {
41
44
hir_map : Map < ' hir > ,
42
45
owner : Option < LocalDefId > ,
43
- hir_ids_seen : FxHashSet < ItemLocalId > ,
46
+ hir_ids_seen : GrowableBitSet < ItemLocalId > ,
44
47
errors : & ' a Lock < Vec < String > > ,
45
48
}
46
49
@@ -80,7 +83,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
80
83
if max != self . hir_ids_seen . len ( ) - 1 {
81
84
// Collect the missing ItemLocalIds
82
85
let missing: Vec < _ > = ( 0 ..=max as u32 )
83
- . filter ( |& i| !self . hir_ids_seen . contains ( & ItemLocalId :: from_u32 ( i) ) )
86
+ . filter ( |& i| !self . hir_ids_seen . contains ( ItemLocalId :: from_u32 ( i) ) )
84
87
. collect ( ) ;
85
88
86
89
// Try to map those to something more useful
@@ -106,7 +109,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
106
109
missing_items,
107
110
self . hir_ids_seen
108
111
. iter( )
109
- . map( |& local_id| HirId { owner, local_id } )
112
+ . map( |local_id| HirId { owner, local_id } )
110
113
. map( |h| format!( "({:?} {})" , h, self . hir_map. node_to_string( h) ) )
111
114
. collect:: <Vec <_>>( )
112
115
)
0 commit comments