Rollup merge of #55459 - memoryruins:issue-49296, r=oli-obk

Add UI test for #49296

Closes #49296

r? @oli-obk
This commit is contained in:
kennytm 2018-10-30 18:55:28 +08:00 committed by GitHub
commit 64417a70fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,23 @@
// issue-49296: Unsafe shenigans in constants can result in missing errors
#![feature(const_fn)]
#![feature(const_fn_union)]
const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
union Transmute<T: Copy, U: Copy> {
from: T,
to: U,
}
Transmute { from: t }.to
}
const fn wat(x: u64) -> &'static u64 {
unsafe { transmute(&x) }
}
const X: u64 = *wat(42);
//~^ ERROR any use of this value will cause an error
fn main() {
println!("{}", X);
}

View file

@ -0,0 +1,12 @@
error: any use of this value will cause an error
--> $DIR/issue-49296.rs:18:1
|
LL | const X: u64 = *wat(42);
| ^^^^^^^^^^^^^^^--------^
| |
| dangling pointer was dereferenced
|
= note: #[deny(const_err)] on by default
error: aborting due to previous error