Skip to content

Commit f49a965

Browse files
committed
Add test for #51559
Closes #51559
1 parent a7f2867 commit f49a965

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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)