forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#55459 - memoryruins:issue-49296, r=oli-obk
Add UI test for rust-lang#49296 Closes rust-lang#49296 r? @oli-obk
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|