Add UI test for #49296
This commit is contained in:
parent
bcb05a0ab2
commit
fc2aa3fe0e
2 changed files with 35 additions and 0 deletions
23
src/test/ui/consts/const-eval/issue-49296.rs
Normal file
23
src/test/ui/consts/const-eval/issue-49296.rs
Normal 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);
|
||||
}
|
||||
12
src/test/ui/consts/const-eval/issue-49296.stderr
Normal file
12
src/test/ui/consts/const-eval/issue-49296.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue