-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Primitive binops are translated wrong when the LHS is mutated #27054
Comments
Looks like this is specifically an issue with the implementation of expr::trans_binary: Rust semantics say the value is supposed to be immediately loaded into a temporary, but expr::trans just returns a pointer into the Box. |
triage: I-nominated |
Some more testcases: fn main() {
let x = Box::new(0);
let mut y = 0;
*{ drop(x); let _ = Box::new(main); &mut y } = *x;
println!("{}", y);
} #[derive(Debug, Copy, Clone)]
struct CoolInt(i32);
impl std::ops::Add<CoolInt> for CoolInt {
type Output = CoolInt;
fn add(self, other: CoolInt) -> CoolInt { CoolInt(self.0 + other.0) }
}
fn main() {
let x = Box::new(CoolInt(0));
let mut y = CoolInt(0);
println!("{:?}", *x + *{ drop(x); let _ = Box::new(main); &mut y });
} struct R { x: i32, y: i32, z: i32 }
fn main() {
let x = Box::new(0);
let r = R { x: 0, y: 0, z: 0 };
let r = R { x: *x, y: { drop(x); let _ = Box::new(main); 0 }, ..r};
println!("{} {} {}", r.x, r.y, r.z);
} fn main() {
let x = Box::new(0);
let mut y = 0;
*{ drop(x); &mut y } += *x;
println!("{}", y);
} |
Your augmented assignment example is actually an order-of-operations mismatch - a different issue. |
Related to #28160 |
triage: P-medium |
Looks like this is fixed by MIR. |
Verified as fixed by MIR, marking as E-needstest. Edit: Well, verified as fixed. No idea if it was by MIR, though. |
Yes, MIR would've fixed this. |
…hton Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes rust-lang#10876. Closes rust-lang#22892. Closes rust-lang#26448. Closes rust-lang#26577. Closes rust-lang#26619. Closes rust-lang#27054. Closes rust-lang#28587. Closes rust-lang#44127. Closes rust-lang#44255. Closes rust-lang#55731. Closes rust-lang#57781.
…hton Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes rust-lang#10876. Closes rust-lang#22892. Closes rust-lang#26448. Closes rust-lang#26577. Closes rust-lang#26619. Closes rust-lang#27054. Closes rust-lang#28587. Closes rust-lang#44127. Closes rust-lang#44255. Closes rust-lang#55731. Closes rust-lang#57781.
…hton Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes rust-lang#10876. Closes rust-lang#22892. Closes rust-lang#26448. Closes rust-lang#26577. Closes rust-lang#26619. Closes rust-lang#27054. Closes rust-lang#28587. Closes rust-lang#44127. Closes rust-lang#44255. Closes rust-lang#55731. Closes rust-lang#57781.
…hton Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes rust-lang#10876. Closes rust-lang#22892. Closes rust-lang#26448. Closes rust-lang#26577. Closes rust-lang#26619. Closes rust-lang#27054. Closes rust-lang#28587. Closes rust-lang#44127. Closes rust-lang#44255. Closes rust-lang#55731. Closes rust-lang#57781.
Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes #10876. Closes #26448. Closes #26577. Closes #26619. Closes #27054. Closes #44127. Closes #44255. Closes #55731. Closes #57781.
…hton Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes rust-lang#10876. Closes rust-lang#26448. Closes rust-lang#26577. Closes rust-lang#26619. Closes rust-lang#27054. Closes rust-lang#44127. Closes rust-lang#44255. Closes rust-lang#55731. Closes rust-lang#57781.
Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes #10876. Closes #26448. Closes #26577. Closes #26619. Closes #27054. Closes #44127. Closes #44255. Closes #55731. Closes #57781.
STR
Expected Results
If this code compiles, it should print
0
.Actual Results
Garbage is printed (the address of
main
, in fact).The text was updated successfully, but these errors were encountered: