rust-lang/rust-clippy

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

Open

#1631 aperta il 20 mar 2017

Vedi su GitHub
 (4 commenti) (3 reazioni) (0 assegnatari)Rust (1391 fork)batch import
A-lintE-hardL-correctnessT-ASTgood first issue

Metriche repository

Star
 (10.406 star)
Metriche merge PR
 (Merge medio 19g 22h) (113 PR mergiate in 30 g)

Descrizione

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);
   }

Guida contributor