summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs
blob: f6a5e4d3c2b7ddfb55b6dd270f86f02383ad97cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// only-x86_64
// stderr-per-bitwidth

#[repr(C)]
union Nonsense {
    u: usize,
    int_32_ref: &'static i32,
    uint_8: u8,
    uint_16: u16,
    uint_32: u32,
    uint_64: u64,
    uint_128: u128,
    int_8: i8,
    int_16: i16,
    int_32: i32,
    int_64: i64,
    int_128: i128,
    float_32: f32,
    float_64: f64,
    truthy_falsey: bool,
    character: char,
    stringy: &'static str,
}

fn main() {
    const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 };
    //~^ ERROR evaluation of constant value failed
    //~| uninitialized

    const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 };
    //~^ ERROR evaluation of constant value failed
    //~| uninitialized

    const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out

    const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character };
    //~^ ERROR any use of this value will cause an error
    //~| WARN this was previously accepted by the compiler but is being phased out
}