Skip to content

Commit

Permalink
Add UI test for #49296
Browse files Browse the repository at this point in the history
  • Loading branch information
memoryruins committed Oct 29, 2018
1 parent bcb05a0 commit fc2aa3f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/ui/consts/const-eval/issue-49296.rs
@@ -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);
}
12 changes: 12 additions & 0 deletions src/test/ui/consts/const-eval/issue-49296.stderr
@@ -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

0 comments on commit fc2aa3f

Please sign in to comment.