rust-lang/rust-clippy
View on GitHubWarn about uses of Rust types where a C (raw) type is expected
Open
#1631 opened on Mar 20, 2017
A-lintE-hardL-correctnessT-ASTgood first issue
Description
I started using Rust on ARMv7 and run twice into issues where Rust types where used instead of c_* types.
- It should not be possible to use a C type in a function declaration and a Rust type when calling it (or vice versa.)
- Functions like CStr::from_ptr should not allow the use of a Rust type. It is clearly intended for use with c_char.
A few examples
This really should be libc::c_char (c_char is an alias for u8 on ARMv7)
CStr::from_ptr(ptr as *const i8)
Use of libc::c_char in declaration but when using the function i8 is used instead:
pub fn rados_append(io: rados_ioctx_t, oid: *const ::libc::c_char, buf: *const ::libc::c_char, len: size_t)
…
unsafe {
rados_append(ctx, obj_name_str.as_ptr(), buffer.as_ptr() as *const i8, buffer.len());
}
Use of i64 instead of c_time (32bit on ARMv7):
pub fn rados_ioctx_snap_get_stamp(io: rados_ioctx_t, id: rados_snap_t, t: *mut time_t) -> ::libc::c_int;
…
let mut time_id: i64 = 0;
unsafe {
rados_ioctx_snap_get_stamp(ctx, snap_id, &mut time_id);
}