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 @@ -185,12 +185,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: 0 additions & 2 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3050,14 +3050,12 @@ f! {
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] |= 1 << offset;
()
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] &= !(1 << offset);
()
}

pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ macro_rules! offset_of {
($Ty:path, $field:ident) => {{
// Taken from bytemuck, avoids accidentally calling on deref
#[allow(clippy::unneeded_field_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/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
let mut s: u32 = 0;
let size_of_mask = size_of_val(&cpuset.bits[0]);

for i in cpuset.bits[..(size / size_of_mask)].iter() {
for i in &cpuset.bits[..(size / size_of_mask)] {
s += i.count_ones();
}
s as c_int
Expand Down
4 changes: 1 addition & 3 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ const fn _CMSG_ALIGN(n: usize) -> usize {

f! {
pub 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 fn CMSG_LEN(length: c_uint) -> c_uint {
Expand Down Expand Up @@ -1206,13 +1206,11 @@ f! {
pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
cpuset.ary[idx] |= 1 << offset;
()
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
cpuset.ary[idx] &= !(1 << offset);
()
}

pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4238,19 +4238,19 @@ f! {
}

pub fn CPU_SET(cpu: usize, cpuset: &mut cpuset_t) -> () {
let bitset_bits = 8 * size_of::<c_long>();
let bitset_bits = c_long::BITS as usize;
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
cpuset.__bits[idx] |= 1 << offset;
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpuset_t) -> () {
let bitset_bits = 8 * size_of::<c_long>();
let bitset_bits = c_long::BITS as usize;
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
cpuset.__bits[idx] &= !(1 << offset);
}

pub fn CPU_ISSET(cpu: usize, cpuset: &cpuset_t) -> bool {
let bitset_bits = 8 * size_of::<c_long>();
let bitset_bits = c_long::BITS as usize;
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
0 != cpuset.__bits[idx] & (1 << offset)
}
Expand All @@ -4260,7 +4260,7 @@ f! {
let cpuset_size = size_of::<cpuset_t>();
let bitset_size = size_of::<c_long>();

for i in cpuset.__bits[..(cpuset_size / bitset_size)].iter() {
for i in &cpuset.__bits[..(cpuset_size / bitset_size)] {
s += i.count_ones();
}
s as c_int
Expand Down
26 changes: 13 additions & 13 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,42 +1330,42 @@ cfg_if! {
ptm_pad1: Padding::new([0; 3]),
ptm_unused: Padding::new(0),
ptm_pad2: Padding::new([0; 3]),
ptm_waiters: 0 as *mut _,
ptm_waiters: ptr::null_mut(),
ptm_owner: 0,
ptm_recursed: 0,
ptm_spare2: 0 as *mut _,
ptm_spare2: ptr::null_mut(),
};
} else {
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
ptm_magic: 0x33330003,
ptm_errorcheck: 0,
ptm_unused: Padding::new(0),
ptm_waiters: 0 as *mut _,
ptm_waiters: ptr::null_mut(),
ptm_owner: 0,
ptm_recursed: 0,
ptm_spare2: 0 as *mut _,
ptm_spare2: ptr::null_mut(),
};
}
}

pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
ptc_magic: 0x55550005,
ptc_lock: 0,
ptc_waiters_first: 0 as *mut _,
ptc_waiters_last: 0 as *mut _,
ptc_mutex: 0 as *mut _,
ptc_private: 0 as *mut _,
ptc_waiters_first: ptr::null_mut(),
ptc_waiters_last: ptr::null_mut(),
ptc_mutex: ptr::null_mut(),
ptc_private: ptr::null_mut(),
};
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
ptr_magic: 0x99990009,
ptr_interlock: 0,
ptr_rblocked_first: 0 as *mut _,
ptr_rblocked_last: 0 as *mut _,
ptr_wblocked_first: 0 as *mut _,
ptr_wblocked_last: 0 as *mut _,
ptr_rblocked_first: ptr::null_mut(),
ptr_rblocked_last: ptr::null_mut(),
ptr_wblocked_first: ptr::null_mut(),
ptr_wblocked_last: ptr::null_mut(),
ptr_nreaders: 0,
ptr_owner: 0,
ptr_private: 0 as *mut _,
ptr_private: ptr::null_mut(),
};
pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 1;
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 @@ -1822,7 +1822,7 @@ const fn _ALIGN(p: usize) -> usize {

f! {
pub 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 fn CMSG_LEN(length: c_uint) -> c_uint {
Expand Down
4 changes: 2 additions & 2 deletions src/unix/cygwin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ f! {
pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
let mut s: u32 = 0;
let size_of_mask = size_of_val(&cpuset.bits[0]);
for i in cpuset.bits[..(size / size_of_mask)].iter() {
for i in &cpuset.bits[..(size / size_of_mask)] {
s += i.count_ones();
}
s as c_int
Expand Down Expand Up @@ -1827,7 +1827,7 @@ safe_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
8 changes: 4 additions & 4 deletions src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
flags: 0,
unused: Padding::new(0),
mutex: 0 as *mut _,
mutex: ptr::null_mut(),
waiter_count: 0,
lock: 0,
};
Expand All @@ -1108,7 +1108,7 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
lock_count: 0,
reader_count: 0,
writer_count: 0,
waiters: [0 as *mut _; 2],
waiters: [ptr::null_mut(); 2],
};

pub const PTHREAD_MUTEX_DEFAULT: c_int = 0;
Expand Down Expand Up @@ -1377,7 +1377,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 @@ -1390,7 +1390,7 @@ f! {
}

pub 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 fn CMSG_SPACE(length: c_uint) -> c_uint {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/haiku/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ pub const B_DIRECTORY_NODE: u32 = 0x04;
pub const B_ANY_NODE: u32 = 0x07;

// support/Errors.h
pub const B_GENERAL_ERROR_BASE: status_t = core::i32::MIN;
pub const B_GENERAL_ERROR_BASE: status_t = i32::MIN;
pub const B_OS_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x1000;
pub const B_APP_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x2000;
pub const B_INTERFACE_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x3000;
Expand Down
26 changes: 13 additions & 13 deletions src/unix/hurd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,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;
pub const CMASK: mode_t = 18;
pub const UF_SETTABLE: c_uint = 65535;
pub const UF_NODUMP: c_uint = 1;
Expand Down Expand Up @@ -3336,19 +3336,19 @@ pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
};
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
__lock: __PTHREAD_SPIN_LOCK_INITIALIZER,
__queue: 0i64 as *mut __pthread,
__attr: 0i64 as *mut __pthread_condattr,
__queue: ptr::null_mut::<__pthread>(),
__attr: ptr::null_mut::<__pthread_condattr>(),
__wrefs: 0,
__data: 0i64 as *mut c_void,
__data: ptr::null_mut::<c_void>(),
};
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
__held: __PTHREAD_SPIN_LOCK_INITIALIZER,
__lock: __PTHREAD_SPIN_LOCK_INITIALIZER,
__readers: 0,
__readerqueue: 0i64 as *mut __pthread,
__writerqueue: 0i64 as *mut __pthread,
__attr: 0i64 as *mut __pthread_rwlockattr,
__data: 0i64 as *mut c_void,
__readerqueue: ptr::null_mut::<__pthread>(),
__writerqueue: ptr::null_mut::<__pthread>(),
__attr: ptr::null_mut::<__pthread_rwlockattr>(),
__data: ptr::null_mut::<c_void>(),
};
pub const PTHREAD_STACK_MIN: size_t = 0;

Expand All @@ -3365,12 +3365,12 @@ f! {
if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() {
(*mhdr).msg_control.cast::<cmsghdr>()
} else {
core::ptr::null_mut::<cmsghdr>()
ptr::null_mut::<cmsghdr>()
}
}

pub 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 fn CMSG_SPACE(length: c_uint) -> c_uint {
Expand All @@ -3383,14 +3383,14 @@ f! {

pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
if ((*cmsg).cmsg_len as usize) < size_of::<cmsghdr>() {
return core::ptr::null_mut::<cmsghdr>();
return ptr::null_mut::<cmsghdr>();
}
let next = (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
if (next.offset(1)) as usize > max
|| next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max
{
core::ptr::null_mut::<cmsghdr>()
ptr::null_mut::<cmsghdr>()
} else {
next.cast::<cmsghdr>()
}
Expand Down Expand Up @@ -3427,7 +3427,7 @@ f! {
pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
let mut s: u32 = 0;
let size_of_mask = size_of_val(&cpuset.bits[0]);
for i in cpuset.bits[..(size / size_of_mask)].iter() {
for i in &cpuset.bits[..(size / size_of_mask)] {
s += i.count_ones();
}
s as c_int
Expand Down
4 changes: 1 addition & 3 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3303,14 +3303,12 @@ f! {
let size_in_bits = 8 * size_of_val(&cpuset.__bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.__bits[idx] |= 1 << offset;
()
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let size_in_bits = 8 * size_of_val(&cpuset.__bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.__bits[idx] &= !(1 << offset);
()
}

pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool {
Expand All @@ -3322,7 +3320,7 @@ f! {
pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
let mut s: u32 = 0;
let size_of_mask = size_of_val(&cpuset.__bits[0]);
for i in cpuset.__bits[..(size / size_of_mask)].iter() {
for i in &cpuset.__bits[..(size / size_of_mask)] {
s += i.count_ones();
}
s as c_int
Expand Down
2 changes: 0 additions & 2 deletions src/unix/linux_like/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,14 +1272,12 @@ f! {
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] |= 1 << offset;
()
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] &= !(1 << offset);
()
}

pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool {
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 @@ -1512,7 +1512,7 @@ f! {
if next_cmsg as usize + size_of::<crate::cmsghdr>() > max_addr {
core::ptr::null_mut::<crate::cmsghdr>()
} else {
next_cmsg as *mut crate::cmsghdr
next_cmsg.cast_mut()
}
}

Expand Down
Loading