Skip to content

Commit fc2aa3f

Browse files
committed
Add UI test for #49296
1 parent bcb05a0 commit fc2aa3f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// issue-49296: Unsafe shenigans in constants can result in missing errors
2+
3+
#![feature(const_fn)]
4+
#![feature(const_fn_union)]
5+
6+
const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
7+
union Transmute<T: Copy, U: Copy> {
8+
from: T,
9+
to: U,
10+
}
11+
12+
Transmute { from: t }.to
13+
}
14+
15+
const fn wat(x: u64) -> &'static u64 {
16+
unsafe { transmute(&x) }
17+
}
18+
const X: u64 = *wat(42);
19+
//~^ ERROR any use of this value will cause an error
20+
21+
fn main() {
22+
println!("{}", X);
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: any use of this value will cause an error
2+
--> $DIR/issue-49296.rs:18:1
3+
|
4+
LL | const X: u64 = *wat(42);
5+
| ^^^^^^^^^^^^^^^--------^
6+
| |
7+
| dangling pointer was dereferenced
8+
|
9+
= note: #[deny(const_err)] on by default
10+
11+
error: aborting due to previous error
12+

0 commit comments

Comments
 (0)