Error when casting mut to const pointer
use std::ptr::NonNull;
pub fn g(x: * const i32) -> i32 {
1
}
unsafe fn f(x: NonNull<i32>) -> i32 {
g(x.as_ptr())
}
Open this code snippet in the playground
This gives:
error: [HAX0002] (AST import) Fatal error: something we considered as impossible occurred! Please report this by submitting an issue on GitHub!
Details: Pointer, with [cast] being Types.MutToConstPointer
--> src/lib.rs:10:7
|
10 | g(x.as_ptr())
and
error: [HAX0002] (RefMut) Fatal error: something we considered as impossible occurred! Please report this by submitting an issue on GitHub!
Details: expected an arrow type here
--> src/lib.rs:10:1
|
10 | g(x.as_ptr())
I also found the same kind of error with Details: Pointer, with [cast] being Types.UnsafeFnPointer
Thanks, that's the engine side of #1057 I believe!
There are no constants involved here though
This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.
There is no unsafe needed here:
use std::ptr::NonNull;
fn g(x: * const i32) -> i32 {
1
}
fn f(x: NonNull<i32>) -> i32 {
g(x.as_ptr())
}
Open this code snippet in the playground
Also, here is a further minimization:
fn g(x: *const ()) { }
fn f(x: *mut ()) {
g(x)
}
Open this code snippet in the playground
We should implement everything from https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/adjustment/enum.PointerCoercion.html#variant.ClosureFnPointer, via calls to dedicated Rust_primitive cast functions.