diff options
| author | kennytm <kennytm@gmail.com> | 2018-10-30 18:55:28 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-30 18:55:28 +0800 |
| commit | 64417a70fccfbae81458fd8fd02af58e60d69355 (patch) | |
| tree | 6cde86587b576b9a8aefa79be6d870b68be04955 | |
| parent | 8c8581703e536ae584d6b46216e360fb587afb66 (diff) | |
| parent | fc2aa3fe0ec13c8d6150a877d7193473aabc58c9 (diff) | |
| download | rust-64417a70fccfbae81458fd8fd02af58e60d69355.tar.gz rust-64417a70fccfbae81458fd8fd02af58e60d69355.zip | |
Rollup merge of #55459 - memoryruins:issue-49296, r=oli-obk
Add UI test for #49296 Closes #49296 r? @oli-obk
| -rw-r--r-- | src/test/ui/consts/const-eval/issue-49296.rs | 23 | ||||
| -rw-r--r-- | src/test/ui/consts/const-eval/issue-49296.stderr | 12 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-eval/issue-49296.rs b/src/test/ui/consts/const-eval/issue-49296.rs new file mode 100644 index 00000000000..a7c3c5318d4 --- /dev/null +++ b/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); +} diff --git a/src/test/ui/consts/const-eval/issue-49296.stderr b/src/test/ui/consts/const-eval/issue-49296.stderr new file mode 100644 index 00000000000..37462db4c96 --- /dev/null +++ b/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 + |
