Skip to content

Add UI test for #49296 #55459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/test/ui/consts/const-eval/issue-49296.rs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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