2
2
// closely. The idea is that all reachable symbols are live, codes called
3
3
// from live codes are live, and everything else is dead.
4
4
5
+ use hir:: def_id:: { LocalDefIdMap , LocalDefIdSet } ;
5
6
use itertools:: Itertools ;
6
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
7
7
use rustc_errors:: MultiSpan ;
8
8
use rustc_hir as hir;
9
9
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
@@ -45,17 +45,17 @@ struct MarkSymbolVisitor<'tcx> {
45
45
worklist : Vec < LocalDefId > ,
46
46
tcx : TyCtxt < ' tcx > ,
47
47
maybe_typeck_results : Option < & ' tcx ty:: TypeckResults < ' tcx > > ,
48
- live_symbols : FxHashSet < LocalDefId > ,
48
+ live_symbols : LocalDefIdSet ,
49
49
repr_has_repr_c : bool ,
50
50
repr_has_repr_simd : bool ,
51
51
in_pat : bool ,
52
52
ignore_variant_stack : Vec < DefId > ,
53
53
// maps from tuple struct constructors to tuple struct items
54
- struct_constructors : FxHashMap < LocalDefId , LocalDefId > ,
54
+ struct_constructors : LocalDefIdMap < LocalDefId > ,
55
55
// maps from ADTs to ignored derived traits (e.g. Debug and Clone)
56
56
// and the span of their respective impl (i.e., part of the derive
57
57
// macro)
58
- ignored_derived_traits : FxHashMap < LocalDefId , Vec < ( DefId , DefId ) > > ,
58
+ ignored_derived_traits : LocalDefIdMap < Vec < ( DefId , DefId ) > > ,
59
59
}
60
60
61
61
impl < ' tcx > MarkSymbolVisitor < ' tcx > {
@@ -237,7 +237,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
237
237
}
238
238
239
239
fn mark_live_symbols ( & mut self ) {
240
- let mut scanned = FxHashSet :: default ( ) ;
240
+ let mut scanned = LocalDefIdSet :: default ( ) ;
241
241
while let Some ( id) = self . worklist . pop ( ) {
242
242
if !scanned. insert ( id) {
243
243
continue ;
@@ -371,7 +371,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
371
371
}
372
372
if tcx. visibility ( def_id) . is_public ( ) { Some ( def_id) } else { None }
373
373
} ) ;
374
- self . live_symbols . extend ( live_fields) ;
374
+ Extend :: extend ( & mut self . live_symbols , live_fields) ;
375
375
376
376
intravisit:: walk_struct_def ( self , def) ;
377
377
}
@@ -506,7 +506,7 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool
506
506
fn check_item < ' tcx > (
507
507
tcx : TyCtxt < ' tcx > ,
508
508
worklist : & mut Vec < LocalDefId > ,
509
- struct_constructors : & mut FxHashMap < LocalDefId , LocalDefId > ,
509
+ struct_constructors : & mut LocalDefIdMap < LocalDefId > ,
510
510
id : hir:: ItemId ,
511
511
) {
512
512
let allow_dead_code = has_allow_dead_code_or_lang_attr ( tcx, id. owner_id . def_id ) ;
@@ -583,9 +583,7 @@ fn check_foreign_item(tcx: TyCtxt<'_>, worklist: &mut Vec<LocalDefId>, id: hir::
583
583
}
584
584
}
585
585
586
- fn create_and_seed_worklist (
587
- tcx : TyCtxt < ' _ > ,
588
- ) -> ( Vec < LocalDefId > , FxHashMap < LocalDefId , LocalDefId > ) {
586
+ fn create_and_seed_worklist ( tcx : TyCtxt < ' _ > ) -> ( Vec < LocalDefId > , LocalDefIdMap < LocalDefId > ) {
589
587
let effective_visibilities = & tcx. effective_visibilities ( ( ) ) ;
590
588
// see `MarkSymbolVisitor::struct_constructors`
591
589
let mut struct_constructors = Default :: default ( ) ;
@@ -617,7 +615,7 @@ fn create_and_seed_worklist(
617
615
fn live_symbols_and_ignored_derived_traits (
618
616
tcx : TyCtxt < ' _ > ,
619
617
( ) : ( ) ,
620
- ) -> ( FxHashSet < LocalDefId > , FxHashMap < LocalDefId , Vec < ( DefId , DefId ) > > ) {
618
+ ) -> ( LocalDefIdSet , LocalDefIdMap < Vec < ( DefId , DefId ) > > ) {
621
619
let ( worklist, struct_constructors) = create_and_seed_worklist ( tcx) ;
622
620
let mut symbol_visitor = MarkSymbolVisitor {
623
621
worklist,
@@ -629,7 +627,7 @@ fn live_symbols_and_ignored_derived_traits(
629
627
in_pat : false ,
630
628
ignore_variant_stack : vec ! [ ] ,
631
629
struct_constructors,
632
- ignored_derived_traits : FxHashMap :: default ( ) ,
630
+ ignored_derived_traits : Default :: default ( ) ,
633
631
} ;
634
632
symbol_visitor. mark_live_symbols ( ) ;
635
633
( symbol_visitor. live_symbols , symbol_visitor. ignored_derived_traits )
@@ -643,8 +641,8 @@ struct DeadVariant {
643
641
644
642
struct DeadVisitor < ' tcx > {
645
643
tcx : TyCtxt < ' tcx > ,
646
- live_symbols : & ' tcx FxHashSet < LocalDefId > ,
647
- ignored_derived_traits : & ' tcx FxHashMap < LocalDefId , Vec < ( DefId , DefId ) > > ,
644
+ live_symbols : & ' tcx LocalDefIdSet ,
645
+ ignored_derived_traits : & ' tcx LocalDefIdMap < Vec < ( DefId , DefId ) > > ,
648
646
}
649
647
650
648
enum ShouldWarnAboutField {
0 commit comments