]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs
Merge commit 'e214ea82ad0a751563acf67e1cd9279cf302db3a' into clippyup
[rust.git] / src / test / ui / consts / const-eval / const-pointer-values-in-various-types.rs
1 // only-x86_64
2
3 #[repr(C)]
4 union Nonsense {
5     u: usize,
6     int_32_ref: &'static i32,
7     uint_8: u8,
8     uint_16: u16,
9     uint_32: u32,
10     uint_64: u64,
11     uint_128: u128,
12     int_8: i8,
13     int_16: i16,
14     int_32: i32,
15     int_64: i64,
16     int_128: i128,
17     float_32: f32,
18     float_64: f64,
19     truthy_falsey: bool,
20     character: char,
21     stringy: &'static str,
22 }
23
24 fn main() {
25     const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u };
26     //~^ ERROR it is undefined behavior to use this value
27
28     const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 };
29     //~^ ERROR any use of this value will cause an error
30
31     const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 };
32     //~^ ERROR any use of this value will cause an error
33
34     const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 };
35     //~^ ERROR any use of this value will cause an error
36
37     const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 };
38     //~^ ERROR it is undefined behavior to use this value
39
40     const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 };
41     //~^ ERROR it is undefined behavior to use this value
42
43     const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 };
44     //~^ ERROR any use of this value will cause an error
45
46     const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 };
47     //~^ ERROR any use of this value will cause an error
48
49     const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 };
50     //~^ ERROR any use of this value will cause an error
51
52     const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 };
53     //~^ ERROR it is undefined behavior to use this value
54
55     const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 };
56     //~^ ERROR it is undefined behavior to use this value
57
58     const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 };
59     //~^ ERROR any use of this value will cause an error
60
61     const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 };
62     //~^ ERROR it is undefined behavior to use this value
63
64     const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey };
65     //~^ ERROR any use of this value will cause an error
66
67     const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character };
68     //~^ ERROR any use of this value will cause an error
69
70     const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 };
71     //~^ ERROR any use of this value will cause an error
72
73     const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 };
74     //~^ ERROR any use of this value will cause an error
75
76     const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 };
77     //~^ ERROR any use of this value will cause an error
78
79     const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 };
80     //~^ ERROR it is undefined behavior to use this value
81
82     const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 };
83     //~^ ERROR any use of this value will cause an error
84
85     const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 };
86     //~^ ERROR any use of this value will cause an error
87
88     const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 };
89     //~^ ERROR any use of this value will cause an error
90
91     const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 };
92     //~^ ERROR any use of this value will cause an error
93
94     const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 };
95     //~^ ERROR it is undefined behavior to use this value
96
97     const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 };
98     //~^ ERROR any use of this value will cause an error
99
100     const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 };
101     //~^ ERROR any use of this value will cause an error
102
103     const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 };
104     //~^ ERROR it is undefined behavior to use this value
105
106     const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey };
107     //~^ ERROR any use of this value will cause an error
108
109     const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character };
110     //~^ ERROR any use of this value will cause an error
111 }