Given the following files:
main.rs:
mod ffi;
mod impl_do_print;
fn main() {
unsafe {
ffi::do_print(42.0);
}
}
ffi.rs:
extern "C" {
pub fn do_print(x: f32);
}
impl_do_print.rs:
#[no_mangle]
pub extern "C" fn do_print(x: i32) {
println!("{}", x);
}
Obviously, the f32 of the definition and the i32 of the implementation don't match.
When I execute this, it prints:
1047505936
I understand that no_mangle is automatically considered unsafe, but is there any way I could ask the compiler to catch the mismatch, or would I have to write my own linter for this?
Usecase:
This question came up with generated FFIs. I am able to modify the implementation in any way possible, but I cannot edit the function definition, as it is generated via bindgen.