3 #![allow(unused_mut)] // under NLL we get warning about `x` below: rust-lang/rust#54499
5 // This test is bogus (i.e., should be check-fail) during the period
6 // where #54986 is implemented and #54987 is *not* implemented. For
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`.)
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
26 let mut x: (Void, usize);
30 // Make sure `y` stays on the stack.
31 test::black_box(&mut y);
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");
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>());