Skip to content

Commit d997596

Browse files
authored
Rollup merge of #64015 - RalfJung:const-tests, r=oli-obk
some const-eval test tweaks Best reviewed commit-by-commit. r? @oli-obk
2 parents 1dc8b23 + 6d86163 commit d997596

33 files changed

+84
-60
lines changed

src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// only-x86_64
22

3+
#[repr(C)]
34
union Nonsense {
45
u: usize,
56
int_32_ref: &'static i32,

src/test/ui/consts/const-eval/const-pointer-values-in-various-types.stderr

+29-29
Large diffs are not rendered by default.

src/test/ui/consts/const-eval/const_transmute.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![feature(const_fn_union)]
44

5+
#[repr(C)]
56
union Transmute<T: Copy, U: Copy> {
67
t: T,
78
u: U,

src/test/ui/consts/const-eval/double_check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum Bar {
88
C = 42,
99
D = 99,
1010
}
11+
#[repr(C)]
1112
union Union {
1213
foo: &'static Foo,
1314
bar: &'static Bar,

src/test/ui/consts/const-eval/double_check2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum Bar {
66
C = 42,
77
D = 99,
88
}
9+
#[repr(C)]
910
union Union {
1011
foo: &'static Foo,
1112
bar: &'static Bar,

src/test/ui/consts/const-eval/double_check2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/double_check2.rs:15:1
2+
--> $DIR/double_check2.rs:16:1
33
|
44
LL | / static FOO: (&Foo, &Bar) = unsafe {(
55
LL | | Union { u8: &BAR }.foo,

src/test/ui/consts/const-eval/feature-gate-const_fn_union.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
fn main() {}
44

5+
#[repr(C)]
56
union Foo {
67
u: u32,
78
i: i32,

src/test/ui/consts/const-eval/feature-gate-const_fn_union.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: unions in const fn are unstable
2-
--> $DIR/feature-gate-const_fn_union.rs:11:5
2+
--> $DIR/feature-gate-const_fn_union.rs:12:5
33
|
44
LL | Foo { u }.i
55
| ^^^^^^^^^^^

src/test/ui/consts/const-eval/issue-49296.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(const_fn_union)]
55

66
const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
7+
#[repr(C)]
78
union Transmute<T: Copy, U: Copy> {
89
from: T,
910
to: U,

src/test/ui/consts/const-eval/issue-49296.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: any use of this value will cause an error
2-
--> $DIR/issue-49296.rs:18:16
2+
--> $DIR/issue-49296.rs:19:16
33
|
44
LL | const X: u64 = *wat(42);
55
| ---------------^^^^^^^^-

src/test/ui/consts/const-eval/promoted_const_fn_fail.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![allow(const_err)]
44

5+
#[repr(C)]
56
union Bar {
67
a: &'static u8,
78
b: usize,

src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/promoted_const_fn_fail.rs:20:27
2+
--> $DIR/promoted_const_fn_fail.rs:21:27
33
|
44
LL | let x: &'static u8 = &(bar() + 1);
55
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use

src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![deny(const_err)]
44

5+
#[repr(C)]
56
union Bar {
67
a: &'static u8,
78
b: usize,

src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:21:27
2+
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:22:27
33
|
44
LL | let x: &'static u8 = &(bar() + 1);
55
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use

src/test/ui/consts/const-eval/ref_to_int_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn main() {
99
}
1010
}
1111

12+
#[repr(C)]
1213
union Foo {
1314
f: Int,
1415
r: &'static u32,

src/test/ui/consts/const-eval/ref_to_int_match.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ref_to_int_match.rs:23:1
2+
--> $DIR/ref_to_int_match.rs:24:1
33
|
44
LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain (non-pointer) bytes

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

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct Wrap<T>(T);
1010
enum Enum {
1111
A = 0,
1212
}
13+
#[repr(C)]
1314
union TransmuteEnum {
1415
in1: &'static u8,
1516
in2: usize,
@@ -35,6 +36,7 @@ enum Enum2 {
3536
A = 2,
3637
}
3738

39+
#[repr(C)]
3840
union TransmuteEnum2 {
3941
in1: usize,
4042
in2: &'static u8,
@@ -60,6 +62,7 @@ const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.
6062

6163
// Invalid enum field content (mostly to test printing of paths for enum tuple
6264
// variants and tuples).
65+
#[repr(C)]
6366
union TransmuteChar {
6467
a: u32,
6568
b: char,

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-enum.rs:22:1
2+
--> $DIR/ub-enum.rs:23:1
33
|
44
LL | const BAD_ENUM: Enum = unsafe { TransmuteEnum { in2: 1 }.out1 };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 rust compiler repository if you believe it should not be considered undefined behavior
88

99
error[E0080]: it is undefined behavior to use this value
10-
--> $DIR/ub-enum.rs:25:1
10+
--> $DIR/ub-enum.rs:26:1
1111
|
1212
LL | const BAD_ENUM_PTR: Enum = unsafe { TransmuteEnum { in1: &1 }.out1 };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected a valid enum discriminant
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 rust compiler repository if you believe it should not be considered undefined behavior
1616

1717
error[E0080]: it is undefined behavior to use this value
18-
--> $DIR/ub-enum.rs:28:1
18+
--> $DIR/ub-enum.rs:29:1
1919
|
2020
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { TransmuteEnum { in1: &1 }.out2 };
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected something that cannot possibly fail to be equal to 0
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 rust compiler 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:46:1
26+
--> $DIR/ub-enum.rs:48:1
2727
|
2828
LL | const BAD_ENUM2: Enum2 = unsafe { TransmuteEnum2 { in1: 0 }.out1 };
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 rust compiler 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:48:1
34+
--> $DIR/ub-enum.rs:50:1
3535
|
3636
LL | const BAD_ENUM2_PTR: Enum2 = unsafe { TransmuteEnum2 { in2: &0 }.out1 };
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected a valid enum discriminant
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 rust compiler 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:50:1
42+
--> $DIR/ub-enum.rs:52:1
4343
|
4444
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.out2 };
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected something that cannot possibly fail to be equal to 2
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 rust compiler 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:54:1
50+
--> $DIR/ub-enum.rs:56:1
5151
|
5252
LL | const BAD_ENUM2_UNDEF : Enum2 = unsafe { TransmuteEnum2 { in3: () }.out1 };
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected a valid enum discriminant
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 rust compiler 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:58:1
58+
--> $DIR/ub-enum.rs:60:1
5959
|
6060
LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.out3 };
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected a valid enum discriminant
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 rust compiler 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:68:1
66+
--> $DIR/ub-enum.rs:71:1
6767
|
6868
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { TransmuteChar { a: !0 }.b }));
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 4294967295 at .<downcast-variant(Some)>.0.1, but expected something less or equal to 1114111

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

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
2424
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
2525
//~^ ERROR it is undefined behavior to use this value
2626

27+
#[repr(C)]
2728
union Transmute {
2829
uninit: (),
2930
out: NonZeroU8,

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
4141
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
4242

4343
error[E0080]: it is undefined behavior to use this value
44-
--> $DIR/ub-nonnull.rs:31:1
44+
--> $DIR/ub-nonnull.rs:32:1
4545
|
4646
LL | const UNINIT: NonZeroU8 = unsafe { Transmute { uninit: () }.out };
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected something greater or equal to 1
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 rust compiler repository if you believe it should not be considered undefined behavior
5050

5151
error[E0080]: it is undefined behavior to use this value
52-
--> $DIR/ub-nonnull.rs:39:1
52+
--> $DIR/ub-nonnull.rs:40:1
5353
|
5454
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
5656
|
5757
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
5858

5959
error[E0080]: it is undefined behavior to use this value
60-
--> $DIR/ub-nonnull.rs:45:1
60+
--> $DIR/ub-nonnull.rs:46:1
6161
|
6262
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30

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

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
1111
const NULL: &u16 = unsafe { mem::transmute(0usize) };
1212
//~^ ERROR it is undefined behavior to use this value
1313

14+
// It is very important that we reject this: We do promote `&(4 * REF_AS_USIZE)`,
15+
// but that would fail to compile; so we ended up breaking user code that would
16+
// have worked fine had we not promoted.
1417
const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
1518
//~^ ERROR it is undefined behavior to use this value
1619

src/test/ui/consts/const-eval/ub-ref.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
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 rust compiler repository if you believe it should not be considered undefined behavior
1616

1717
error[E0080]: it is undefined behavior to use this value
18-
--> $DIR/ub-ref.rs:14:1
18+
--> $DIR/ub-ref.rs:17:1
1919
|
2020
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, 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 rust compiler 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-ref.rs:17:1
26+
--> $DIR/ub-ref.rs:20:1
2727
|
2828
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<deref>, but expected plain (non-pointer) bytes
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 rust compiler 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-ref.rs:20:1
34+
--> $DIR/ub-ref.rs:23:1
3535
|
3636
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling reference (created from integer)

src/test/ui/consts/const-eval/ub-uninhabit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::mem;
66
#[derive(Copy, Clone)]
77
enum Bar {}
88

9+
#[repr(C)]
910
union TransmuteUnion<A: Clone + Copy, B: Clone + Copy> {
1011
a: A,
1112
b: B,

src/test/ui/consts/const-eval/ub-uninhabit.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-uninhabit.rs:14:1
2+
--> $DIR/ub-uninhabit.rs:15:1
33
|
44
LL | const BAD_BAD_BAD: Bar = unsafe { (TransmuteUnion::<(), Bar> { a: () }).b };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type
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 rust compiler repository if you believe it should not be considered undefined behavior
88

99
error[E0080]: it is undefined behavior to use this value
10-
--> $DIR/ub-uninhabit.rs:17:1
10+
--> $DIR/ub-uninhabit.rs:18:1
1111
|
1212
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>
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 rust compiler repository if you believe it should not be considered undefined behavior
1616

1717
error[E0080]: it is undefined behavior to use this value
18-
--> $DIR/ub-uninhabit.rs:20:1
18+
--> $DIR/ub-uninhabit.rs:21:1
1919
|
2020
LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { (TransmuteUnion::<(), [Bar; 1]> { a: () }).b };
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type

src/test/ui/consts/const-eval/union-const-eval-field.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type Field1 = i32;
44
type Field2 = f32;
55
type Field3 = i64;
66

7+
#[repr(C)]
78
union DummyUnion {
89
field1: Field1,
910
field2: Field2,

src/test/ui/consts/const-eval/union-const-eval-field.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/union-const-eval-field.rs:27:5
2+
--> $DIR/union-const-eval-field.rs:28:5
33
|
44
LL | const FIELD3: Field3 = unsafe { UNION.field3 };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes

src/test/ui/consts/const-eval/union-ice.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
type Field1 = i32;
44
type Field3 = i64;
55

6+
#[repr(C)]
67
union DummyUnion {
78
field1: Field1,
89
field3: Field3,

src/test/ui/consts/const-eval/union-ice.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/union-ice.rs:13:1
2+
--> $DIR/union-ice.rs:14:1
33
|
44
LL | const FIELD3: Field3 = unsafe { UNION.field3 };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
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 rust compiler repository if you believe it should not be considered undefined behavior
88

99
error[E0080]: it is undefined behavior to use this value
10-
--> $DIR/union-ice.rs:15:1
10+
--> $DIR/union-ice.rs:16:1
1111
|
1212
LL | / const FIELD_PATH: Struct = Struct {
1313
LL | | a: 42,
@@ -18,7 +18,7 @@ LL | | };
1818
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
1919

2020
error[E0080]: it is undefined behavior to use this value
21-
--> $DIR/union-ice.rs:25:1
21+
--> $DIR/union-ice.rs:26:1
2222
|
2323
LL | / const FIELD_PATH2: Struct2 = Struct2 {
2424
LL | | b: [

src/test/ui/consts/const-eval/union-ub.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(const_err)] // make sure we cannot allow away the errors tested here
22

3+
#[repr(C)]
34
union DummyUnion {
45
u8: u8,
56
bool: bool,
@@ -14,11 +15,13 @@ enum Enum {
1415
}
1516

1617
#[derive(Copy, Clone)]
18+
#[repr(C)]
1719
union Foo {
1820
a: bool,
1921
b: Enum,
2022
}
2123

24+
#[repr(C)]
2225
union Bar {
2326
foo: Foo,
2427
u8: u8,

src/test/ui/consts/const-eval/union-ub.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/union-ub.rs:28:1
2+
--> $DIR/union-ub.rs:31:1
33
|
44
LL | const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool};
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something less or equal to 1

0 commit comments

Comments
 (0)