1 // General test of maybe_inits 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_maybe_init,stop_after_dataflow)]
12 fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
14 // `ret` starts off uninitialized, so we get an error report here.
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)
31 // `z` may be initialized here.
32 unsafe { rustc_peek(&z); }
34 // `y` is definitely uninitialized here.
35 unsafe { rustc_peek(&y); } //~ ERROR rustc_peek: bit not set
37 // `x` is still (definitely) initialized (replace above is a reborrow).
38 unsafe { rustc_peek(&x); }
42 // `x` is *definitely* uninitialized here
43 unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
45 // `ret` is now definitely initialized (via `if` above).
46 unsafe { rustc_peek(&ret); }
52 foo(true, &mut S(13), S(14), S(15));
53 foo(false, &mut S(13), S(14), S(15));