Skip to content

Commit 426dcf0

Browse files
committed
Add test for issue-63952
1 parent ecb8bf0 commit 426dcf0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/test/ui/consts/issue-63952.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Regression test for #63952, shouldn't hang.
2+
3+
use std::usize;
4+
5+
#[repr(C)]
6+
#[derive(Copy, Clone)]
7+
struct SliceRepr {
8+
ptr: *const u8,
9+
len: usize,
10+
}
11+
12+
union SliceTransmute {
13+
repr: SliceRepr,
14+
slice: &'static [u8],
15+
}
16+
17+
// bad slice: length too big to even exist anywhere
18+
const SLICE_WAY_TOO_LONG: &[u8] = unsafe { //~ ERROR: it is undefined behavior to use this value
19+
SliceTransmute {
20+
repr: SliceRepr {
21+
ptr: &42,
22+
len: usize::MAX,
23+
},
24+
}
25+
.slice
26+
};
27+
28+
fn main() {}

src/test/ui/consts/issue-63952.stderr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0080]: it is undefined behavior to use this value
2+
--> $DIR/issue-63952.rs:18:1
3+
|
4+
LL | / const SLICE_WAY_TOO_LONG: &[u8] = unsafe {
5+
LL | | SliceTransmute {
6+
LL | | repr: SliceRepr {
7+
LL | | ptr: &42,
8+
... |
9+
LL | | .slice
10+
LL | | };
11+
| |__^ invalid slice: total size is bigger than largest supported object
12+
|
13+
= 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.
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)