Skip to content

Commit 6e8d7b6

Browse files
authored
Rollup merge of rust-lang#62930 - iluuu1994:test-for-51559, r=oli-obk
Add test for rust-lang#51559 Closes rust-lang#51559
2 parents fe07132 + f49a965 commit 6e8d7b6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/test/ui/consts/issue-51559.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(const_raw_ptr_to_usize_cast)]
2+
3+
const BAR: *mut () = ((|| 3) as fn() -> i32) as *mut ();
4+
pub const FOO: usize = unsafe { BAR as usize };
5+
//~^ ERROR it is undefined behavior to use this value
6+
7+
fn main() {}

src/test/ui/consts/issue-51559.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0080]: it is undefined behavior to use this value
2+
--> $DIR/issue-51559.rs:4:1
3+
|
4+
LL | pub const FOO: usize = unsafe { BAR as usize };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain (non-pointer) bytes
6+
|
7+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)