Skip to content

Commit 4b6a482

Browse files
Fix dest prop miscompilation around references
1 parent e0bc267 commit 4b6a482

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/rustc_mir/src/transform/dest_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
905905
// FIXME: This can be smarter and take `StorageDead` into account (which
906906
// invalidates borrows).
907907
if self.ever_borrowed_locals.contains(dest.local)
908-
&& self.ever_borrowed_locals.contains(src.local)
908+
|| self.ever_borrowed_locals.contains(src.local)
909909
{
910910
return;
911911
}

src/test/ui/issues/issue-77002.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -Zmir-opt-level=2 -Copt-level=0
2+
// run-pass
3+
4+
type M = [i64; 2];
5+
6+
fn f(a: &M) -> M {
7+
let mut b: M = M::default();
8+
b[0] = a[0] * a[0];
9+
b
10+
}
11+
12+
fn main() {
13+
let mut a: M = [1, 1];
14+
a = f(&a);
15+
assert_eq!(a[0], 1);
16+
}

0 commit comments

Comments
 (0)