https://github.com/rust-lang/rust/pull/71911 introduced a (nightly-to-nightly) regression in mir-opt-level=3: since that landed, this assertion fails when running the test in Miri.
https://github.com/rust-lang/rust/issues/73223 is also still reproducible with mir-opt-level=2, but @oli-obk said there's a plan to hide it behind a flag that better expresses "this can and will break valid code".
In fact even level 2 is broken.
... and level 1, for the union issue (so let's treat the other one separately).
This doesn't require nightly after all, we have a stable-to-nightly regression when just running this code:
fn main() {
#[allow(dead_code)]
union U {
f1: u32,
f2: f32,
}
let mut u = U { f1: 1 };
unsafe {
let b1 = &mut u.f1;
*b1 = 5;
}
assert_eq!(unsafe { u.f1 }, 5);
}
gives
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `1`,
right: `5`', src/main.rs:12:5
In fact we don't even need a union, nor an unsafe block:
fn main() {
#[allow(dead_code)]
struct U {
f1: u32,
f2: f32,
}
let mut u = U { f1: 1, f2: 1.0 };
let b1 = &mut u.f1;
*b1 = 5;
assert_eq!( { u.f1 }, 5);
}
Minimized:
fn main() {
let mut u = (1,);
*&mut u.0 = 5;
assert_eq!( { u.0 }, 5);
}
on it
giving this p-critical based on our discussion
Why is this regression-from-stable-to-beta
when the offending PR only merged last night?
@RalfJung: Why didn't the assertion failure cause a Miri toolstate change?
I think this is stable-to-nightly only... @oli-obk why did you change that?
@Aaron1011 rustc's CI currently only tests Miri with mir-opt-level=0.
I tested it in the playground and I thought it also happened on beta?
Hmm... not sure what happened, must have mis-clicked on the playground
Most helpful comment
Hmm... not sure what happened, must have mis-clicked on the playground