diff --git a/tests/run-pass/issue-miri-2068-2.rs b/tests/run-pass/issue-miri-2068-2.rs new file mode 100644 index 0000000000..45b2004e33 --- /dev/null +++ b/tests/run-pass/issue-miri-2068-2.rs @@ -0,0 +1,14 @@ +// compile-flags: -Zmiri-disable-validation + +use std::mem::MaybeUninit; + +fn main() { unsafe { + let mut x = MaybeUninit::::uninit(); + // Put in a ptr. + x.as_mut_ptr().cast::<&i32>().write_unaligned(&0); + // Overwrite parts of that pointer with 'uninit' through a Scalar. + let ptr = x.as_mut_ptr().cast::(); + *ptr = MaybeUninit::uninit().assume_init(); + // Reading this back should hence work fine. + let _c = *ptr; +} } diff --git a/tests/run-pass/stacked-borrows/stacked-borrows.rs b/tests/run-pass/stacked-borrows/stacked-borrows.rs index 8aea945f90..b63f9addb0 100644 --- a/tests/run-pass/stacked-borrows/stacked-borrows.rs +++ b/tests/run-pass/stacked-borrows/stacked-borrows.rs @@ -16,6 +16,7 @@ fn main() { disjoint_mutable_subborrows(); raw_ref_to_part(); array_casts(); + mut_below_shr(); } // Make sure that reading from an `&mut` does, like reborrowing to `&`, @@ -186,3 +187,12 @@ fn array_casts() { let p = &x as *const usize; assert_eq!(unsafe { *p.add(1) }, 1); } + +/// Transmuting &&i32 to &&mut i32 is fine. +fn mut_below_shr() { + let x = 0; + let y = &x; + let p = unsafe { core::mem::transmute::<&&i32,&&mut i32>(&y) }; + let r = &**p; + let _val = *r; +}