1 // General test of maybe_uninits state computed by MIR dataflow.
4 #![feature(core_intrinsics, rustc_attrs)]
6 use std::intrinsics::rustc_peek;
7 use std::mem::{drop, replace};
11 #[rustc_mir(rustc_peek_definite_init,stop_after_dataflow)]
12 fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
14 // `ret` starts off uninitialized
15 unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
17 // All function formal parameters start off initialized.
19 unsafe { rustc_peek(&x) };
20 unsafe { rustc_peek(&y) };
21 unsafe { rustc_peek(&z) };
24 ::std::mem::replace(x, y)
30 // `z` may be uninitialized here.
31 unsafe { rustc_peek(&z); } //~ ERROR rustc_peek: bit not set
33 // `y` is definitely uninitialized here.
34 unsafe { rustc_peek(&y); } //~ ERROR rustc_peek: bit not set
36 // `x` is still (definitely) initialized (replace above is a reborrow).
37 unsafe { rustc_peek(&x); }
41 // `x` is *definitely* uninitialized here
42 unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
44 // `ret` is now definitely initialized (via `if` above).
45 unsafe { rustc_peek(&ret); }
50 foo(true, &mut S(13), S(14), S(15));
51 foo(false, &mut S(13), S(14), S(15));