Skip to content

Commit aaca6b1

Browse files
committed
in copy_prop, we should only ignore storage statement
1 parent f01bda9 commit aaca6b1

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp {
6161

6262
// If the local is borrowed, we cannot easily determine if it is used, so we have to remove the storage statements.
6363
let borrowed_locals = ssa.borrowed_locals();
64-
64+
6565
for (local, &head) in ssa.copy_classes().iter_enumerated() {
6666
if local != head && borrowed_locals.contains(local) {
6767
storage_to_remove.insert(head);
@@ -203,19 +203,9 @@ struct StorageChecker<'a, 'tcx> {
203203

204204
impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
205205
fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) {
206-
// We don't need to check storage statements and statements for which the local doesn't need to be initialized.
207-
match context {
208-
PlaceContext::MutatingUse(
209-
MutatingUseContext::Store
210-
| MutatingUseContext::Call
211-
| MutatingUseContext::Yield
212-
| MutatingUseContext::AsmOutput,
213-
)
214-
| PlaceContext::NonUse(_) => {
215-
return;
216-
}
217-
_ => {}
218-
};
206+
if !context.is_use() {
207+
return;
208+
}
219209

220210
let head = self.copy_classes[local];
221211

tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ pub fn g() -> usize {
5353
Return()
5454
}
5555
}
56-
}
56+
}

0 commit comments

Comments
 (0)