1
1
use crate :: deref_separator:: deref_finder;
2
2
use crate :: MirPass ;
3
- use rustc_data_structures:: fx:: FxHashMap ;
4
3
use rustc_index:: bit_set:: BitSet ;
4
+ use rustc_index:: IndexVec ;
5
5
use rustc_middle:: mir:: patch:: MirPatch ;
6
6
use rustc_middle:: mir:: * ;
7
7
use rustc_middle:: ty:: { self , TyCtxt } ;
@@ -84,12 +84,13 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
84
84
85
85
let reachable = traversal:: reachable_as_bitset ( body) ;
86
86
87
+ let drop_flags = IndexVec :: from_elem ( None , & env. move_data . move_paths ) ;
87
88
ElaborateDropsCtxt {
88
89
tcx,
89
90
body,
90
91
env : & env,
91
92
init_data : InitializationData { inits, uninits } ,
92
- drop_flags : Default :: default ( ) ,
93
+ drop_flags,
93
94
patch : MirPatch :: new ( body) ,
94
95
un_derefer : un_derefer,
95
96
reachable,
@@ -293,7 +294,7 @@ struct ElaborateDropsCtxt<'a, 'tcx> {
293
294
body : & ' a Body < ' tcx > ,
294
295
env : & ' a MoveDataParamEnv < ' tcx > ,
295
296
init_data : InitializationData < ' a , ' tcx > ,
296
- drop_flags : FxHashMap < MovePathIndex , Local > ,
297
+ drop_flags : IndexVec < MovePathIndex , Option < Local > > ,
297
298
patch : MirPatch < ' tcx > ,
298
299
un_derefer : UnDerefer < ' tcx > ,
299
300
reachable : BitSet < BasicBlock > ,
@@ -312,11 +313,11 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
312
313
let tcx = self . tcx ;
313
314
let patch = & mut self . patch ;
314
315
debug ! ( "create_drop_flag({:?})" , self . body. span) ;
315
- self . drop_flags . entry ( index) . or_insert_with ( || patch. new_internal ( tcx. types . bool , span) ) ;
316
+ self . drop_flags [ index] . get_or_insert_with ( || patch. new_internal ( tcx. types . bool , span) ) ;
316
317
}
317
318
318
319
fn drop_flag ( & mut self , index : MovePathIndex ) -> Option < Place < ' tcx > > {
319
- self . drop_flags . get ( & index) . map ( |t| Place :: from ( * t ) )
320
+ self . drop_flags [ index] . map ( Place :: from)
320
321
}
321
322
322
323
/// create a patch that elaborates all drops in the input
@@ -463,7 +464,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
463
464
}
464
465
465
466
fn set_drop_flag ( & mut self , loc : Location , path : MovePathIndex , val : DropFlagState ) {
466
- if let Some ( & flag) = self . drop_flags . get ( & path) {
467
+ if let Some ( flag) = self . drop_flags [ path] {
467
468
let span = self . patch . source_info_for_location ( self . body , loc) . span ;
468
469
let val = self . constant_bool ( span, val. value ( ) ) ;
469
470
self . patch . add_assign ( loc, Place :: from ( flag) , val) ;
@@ -474,7 +475,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
474
475
let loc = Location :: START ;
475
476
let span = self . patch . source_info_for_location ( self . body , loc) . span ;
476
477
let false_ = self . constant_bool ( span, false ) ;
477
- for flag in self . drop_flags . values ( ) {
478
+ for flag in self . drop_flags . iter ( ) . flatten ( ) {
478
479
self . patch . add_assign ( loc, Place :: from ( * flag) , false_. clone ( ) ) ;
479
480
}
480
481
}
0 commit comments