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