Skip to content

Commit c31b704

Browse files
authored
Rollup merge of #69646 - RalfJung:layout-visitor, r=eddyb
Miri visitor: detect primitive types based on type, not layout (also, more tests) I also converted the union-based transmutes to use `mem::transmute` for increased readability. r? @eddyb @oli-obk
2 parents b3c405c + a95f00f commit c31b704

14 files changed

+472
-356
lines changed

Diff for: src/librustc_mir/interpret/validity.rs

+166-127
Large diffs are not rendered by default.

Diff for: src/librustc_target/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ impl Niche {
872872
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
873873
pub struct LayoutDetails {
874874
/// Says where the fields are located within the layout.
875-
/// Primitives and fieldless enums appear as unions without fields.
875+
/// Primitives and uninhabited enums appear as unions without fields.
876876
pub fields: FieldPlacement,
877877

878878
/// Encodes information about multi-variant layouts.

Diff for: src/test/ui/consts/const-eval/ub-enum.rs

+52-31
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,95 @@
1+
#![feature(const_transmute, never_type)]
12
#![allow(const_err)] // make sure we cannot allow away the errors tested here
23

4+
use std::mem;
35

46
#[repr(transparent)]
57
#[derive(Copy, Clone)]
68
struct Wrap<T>(T);
79

10+
#[derive(Copy, Clone)]
11+
enum Never {}
12+
13+
// # simple enum with discriminant 0
14+
815
#[repr(usize)]
916
#[derive(Copy, Clone)]
1017
enum Enum {
1118
A = 0,
1219
}
13-
#[repr(C)]
14-
union TransmuteEnum {
15-
in1: &'static u8,
16-
in2: usize,
17-
out1: Enum,
18-
out2: Wrap<Enum>,
19-
}
2020

21-
const GOOD_ENUM: Enum = unsafe { TransmuteEnum { in2: 0 }.out1 };
21+
const GOOD_ENUM: Enum = unsafe { mem::transmute(0usize) };
2222

23-
const BAD_ENUM: Enum = unsafe { TransmuteEnum { in2: 1 }.out1 };
23+
const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
2424
//~^ ERROR is undefined behavior
2525

26-
const BAD_ENUM_PTR: Enum = unsafe { TransmuteEnum { in1: &1 }.out1 };
26+
const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
2727
//~^ ERROR is undefined behavior
2828

29-
const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { TransmuteEnum { in1: &1 }.out2 };
29+
const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
3030
//~^ ERROR is undefined behavior
3131

32+
// # simple enum with discriminant 2
33+
3234
// (Potentially) invalid enum discriminant
3335
#[repr(usize)]
3436
#[derive(Copy, Clone)]
3537
enum Enum2 {
3638
A = 2,
3739
}
3840

39-
#[repr(C)]
40-
union TransmuteEnum2 {
41-
in1: usize,
42-
in2: &'static u8,
43-
in3: (),
44-
out1: Enum2,
45-
out2: Wrap<Enum2>, // something wrapping the enum so that we test layout first, not enum
46-
out3: Option<Enum2>,
47-
}
48-
const BAD_ENUM2: Enum2 = unsafe { TransmuteEnum2 { in1: 0 }.out1 };
41+
const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
4942
//~^ ERROR is undefined behavior
50-
const BAD_ENUM2_PTR: Enum2 = unsafe { TransmuteEnum2 { in2: &0 }.out1 };
43+
const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
5144
//~^ ERROR is undefined behavior
52-
const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.out2 };
45+
// something wrapping the enum so that we test layout first, not enum
46+
const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
5347
//~^ ERROR is undefined behavior
5448

5549
// Undef enum discriminant.
56-
const BAD_ENUM2_UNDEF : Enum2 = unsafe { TransmuteEnum2 { in3: () }.out1 };
50+
#[repr(C)]
51+
union MaybeUninit<T: Copy> {
52+
uninit: (),
53+
init: T,
54+
}
55+
const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
5756
//~^ ERROR is undefined behavior
5857

5958
// Pointer value in an enum with a niche that is not just 0.
60-
const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.out3 };
59+
const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
6160
//~^ ERROR is undefined behavior
6261

