]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs
Rollup merge of #81676 - jyn514:crate-not-found, r=oli-obk
[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     //~| WARN this was previously accepted by the compiler but is being phased out
31
32     const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 };
33     //~^ ERROR any use of this value will cause an error
34     //~| WARN this was previously accepted by the compiler but is being phased out
35
36     const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 };
37     //~^ ERROR any use of this value will cause an error
38     //~| WARN this was previously accepted by the compiler but is being phased out
39
40     const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 };
41     //~^ ERROR it is undefined behavior to use this value
42
43     const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 };
44     //~^ ERROR it is undefined behavior to use this value
45
46     const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 };
47     //~^ ERROR any use of this value will cause an error
48     //~| WARN this was previously accepted by the compiler but is being phased out
49
50     const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 };
51     //~^ ERROR any use of this value will cause an error
52     //~| WARN this was previously accepted by the compiler but is being phased out
53
54     const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 };
55     //~^ ERROR any use of this value will cause an error
56     //~| WARN this was previously accepted by the compiler but is being phased out
57
58     const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 };
59     //~^ ERROR it is undefined behavior to use this value
60
61     const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 };
62     //~^ ERROR it is undefined behavior to use this value
63
64     const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 };
65     //~^ ERROR any use of this value will cause an error
66     //~| WARN this was previously accepted by the compiler but is being phased out
67
68     const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 };
69     //~^ ERROR it is undefined behavior to use this value
70
71     const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey };
72     //~^ ERROR any use of this value will cause an error
73     //~| WARN this was previously accepted by the compiler but is being phased out
74
75     const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character };
76     //~^ ERROR any use of this value will cause an error
77     //~| WARN this was previously accepted by the compiler but is being phased out
78
79     const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 };
80     //~^ ERROR any use of this value will cause an error
81     //~| WARN this was previously accepted by the compiler but is being phased out
82
83     const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 };
84     //~^ ERROR any use of this value will cause an error
85     //~| WARN this was previously accepted by the compiler but is being phased out
86
87     const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 };
88     //~^ ERROR any use of this value will cause an error
89     //~| WARN this was previously accepted by the compiler but is being phased out
90
91     const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 };
92     //~^ ERROR it is undefined behavior to use this value
93
94     const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 };
95     //~^ ERROR any use of this value will cause an error
96     //~| WARN this was previously accepted by the compiler but is being phased out
97
98     const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 };
99     //~^ ERROR any use of this value will cause an error
100     //~| WARN this was previously accepted by the compiler but is being phased out
101
102     const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 };
103     //~^ ERROR any use of this value will cause an error
104     //~| WARN this was previously accepted by the compiler but is being phased out
105
106     const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 };
107     //~^ ERROR any use of this value will cause an error
108     //~| WARN this was previously accepted by the compiler but is being phased out
109
110     const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 };
111     //~^ ERROR it is undefined behavior to use this value
112
113     const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 };
114     //~^ ERROR any use of this value will cause an error
115     //~| WARN this was previously accepted by the compiler but is being phased out
116
117     const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 };
118     //~^ ERROR any use of this value will cause an error
119     //~| WARN this was previously accepted by the compiler but is being phased out
120
121     const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 };
122     //~^ ERROR it is undefined behavior to use this value
123
124     const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey };
125     //~^ ERROR any use of this value will cause an error
126     //~| WARN this was previously accepted by the compiler but is being phased out
127
128     const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character };
129     //~^ ERROR any use of this value will cause an error
130     //~| WARN this was previously accepted by the compiler but is being phased out
131 }