Skip to content

Commit f01bda9

Browse files
committed
Move borrowed_locals filtering out of StorageChecker
1 parent 2d8df03 commit f01bda9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,22 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp {
5959
let storage_to_remove = if tcx.sess.emit_lifetime_markers() {
6060
storage_to_remove.clear();
6161

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+
6271
let maybe_uninit = MaybeUninitializedLocals::new()
6372
.iterate_to_fixpoint(tcx, body, Some("mir_opt::copy_prop"))
6473
.into_results_cursor(body);
6574

6675
let mut storage_checker = StorageChecker {
6776
maybe_uninit,
6877
copy_classes: ssa.copy_classes(),
69-
borrowed_locals: ssa.borrowed_locals(),
7078
storage_to_remove,
7179
};
7280

@@ -190,7 +198,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
190198
struct StorageChecker<'a, 'tcx> {
191199
maybe_uninit: ResultsCursor<'a, 'tcx, MaybeUninitializedLocals>,
192200
copy_classes: &'a IndexSlice<Local, Local>,
193-
borrowed_locals: &'a DenseBitSet<Local>,
194201
storage_to_remove: DenseBitSet<Local>,
195202
}
196203

@@ -217,12 +224,6 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
217224
return;
218225
}
219226

220-
// If the local is borrowed, we cannot easily determine if it is used, so we have to remove the storage statements.
221-
if self.borrowed_locals.contains(local) {
222-
self.storage_to_remove.insert(head);
223-
return;
224-
}
225-
226227
self.maybe_uninit.seek_before_primary_effect(loc);
227228

228229
if self.maybe_uninit.get().contains(head) {

0 commit comments

Comments
 (0)