rust-lang/rust-clippy

Warn about uses of Rust types where a C (raw) type is expected

Open

#1,631 创建于 2017年3月20日

在 GitHub 查看
 (4 评论) (3 反应) (0 负责人)Rust (10,406 star) (1,391 fork)batch import
A-lintE-hardL-correctnessT-ASTgood first issue

描述

I started using Rust on ARMv7 and run twice into issues where Rust types where used instead of c_* types.

  1. It should not be possible to use a C type in a function declaration and a Rust type when calling it (or vice versa.)
  2. 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);
   }

贡献者指南