I'm tracking down an error in third party code and I narrowed it down to something along the lines of.
use libc::c_void;
pub unsafe fn foo() {}
fn main() {
let ptr = &foo as *const _ as *const c_void;
println!("{:x}", ptr as usize);
}
Ran on stable 1.38.0 this prints the function pointer, but beta (1.39.0-beta.6) and nightly return '1'. (Playground)
What is the _ getting inferred to and why has the behaviour changed?
I assume the correct way to cast this would simply be foo as *const c_void, but this is not my code.
foois already a function pointer, so you should not take an address to it. That creates a double reference, seemingly to a zero-sized type (thus the magic value1).let ptr = foo as *const fn() as *const c_void;