1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // General test of maybe_inits state computed by MIR dataflow.
14 #![feature(core_intrinsics, rustc_attrs)]
16 use std::intrinsics::rustc_peek;
17 use std::mem::{drop, replace};
21 #[rustc_mir(rustc_peek_maybe_init,stop_after_dataflow)]
22 fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
24 // `ret` starts off uninitialized, so we get an error report here.
25 unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
27 // All function formal parameters start off initialized.
29 unsafe { rustc_peek(&x) };
30 unsafe { rustc_peek(&y) };
31 unsafe { rustc_peek(&z) };
34 ::std::mem::replace(x, y)
41 // `z` may be initialized here.
42 unsafe { rustc_peek(&z); }
44 // `y` is definitely uninitialized here.
45 unsafe { rustc_peek(&y); } //~ ERROR rustc_peek: bit not set
47 // `x` is still (definitely) initialized (replace above is a reborrow).
48 unsafe { rustc_peek(&x); }
52 // `x` is *definitely* uninitialized here
53 unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
55 // `ret` is now definitely initialized (via `if` above).
56 unsafe { rustc_peek(&ret); }
62 foo(true, &mut S(13), S(14), S(15));
63 foo(false, &mut S(13), S(14), S(15));