]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/zst.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / pass / zst.rs
1 //@compile-flags: -Zmiri-permissive-provenance
2 #[derive(PartialEq, Debug)]
3 struct A;
4
5 fn zst_ret() -> A {
6     A
7 }
8
9 fn use_zst() -> A {
10     let a = A;
11     a
12 }
13
14 fn main() {
15     // Not using the () type here, as writes of that type do not even have MIR generated.
16     // Also not assigning directly as that's array initialization, not assignment.
17     let zst_val = [1u8; 0];
18
19     assert_eq!(zst_ret(), A);
20     assert_eq!(use_zst(), A);
21     let x = 42 as *mut [u8; 0];
22     // Reading and writing is ok.
23     unsafe {
24         *x = zst_val;
25     }
26     unsafe {
27         let _y = *x;
28     }
29 }