@@ -84,7 +84,7 @@ that contains only loops and breakable blocks. It tracks where a `break`,
8484use std:: mem;
8585
8686use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder , CFG } ;
87- use rustc_data_structures:: fx:: FxHashMap ;
87+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
8888use rustc_hir:: HirId ;
8989use rustc_index:: { IndexSlice , IndexVec } ;
9090use rustc_middle:: middle:: region;
@@ -1195,15 +1195,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11951195 assert_eq ! ( scope. region_scope, local_scope, "local scope is not the topmost scope!" , ) ;
11961196
11971197 // look for moves of a local variable, like `MOVE(_X)`
1198- let locals_moved = operands. iter ( ) . flat_map ( |operand| match operand {
1199- Operand :: Copy ( _) | Operand :: Constant ( _) => None ,
1200- Operand :: Move ( place) => place. as_local ( ) ,
1201- } ) ;
1198+ let locals_moved: FxHashSet < Local > = operands
1199+ . iter ( )
1200+ . flat_map ( |operand| match operand {
1201+ Operand :: Copy ( _) | Operand :: Constant ( _) => None ,
1202+ Operand :: Move ( place) => place. as_local ( ) ,
1203+ } )
1204+ . collect ( ) ;
12021205
1203- for local in locals_moved {
1204- // Unschedule drops from the scope.
1205- scope . drops . retain ( |drop| drop . local != local || drop . kind != DropKind :: Value ) ;
1206- }
1206+ // Unschedule drops from the scope.
1207+ scope
1208+ . drops
1209+ . retain ( |drop| drop . kind != DropKind :: Value || !locals_moved . contains ( & drop . local ) ) ;
12071210 scope. invalidate_cache ( ) ;
12081211 }
12091212
0 commit comments