62+
// # valid discriminant for uninhabited variant
63+
64+
// An enum with 3 variants of which some are uninhabited -- so the uninhabited variants *do*
65+
// have a discriminant.
66+
enum UninhDiscriminant {
67+
A,
68+
B(!),
69+
C,
70+
D(Never),
71+
}
72+
73+
const GOOD_INHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(0u8) }; // variant A
74+
const GOOD_INHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(2u8) }; // variant C
75+
76+
const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
77+
//~^ ERROR is undefined behavior
78+
const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
79+
//~^ ERROR is undefined behavior
80+
81+
// # other
82+
6383
// Invalid enum field content (mostly to test printing of paths for enum tuple
6484
// variants and tuples).
65-
#[repr(C)]
66-
union TransmuteChar {
67-
a: u32,
68-
b: char,
69-
}
7085
// Need to create something which does not clash with enum layout optimizations.
71-
const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { TransmuteChar { a: !0 }.b }));
86+
const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
87+
//~^ ERROR is undefined behavior
88+
89+
// All variants are uninhabited but also have data.
90+
const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(1u64) };
91+
//~^ ERROR is undefined behavior
92+
const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(1u64) };
7293
//~^ ERROR is undefined behavior
7394

7495
fn main() {

Diff for: src/test/ui/consts/const-eval/ub-enum.stderr

+56-24
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,107 @@
11
error[E0080]: it is undefined behavior to use this value
22
--> $DIR/ub-enum.rs:23:1
33
|
4-
LL | const BAD_ENUM: Enum = unsafe { TransmuteEnum { in2: 1 }.out1 };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 1, but expected a valid enum discriminant
4+
LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 1, but expected a valid enum discriminant
66
|
77
= 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.
88

99
error[E0080]: it is undefined behavior to use this value
1010
--> $DIR/ub-enum.rs:26:1
1111
|
12-
LL | const BAD_ENUM_PTR: Enum = unsafe { TransmuteEnum { in1: &1 }.out1 };
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
12+
LL | const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
1414
|
1515
= 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.
1616

1717
error[E0080]: it is undefined behavior to use this value
1818
--> $DIR/ub-enum.rs:29:1
1919
|
20-
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { TransmuteEnum { in1: &1 }.out2 };
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
20+
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
2222
|
2323
= 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.
2424

2525
error[E0080]: it is undefined behavior to use this value
26-
--> $DIR/ub-enum.rs:48:1
26+
--> $DIR/ub-enum.rs:41:1
2727
|
28-
LL | const BAD_ENUM2: Enum2 = unsafe { TransmuteEnum2 { in1: 0 }.out1 };
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected a valid enum discriminant
28+
LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected a valid enum discriminant
3030
|
3131
= 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.
3232

3333
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/ub-enum.rs:50:1
34+
--> $DIR/ub-enum.rs:43:1
3535
|
36-
LL | const BAD_ENUM2_PTR: Enum2 = unsafe { TransmuteEnum2 { in2: &0 }.out1 };
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
36+
LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
3838
|
3939
= 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.
4040

4141
error[E0080]: it is undefined behavior to use this value
42-
--> $DIR/ub-enum.rs:52:1
42+
--> $DIR/ub-enum.rs:46:1
4343
|
44-
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.out2 };
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
44+
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
4646
|
4747
= 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.
4848

4949
error[E0080]: it is undefined behavior to use this value
50-
--> $DIR/ub-enum.rs:56:1
50+
--> $DIR/ub-enum.rs:55:1
5151
|
52-
LL | const BAD_ENUM2_UNDEF : Enum2 = unsafe { TransmuteEnum2 { in3: () }.out1 };
52+
LL | const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes at .<enum-tag>, but expected initialized plain (non-pointer) bytes
5454
|
5555
= 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.
5656

5757
error[E0080]: it is undefined behavior to use this value
58-
--> $DIR/ub-enum.rs:60:1
58+
--> $DIR/ub-enum.rs:59:1
5959
|
60-
LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.out3 };
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
60+
LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
6262
|
6363
= 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.
6464

