@@ -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;
@@ -1103,15 +1103,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11031103 assert_eq ! ( scope. region_scope, local_scope, "local scope is not the topmost scope!" , ) ;
11041104
11051105 // look for moves of a local variable, like `MOVE(_X)`
1106- let locals_moved = operands. iter ( ) . flat_map ( |operand| match operand {
1107- Operand :: Copy ( _) | Operand :: Constant ( _) => None ,
1108- Operand :: Move ( place) => place. as_local ( ) ,
1109- } ) ;
1106+ let locals_moved: FxHashSet < Local > = operands
1107+ . iter ( )
1108+ . flat_map ( |operand| match operand {
1109+ Operand :: Copy ( _) | Operand :: Constant ( _) => None ,
1110+ Operand :: Move ( place) => place. as_local ( ) ,
1111+ } )
1112+ . collect ( ) ;
11101113
1111- for local in locals_moved {
1112- // Unschedule drops from the scope.
1113- scope . drops . retain ( |drop| drop . local != local || drop . kind != DropKind :: Value ) ;
1114- }
1114+ // Unschedule drops from the scope.
1115+ scope
1116+ . drops
1117+ . retain ( |drop| drop . kind != DropKind :: Value || !locals_moved . contains ( & drop . local ) ) ;
11151118 scope. invalidate_cache ( ) ;
11161119 }
11171120
0 commit comments