Skip to content

Commit ba24c31

Browse files
committed
Auto merge of #2077 - RalfJung:more-test, r=RalfJung
add some more tests
2 parents c9039de + e214e6d commit ba24c31

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tests/run-pass/issue-miri-2068-2.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-flags: -Zmiri-disable-validation
2+
3+
use std::mem::MaybeUninit;
4+
5+
fn main() { unsafe {
6+
let mut x = MaybeUninit::<i64>::uninit();
7+
// Put in a ptr.
8+
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
9+
// Overwrite parts of that pointer with 'uninit' through a Scalar.
10+
let ptr = x.as_mut_ptr().cast::<i32>();
11+
*ptr = MaybeUninit::uninit().assume_init();
12+
// Reading this back should hence work fine.
13+
let _c = *ptr;
14+
} }

tests/run-pass/stacked-borrows/stacked-borrows.rs

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn main() {
1616
disjoint_mutable_subborrows();
1717
raw_ref_to_part();
1818
array_casts();
19+
mut_below_shr();
1920
}
2021

2122
// Make sure that reading from an `&mut` does, like reborrowing to `&`,
@@ -186,3 +187,12 @@ fn array_casts() {
186187
let p = &x as *const usize;
187188
assert_eq!(unsafe { *p.add(1) }, 1);
188189
}
190+
191+
/// Transmuting &&i32 to &&mut i32 is fine.
192+
fn mut_below_shr() {
193+
let x = 0;
194+
let y = &x;
195+
let p = unsafe { core::mem::transmute::<&&i32,&&mut i32>(&y) };
196+
let r = &**p;
197+
let _val = *r;
198+
}

0 commit comments

Comments
 (0)