6565
error[E0080]: it is undefined behavior to use this value
66-
--> $DIR/ub-enum.rs:71:1
66+
--> $DIR/ub-enum.rs:76:1
6767
|
68-
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { TransmuteChar { a: !0 }.b }));
69-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 4294967295 at .<enum-variant(Some)>.0.1, but expected a valid unicode codepoint
68+
LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of the never type `!` at .<enum-variant(B)>.0
7070
|
7171
= 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.
7272

73-
error: aborting due to 9 previous errors
73+
error[E0080]: it is undefined behavior to use this value
74+
--> $DIR/ub-enum.rs:78:1
75+
|
76+
LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of uninhabited type Never at .<enum-variant(D)>.0
78+
|
79+
= 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.
80+
81+
error[E0080]: it is undefined behavior to use this value
82+
--> $DIR/ub-enum.rs:86:1
83+
|
84+
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 4294967295 at .<enum-variant(Some)>.0.1, but expected a valid unicode codepoint
86+
|
87+
= 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.
88+
89+
error[E0080]: it is undefined behavior to use this value
90+
--> $DIR/ub-enum.rs:90:1
91+
|
92+
LL | const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(1u64) };
93+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of the never type `!` at .<enum-variant(Err)>.0.1
94+
|
95+
= 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.
96+
97+
error[E0080]: it is undefined behavior to use this value
98+
--> $DIR/ub-enum.rs:92:1
99+
|
100+
LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(1u64) };
101+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of uninhabited type Never at .<enum-variant(Err)>.0.1
102+
|
103+
= 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.
104+
105+
error: aborting due to 13 previous errors
74106

75107
For more information about this error, try `rustc --explain E0080`.

Diff for: src/test/ui/consts/const-eval/ub-nonnull.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
2525
//~^ ERROR it is undefined behavior to use this value
2626

2727
#[repr(C)]
28-
union Transmute {
28+
union MaybeUninit<T: Copy> {
2929
uninit: (),
30-
out: NonZeroU8,
30+
init: T,
3131
}
32-
const UNINIT: NonZeroU8 = unsafe { Transmute { uninit: () }.out };
32+
const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
3333
//~^ ERROR it is undefined behavior to use this value
3434

3535
// Also test other uses of rustc_layout_scalar_valid_range_start

Diff for: src/test/ui/consts/const-eval/ub-nonnull.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
4343
error[E0080]: it is undefined behavior to use this value
4444
--> $DIR/ub-nonnull.rs:32:1
4545
|
46-
LL | const UNINIT: NonZeroU8 = unsafe { Transmute { uninit: () }.out };
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes at .0, but expected initialized plain (non-pointer) bytes
46+
LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes at .0, but expected initialized plain (non-pointer) bytes
4848
|
4949
= 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.
5050

Diff for: src/test/ui/consts/const-eval/ub-ref.rs

+13
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
88
//~^ ERROR it is undefined behavior to use this value
99
//~^^ type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1)
1010

11+
const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
12+
//~^ ERROR it is undefined behavior to use this value
13+
//~^^ type validation failed: encountered an unaligned box (required 2 byte alignment but found 1)
14+
1115
const NULL: &u16 = unsafe { mem::transmute(0usize) };
1216
//~^ ERROR it is undefined behavior to use this value
1317

18+
const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
19+
//~^ ERROR it is undefined behavior to use this value
20+
1421
// It is very important that we reject this: We do promote `&(4 * REF_AS_USIZE)`,
1522
// but that would fail to compile; so we ended up breaking user code that would
1623
// have worked fine had we not promoted.
@@ -20,7 +27,13 @@ const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
2027
const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
2128
//~^ ERROR it is undefined behavior to use this value
2229

30+
const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
31+
//~^ ERROR it is undefined behavior to use this value
32+
2333
const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
2434
//~^ ERROR it is undefined behavior to use this value
2535

36+
const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
37+
//~^ ERROR it is undefined behavior to use this value
38+
2639
fn main() {}

0 commit comments

Comments
 (0)