]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/ub-int-array.rs
Special sync of 'e89801553ddbaccdeb2eac4db08900edb51ac7ff'
[rust.git] / src / test / ui / consts / const-eval / ub-int-array.rs
1 #![allow(const_err)] // make sure we cannot allow away the errors tested here
2
3 //! Test the "array of int" fast path in validity checking, and in particular whether it
4 //! points at the right array element.
5
6 use std::mem;
7
8 #[repr(C)]
9 union MaybeUninit<T: Copy> {
10     uninit: (),
11     init: T,
12 }
13
14 const UNINIT_INT_0: [u32; 3] = unsafe {
15 //~^ ERROR it is undefined behavior to use this value
16 //~| type validation failed: encountered uninitialized bytes at [0]
17     [
18         MaybeUninit { uninit: () }.init,
19         1,
20         2,
21     ]
22 };
23 const UNINIT_INT_1: [u32; 3] = unsafe {
24 //~^ ERROR it is undefined behavior to use this value
25 //~| type validation failed: encountered uninitialized bytes at [1]
26     mem::transmute(
27         [
28             0u8,
29             0u8,
30             0u8,
31             0u8,
32             1u8,
33             MaybeUninit { uninit: () }.init,
34             1u8,
35             1u8,
36             2u8,
37             2u8,
38             MaybeUninit { uninit: () }.init,
39             2u8,
40         ]
41     )
42 };
43 const UNINIT_INT_2: [u32; 3] = unsafe {
44 //~^ ERROR it is undefined behavior to use this value
45 //~| type validation failed: encountered uninitialized bytes at [2]
46     mem::transmute(
47         [
48             0u8,
49             0u8,
50             0u8,
51             0u8,
52             1u8,
53             1u8,
54             1u8,
55             1u8,
56             2u8,
57             2u8,
58             2u8,
59             MaybeUninit { uninit: () }.init,
60         ]
61     )
62 };
63
64 fn main() {}