@@ -121,8 +121,6 @@ struct Scope {
121
121
/// end of the vector (top of the stack) first.
122
122
drops : Vec < DropData > ,
123
123
124
- moved_locals : Vec < Local > ,
125
-
126
124
/// The drop index that will drop everything in and below this scope on an
127
125
/// unwind path.
128
126
cached_unwind_block : Option < DropIdx > ,
@@ -406,7 +404,6 @@ impl<'tcx> Scopes<'tcx> {
406
404
region_scope : region_scope. 0 ,
407
405
region_scope_span : region_scope. 1 . span ,
408
406
drops : vec ! [ ] ,
409
- moved_locals : vec ! [ ] ,
410
407
cached_unwind_block : None ,
411
408
cached_generator_drop_block : None ,
412
409
} ) ;
@@ -904,29 +901,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
904
901
return ;
905
902
}
906
903
907
- Some ( local_scope) => self
908
- . scopes
909
- . scopes
910
- . iter_mut ( )
911
- . rfind ( |scope| scope. region_scope == local_scope)
912
- . unwrap_or_else ( || bug ! ( "scope {:?} not found in scope list!" , local_scope) ) ,
904
+ Some ( local_scope) => {
905
+ let top_scope = self . scopes . scopes . last_mut ( ) . unwrap ( ) ;
906
+ assert ! (
907
+ top_scope. region_scope == local_scope,
908
+ "local scope ({:?}) is not the topmost scope!" ,
909
+ local_scope
910
+ ) ;
911
+
912
+ top_scope
913
+ }
913
914
} ;
914
915
915
916
// look for moves of a local variable, like `MOVE(_X)`
916
- let locals_moved = operands. iter ( ) . flat_map ( |operand| match operand {
917
- Operand :: Copy ( _) | Operand :: Constant ( _) => None ,
918
- Operand :: Move ( place) => place. as_local ( ) ,
919
- } ) ;
917
+ let locals_moved = operands
918
+ . iter ( )
919
+ . filter_map ( |operand| match operand {
920
+ Operand :: Copy ( _) | Operand :: Constant ( _) => None ,
921
+ Operand :: Move ( place) => place. as_local ( ) ,
922
+ } )
923
+ . collect :: < FxHashSet < _ > > ( ) ;
920
924
921
- for local in locals_moved {
922
- // check if we have a Drop for this operand and -- if so
923
- // -- add it to the list of moved operands. Note that this
924
- // local might not have been an operand created for this
925
- // call, it could come from other places too.
926
- if scope. drops . iter ( ) . any ( |drop| drop. local == local && drop. kind == DropKind :: Value ) {
927
- scope. moved_locals . push ( local) ;
928
- }
929
- }
925
+ // Remove the drops for the moved operands.
926
+ scope
927
+ . drops
928
+ . retain ( |drop| drop. kind == DropKind :: Storage || !locals_moved. contains ( & drop. local ) ) ;
929
+ scope. invalidate_cache ( ) ;
930
930
}
931
931
932
932
// Other
@@ -1174,14 +1174,6 @@ fn build_scope_drops<'tcx>(
1174
1174
debug_assert_eq ! ( unwind_drops. drops[ unwind_to] . 0 . kind, drop_data. kind) ;
1175
1175
unwind_to = unwind_drops. drops [ unwind_to] . 1 ;
1176
1176
1177
- // If the operand has been moved, and we are not on an unwind
1178
- // path, then don't generate the drop. (We only take this into
1179
- // account for non-unwind paths so as not to disturb the
1180
- // caching mechanism.)
1181
- if scope. moved_locals . iter ( ) . any ( |& o| o == local) {
1182
- continue ;
1183
- }
1184
-
1185
1177
unwind_drops. add_entry ( block, unwind_to) ;
1186
1178
1187
1179
let next = cfg. start_new_block ( ) ;
0 commit comments