Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,15 @@ unused_qualifications = "allow"

# We are okay with the current state of these lints
explicit_iter_loop = "warn"
borrow_as_ptr = "warn"
identity_op = "allow" # some expressions like `0 | x` are clearer for bit ops
manual_assert = "warn"
map_unwrap_or = "warn"
missing_safety_doc = "allow" # safety? in libc? seriously?
non_minimal_cfg = "allow" # for some reason cfg_if! sometimes trigger this
ptr_as_ptr = "warn"
ptr_cast_constness = "warn"
ref_as_ptr = "warn"
unnecessary_semicolon = "warn"

# FIXME(clippy): these should be fixed if possible
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ macro_rules! offset_of {
($Ty:path, $field:ident) => {{
// Taken from bytemuck, avoids accidentally calling on deref
#[allow(clippy::unneeded_wildcard_pattern)]
let $Ty { $field: _, .. };
let $Ty { .. };
let data = core::mem::MaybeUninit::<$Ty>::uninit();
let ptr = data.as_ptr();
// nested unsafe, see f!
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ const fn _CMSG_ALIGN(n: usize) -> usize {

f! {
pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::<cmsghdr>()) as isize)
(cmsg as *mut c_uchar).add(_CMSG_ALIGN(size_of::<cmsghdr>()))
}

pub const unsafe fn CMSG_LEN(length: c_uint) -> c_uint {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ const fn _ALIGN(p: usize) -> usize {

f! {
pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(_ALIGN(size_of::<cmsghdr>()) as isize)
(cmsg as *mut c_uchar).add(_ALIGN(size_of::<cmsghdr>()))
}

pub const unsafe fn CMSG_LEN(length: c_uint) -> c_uint {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/cygwin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ f! {
}

const fn CMSG_ALIGN(len: usize) -> usize {
len + size_of::<usize>() - 1 & !(size_of::<usize>() - 1)
(len + size_of::<usize>() - 1) & !(size_of::<usize>() - 1)
}

extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ pub const POSIX_SPAWN_SETSIGMASK: c_short = 0x20;
pub const POSIX_SPAWN_SETSID: c_short = 0x40;

const fn CMSG_ALIGN(len: usize) -> usize {
len + size_of::<usize>() - 1 & !(size_of::<usize>() - 1)
(len + size_of::<usize>() - 1) & !(size_of::<usize>() - 1)
}

f! {
Expand All @@ -1400,7 +1400,7 @@ f! {
}

pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::<cmsghdr>()) as isize)
(cmsg as *mut c_uchar).add(CMSG_ALIGN(size_of::<cmsghdr>()))
}

pub const unsafe fn CMSG_SPACE(length: c_uint) -> c_uint {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/hurd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ pub const S_IPTRANS: mode_t = 0o1000_0000;
pub const S_IATRANS: mode_t = 0o2000_0000;
pub const S_IROOT: mode_t = 0o4000_0000;
pub const S_ITRANS: mode_t = 0o7000_0000;
pub const S_IMMAP0: mode_t = 0o10000_0000;
pub const S_IMMAP0: mode_t = 0o1_0000_0000;

@ada4a ada4a Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave this one as is, for symmetry with the previous ones. I think the logic of rust-lang/rust-clippy#11749 applies here

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the contrary, I’d keep the additional spacing here for consistency with the previous constants. All of the digits are grouped in sets of four.

pub const CMASK: mode_t = 18;
pub const UF_SETTABLE: c_uint = 65535;
pub const UF_NODUMP: c_uint = 1;
Expand Down Expand Up @@ -3487,7 +3487,7 @@ f! {
}

pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::<cmsghdr>()) as isize)
(cmsg as *mut c_uchar).add(CMSG_ALIGN(size_of::<cmsghdr>()))
}

pub const unsafe fn CMSG_SPACE(length: c_uint) -> c_uint {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/linux_l4re_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ f! {
if next_cmsg as usize + size_of::<crate::cmsghdr>() > max_addr {
ptr::null_mut()
} else {
next_cmsg as *mut crate::cmsghdr
next_cmsg.cast_mut()
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/unix/nto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { __u: 0, __owner: 0 };

const fn _CMSG_ALIGN(len: usize) -> usize {
len + size_of::<usize>() - 1 & !(size_of::<usize>() - 1)
(len + size_of::<usize>() - 1) & !(size_of::<usize>() - 1)
}

const fn _ALIGN(p: usize, b: usize) -> usize {
Expand All @@ -2348,7 +2348,7 @@ f! {
}

pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::<cmsghdr>()) as isize)
(cmsg as *mut c_uchar).add(_CMSG_ALIGN(size_of::<cmsghdr>()))
}

pub const unsafe fn CMSG_LEN(length: c_uint) -> c_uint {
Expand Down Expand Up @@ -2384,7 +2384,7 @@ f! {
}

pub unsafe fn _DEXTRA_FIRST(_d: *const dirent) -> *mut crate::dirent_extra {
let _f = &((*(_d)).d_name) as *const _;
let _f = core::ptr::addr_of!(((*(_d)).d_name));
let _s = _d as usize;

_ALIGN(_s + _f as usize - _s + (*_d).d_namelen as usize + 1, 8) as *mut crate::dirent_extra
Expand All @@ -2394,11 +2394,7 @@ f! {
let sz = _x as usize - _d as usize + size_of::<crate::dirent_extra>();
let rsz = (*_d).d_reclen as usize;

if sz > rsz || sz + (*_x).d_datalen as usize > rsz {
false
} else {
true
}
sz <= rsz && sz + (*_x).d_datalen as usize <= rsz
}

pub unsafe fn _DEXTRA_NEXT(_x: *const crate::dirent_extra) -> *mut crate::dirent_extra {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/solarish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ s_no_extra_traits! {

impl siginfo_t {
unsafe fn sidata<T: Copy>(&self) -> T {
*((&self.__data_pad) as *const c_int as *const T)
*core::ptr::addr_of!(self.__data_pad).cast()
}
pub unsafe fn si_addr(&self) -> *mut c_void {
let sifault: siginfo_fault = self.sidata();
Expand Down
6 changes: 3 additions & 3 deletions src/vxworks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ extern_ty! {

f! {
pub const unsafe fn CMSG_ALIGN(len: usize) -> usize {
len + size_of::<usize>() - 1 & !(size_of::<usize>() - 1)
(len + size_of::<usize>() - 1) & !(size_of::<usize>() - 1)
}

pub unsafe fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
Expand All @@ -1482,7 +1482,7 @@ f! {
}

pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::<cmsghdr>()) as isize)
(cmsg as *mut c_uchar).add(CMSG_ALIGN(size_of::<cmsghdr>()))
}

pub const unsafe fn CMSG_SPACE(length: c_uint) -> c_uint {
Expand Down Expand Up @@ -2433,7 +2433,7 @@ extern "C" {
pub unsafe fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size: size_t) -> c_int {
// check to see if align is a power of 2 and if align is a multiple
// of sizeof(void *)
if (align & align - 1 != 0) || (align as usize % size_of::<size_t>() != 0) {
if (align & (align - 1) != 0) || (align as usize % size_of::<size_t>() != 0) {
return crate::EINVAL;
}

Expand Down
6 changes: 2 additions & 4 deletions src/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! `wasi-libc` project provides multiple libraries including emulated features, but we list only
//! basic features with `libc.a` here.

use core::iter::Iterator;

use crate::prelude::*;

pub type intmax_t = i64;
Expand Down Expand Up @@ -671,13 +669,13 @@ f! {
pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
let set = &*set;
let n = set.__nfds;
return set.__fds[..n].iter().any(|p| *p == fd);
return set.__fds[..n].contains(&fd);
}

pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
let set = &mut *set;
let n = set.__nfds;
if !set.__fds[..n].iter().any(|p| *p == fd) {
if !set.__fds[..n].contains(&fd) {
set.__nfds = n + 1;
set.__fds[n] = fd;
}
Expand Down