Skip to content

Commit 0cf4329

Browse files
committed
also test error messages
1 parent 0de6873 commit 0cf4329

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// ignore-tidy-linelength
12
#![feature(const_transmute)]
23
#![allow(const_err)] // make sure we cannot allow away the errors tested here
34

45
use std::mem;
56

67
const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
78
//~^ ERROR it is undefined behavior to use this value
9+
//~^^ type validation failed: encountered unaligned reference (required 2 byte alignment but found 1)
810

911
const NULL: &u16 = unsafe { mem::transmute(0usize) };
1012
//~^ ERROR it is undefined behavior to use this value

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-ref.rs:6:1
2+
--> $DIR/ub-ref.rs:7:1
33
|
44
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered unaligned reference (required 2 byte alignment but found 1)
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-ref.rs:9:1
10+
--> $DIR/ub-ref.rs:11:1
1111
|
1212
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
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-ref.rs:12:1
18+
--> $DIR/ub-ref.rs:14: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:15:1
26+
--> $DIR/ub-ref.rs:17: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:18:1
34+
--> $DIR/ub-ref.rs:20:1
3535
|
3636
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling reference (created from integer)

0 commit comments

Comments
 (0)