rust-lang / rust-lang/rust-clippy
Warn about uses of Rust types where a C (raw) type is expected
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
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);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the CStr::from_ptr example and the declarations and calls for rados_append and rados_ioctx_snap_get_stamp. Define which Rust and C raw-type mismatches should be diagnosed, then use those examples to establish tests showing that the intended warnings appear on ARMv7-relevant type aliases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100