1 error[E0080]: it is undefined behavior to use this value
2 --> $DIR/ub-enum.rs:24:1
4 LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
5 | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000001, but expected a valid enum tag
7 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8 = note: the raw bytes of the constant (size: 8, align: 8) {
9 01 00 00 00 00 00 00 00 │ ........
12 error[E0080]: evaluation of constant value failed
13 --> $DIR/ub-enum.rs:27:1
15 LL | const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
16 | ^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
18 = help: this code performed an operation that depends on the underlying bytes representing a pointer
19 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
21 error[E0080]: evaluation of constant value failed
22 --> $DIR/ub-enum.rs:30:1
24 LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
25 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
27 = help: this code performed an operation that depends on the underlying bytes representing a pointer
28 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
30 error[E0080]: it is undefined behavior to use this value
31 --> $DIR/ub-enum.rs:42:1
33 LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
34 | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000000, but expected a valid enum tag
36 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
37 = note: the raw bytes of the constant (size: 8, align: 8) {
38 00 00 00 00 00 00 00 00 │ ........
41 error[E0080]: evaluation of constant value failed
42 --> $DIR/ub-enum.rs:44:1
44 LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
45 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
47 = help: this code performed an operation that depends on the underlying bytes representing a pointer
48 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
50 error[E0080]: evaluation of constant value failed
51 --> $DIR/ub-enum.rs:47:1
53 LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
54 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
56 = help: this code performed an operation that depends on the underlying bytes representing a pointer
57 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
59 error[E0080]: evaluation of constant value failed
60 --> $DIR/ub-enum.rs:56:42
62 LL | const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
63 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
65 error[E0080]: evaluation of constant value failed
66 --> $DIR/ub-enum.rs:61:1
68 LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
69 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
71 = help: this code performed an operation that depends on the underlying bytes representing a pointer
72 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
74 error[E0080]: it is undefined behavior to use this value
75 --> $DIR/ub-enum.rs:78:1
77 LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
78 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(B)>.0: encountered a value of the never type `!`
80 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
81 = note: the raw bytes of the constant (size: 1, align: 1) {
85 error[E0080]: it is undefined behavior to use this value
86 --> $DIR/ub-enum.rs:80:1
88 LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
89 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(D)>.0: encountered a value of uninhabited type Never
91 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
92 = note: the raw bytes of the constant (size: 1, align: 1) {
96 error[E0080]: it is undefined behavior to use this value
97 --> $DIR/ub-enum.rs:88:1
99 LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
100 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
102 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
103 = note: the raw bytes of the constant (size: 8, align: 4) {
104 78 00 00 00 ff ff ff ff │ x.......
107 error[E0080]: evaluation of constant value failed
108 --> $DIR/ub-enum.rs:93:77
110 LL | const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(0u64) };
111 | ^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
113 error[E0080]: evaluation of constant value failed
114 --> $DIR/ub-enum.rs:95:77
116 LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(0u64) };
117 | ^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
119 error: aborting due to 13 previous errors
121 For more information about this error, try `rustc --explain E0080`.