]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
83c7162d | 2 | #![feature(test)] |
0bf4aa26 XL |
3 | #![allow(unused_mut)] // under NLL we get warning about `x` below: rust-lang/rust#54499 |
4 | ||
5869c6ff | 5 | // This test is bogus (i.e., should be check-fail) during the period |
0bf4aa26 | 6 | // where #54986 is implemented and #54987 is *not* implemented. For |
48663c56 | 7 | // now: just ignore it |
0bf4aa26 | 8 | // |
48663c56 | 9 | // ignore-test |
0bf4aa26 XL |
10 | |
11 | // This test is checking that the space allocated for `x.1` does not | |
12 | // overlap with `y`. (The reason why such a thing happened at one | |
13 | // point was because `x.0: Void` and thus the whole type of `x` was | |
14 | // uninhabited, and so the compiler thought it was safe to use the | |
15 | // space of `x.1` to hold `y`.) | |
16 | // | |
17 | // That's a fine thing to test when this code is accepted by the | |
18 | // compiler, and this code is being transcribed accordingly into | |
19 | // the ui test issue-21232-partial-init-and-use.rs | |
83c7162d XL |
20 | |
21 | extern crate test; | |
22 | ||
23 | enum Void {} | |
24 | ||
25 | fn main() { | |
26 | let mut x: (Void, usize); | |
27 | let mut y = 42; | |
28 | x.1 = 13; | |
29 | ||
30 | // Make sure `y` stays on the stack. | |
31 | test::black_box(&mut y); | |
32 | ||
33 | // Check that the write to `x.1` did not overwrite `y`. | |
34 | // Note that this doesn't fail with optimizations enabled, | |
35 | // because we can't keep `x.1` on the stack, like we can `y`, | |
36 | // as we can't borrow partially initialized variables. | |
37 | assert_eq!(y.to_string(), "42"); | |
38 | ||
39 | // Check that `(Void, usize)` has space for the `usize` field. | |
40 | assert_eq!(std::mem::size_of::<(Void, usize)>(), | |
41 | std::mem::size_of::<usize>()); | |
42 | } |