@@ -59,14 +59,22 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp {
59
59
let storage_to_remove = if tcx. sess . emit_lifetime_markers ( ) {
60
60
storage_to_remove. clear ( ) ;
61
61
62
+ // If the local is borrowed, we cannot easily determine if it is used, so we have to remove the storage statements.
63
+ let borrowed_locals = ssa. borrowed_locals ( ) ;
64
+
65
+ for ( local, & head) in ssa. copy_classes ( ) . iter_enumerated ( ) {
66
+ if local != head && borrowed_locals. contains ( local) {
67
+ storage_to_remove. insert ( head) ;
68
+ }
69
+ }
70
+
62
71
let maybe_uninit = MaybeUninitializedLocals :: new ( )
63
72
. iterate_to_fixpoint ( tcx, body, Some ( "mir_opt::copy_prop" ) )
64
73
. into_results_cursor ( body) ;
65
74
66
75
let mut storage_checker = StorageChecker {
67
76
maybe_uninit,
68
77
copy_classes : ssa. copy_classes ( ) ,
69
- borrowed_locals : ssa. borrowed_locals ( ) ,
70
78
storage_to_remove,
71
79
} ;
72
80
@@ -193,7 +201,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
193
201
struct StorageChecker < ' a , ' tcx > {
194
202
maybe_uninit : ResultsCursor < ' a , ' tcx , MaybeUninitializedLocals > ,
195
203
copy_classes : & ' a IndexSlice < Local , Local > ,
196
- borrowed_locals : & ' a DenseBitSet < Local > ,
197
204
storage_to_remove : DenseBitSet < Local > ,
198
205
}
199
206
@@ -220,12 +227,6 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
220
227
return ;
221
228
}
222
229
223
- // If the local is borrowed, we cannot easily determine if it is used, so we have to remove the storage statements.
224
- if self . borrowed_locals . contains ( local) {
225
- self . storage_to_remove . insert ( head) ;
226
- return ;
227
- }
228
-
229
230
self . maybe_uninit . seek_before_primary_effect ( loc) ;
230
231
231
232
if self . maybe_uninit . get ( ) . contains ( head) {
0 commit comments