about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/zst.rs
blob: a56386a691f8dfb3c39908c74977c45703b64d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//@compile-flags: -Zmiri-permissive-provenance
#[derive(PartialEq, Debug)]
struct A;

fn zst_ret() -> A {
    A
}

fn use_zst() -> A {
    let a = A;
    a
}

fn main() {
    // Not using the () type here, as writes of that type do not even have MIR generated.
    // Also not assigning directly as that's array initialization, not assignment.
    let zst_val = [1u8; 0];

    assert_eq!(zst_ret(), A);
    assert_eq!(use_zst(), A);
    let x = 42 as *mut [u8; 0];
    // Reading and writing is ok.
    unsafe {
        *x = zst_val;
    }
    unsafe {
        let _y = *x;
    }
}