Skip to content

Commit 91d51fe

Browse files
committed
Enable the rust_2024_compatibility lint
Enable this lint with the expectation that we will eventually be upgrading editions. There are some exceptions needed, and `unsafe_op_in_unsafe_fn` will take a while to go through.
1 parent b94681f commit 91d51fe

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
unused_macros,
1111
unused_macro_rules,
1212
)]
13+
// Prepare for a future upgrade
14+
#![warn(rust_2024_compatibility)]
15+
// Things missing for 2024 that are blocked on MSRV or breakage
16+
#![allow(
17+
missing_unsafe_on_extern,
18+
edition_2024_expr_fragment_specifier,
19+
// Allowed globally, the warning is enabled in individual modules as we work through them
20+
unsafe_op_in_unsafe_fn
21+
)]
1322
#![cfg_attr(libc_deny_warnings, deny(warnings))]
1423
// Attributes needed when building as part of the standard library
1524
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]

src/unix/bsd/apple/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ impl siginfo_t {
16531653
si_value: crate::sigval,
16541654
}
16551655

1656-
(*(self as *const siginfo_t).cast::<siginfo_timer>()).si_value
1656+
unsafe { (*(self as *const siginfo_t).cast::<siginfo_timer>()).si_value }
16571657
}
16581658

16591659
pub unsafe fn si_pid(&self) -> crate::pid_t {
@@ -5025,11 +5025,11 @@ pub const MAX_KCTL_NAME: usize = 96;
50255025
f! {
50265026
pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
50275027
if cmsg.is_null() {
5028-
return crate::CMSG_FIRSTHDR(mhdr);
5028+
return unsafe { crate::CMSG_FIRSTHDR(mhdr) };
50295029
}
5030-
let cmsg_len = (*cmsg).cmsg_len as usize;
5030+
let cmsg_len = unsafe { (*cmsg).cmsg_len as usize };
50315031
let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len);
5032-
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
5032+
let max = unsafe { (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize };
50335033
if next + __DARWIN_ALIGN32(size_of::<cmsghdr>()) > max {
50345034
core::ptr::null_mut()
50355035
} else {
@@ -5038,7 +5038,7 @@ f! {
50385038
}
50395039

50405040
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
5041-
(cmsg as *mut c_uchar).add(__DARWIN_ALIGN32(size_of::<cmsghdr>()))
5041+
(cmsg as *mut c_uchar).wrapping_add(__DARWIN_ALIGN32(size_of::<cmsghdr>()))
50425042
}
50435043

50445044
pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {

src/unix/bsd/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(unsafe_op_in_unsafe_fn)]
2+
13
use crate::prelude::*;
24

35
pub type off_t = i64;
@@ -573,35 +575,40 @@ pub const RTAX_BRD: c_int = 7;
573575

574576
f! {
575577
pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr {
576-
if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() {
577-
(*mhdr).msg_control.cast::<cmsghdr>()
578+
let ctrl_len = unsafe { (*mhdr).msg_controllen } as usize;
579+
if ctrl_len >= size_of::<cmsghdr>() {
580+
let ptr = unsafe { (*mhdr).msg_control };
581+
ptr.cast::<cmsghdr>()
578582
} else {
579583
core::ptr::null_mut()
580584
}
581585
}
582586

583587
pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
584-
let bits = size_of_val(&(*set).fds_bits[0]) * 8;
588+
let bits = unsafe { size_of_val( &(*set).fds_bits[0] ) * 8 };
585589
let fd = fd as usize;
586-
(*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
590+
let mask = !(1 << (fd % bits));
591+
unsafe { (*set).fds_bits[fd / bits] &= mask };
587592
return;
588593
}
589594

590595
pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
591-
let bits = size_of_val(&(*set).fds_bits[0]) * 8;
596+
let bits = unsafe { size_of_val(&(*set).fds_bits[0]) * 8 };
592597
let fd = fd as usize;
593-
return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0;
598+
let bit = unsafe { (*set).fds_bits[fd / bits] };
599+
return (bit & (1 << (fd % bits))) != 0;
594600
}
595601

596602
pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
597-
let bits = size_of_val(&(*set).fds_bits[0]) * 8;
603+
let bits = unsafe { size_of_val(&(*set).fds_bits[0]) * 8 };
598604
let fd = fd as usize;
599-
(*set).fds_bits[fd / bits] |= 1 << (fd % bits);
605+
unsafe { (*set).fds_bits[fd / bits] |= 1 << (fd % bits) };
600606
return;
601607
}
602608

603609
pub fn FD_ZERO(set: *mut fd_set) -> () {
604-
for slot in &mut (*set).fds_bits {
610+
let mut bits = unsafe { (*set).fds_bits };
611+
for slot in &mut bits {
605612
*slot = 0;
606613
}
607614
}

0 commit comments

Comments
 (0)