Skip to content

Commit 7b02f69

Browse files
committed
in copy_prop, we should only ignore storage statement
1 parent 9513b89 commit 7b02f69

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);
@@ -206,19 +206,9 @@ struct StorageChecker<'a, 'tcx> {
206206

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

223213
let head = self.copy_classes[local];
224214

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)