e.g. this irlo thread was likely the result of someone translating a void-returning C function to a c_void-returning Rust function.
Given the following:
pub fn example() -> core::ffi::c_void {
}
The current output is:
error[E0308]: mismatched types
--> src/lib.rs:1:21
|
1 | pub fn example() -> core::ffi::c_void {
| ------- ^^^^^^^^^^^^^^^^^ expected enum `c_void`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
Ideally, this should also contain a help message along the lines of
help = returning void in C is the same as returning () in Rust
and a suggestion to remove the -> c_void.
It might be reasonable to have this as a dedicated warning lint for -> c_void either instead of or in addition to help on the type mismatch error, as writing bindings to extern "C" { fn foo() -> c_void; } is wrong but won't get a type mismatch error. This probably should go straight to a rustc lint rather than in clippy due to the practically-100% applicability.
It might also be beneficial to do more thorough linting of misuse of c_void (basically any use that isn't *mut c_void or *const c_void (or maybe ptr::NonNull<c_void>), but that is a separate issue from teaching in this error.
e.g. this irlo thread was likely the result of someone translating a
void-returning C function to ac_void-returning Rust function.Given the following:
The current output is:
Ideally, this should also contain a help message along the lines of
and a suggestion to remove the
-> c_void.It might be reasonable to have this as a dedicated warning lint for
-> c_voideither instead of or in addition to help on the type mismatch error, as writing bindings toextern "C" { fn foo() -> c_void; }is wrong but won't get a type mismatch error. This probably should go straight to a rustc lint rather than in clippy due to the practically-100% applicability.It might also be beneficial to do more thorough linting of misuse of
c_void(basically any use that isn't*mut c_voidor*const c_void(or maybeptr::NonNull<c_void>), but that is a separate issue from teaching in this error.