Skip to content

Commit 69d42c8

Browse files
authored
Miscellaneous clippy fixes. (#1377)
Add `#[non_exhaustive]` to several more types, for better future evolution.
1 parent ddf53b0 commit 69d42c8

File tree

14 files changed

+47
-34
lines changed

14 files changed

+47
-34
lines changed

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ them with field values and `..Default::default()`, construct them with
7070

7171
[`rustix::io_uring`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/index.html
7272

73+
[`rustix::process::Resource`], [`rustix::thread::MembarrierCommand`], and
74+
[`rustix::thread::Capability`] are now marked `#[non_exhaustive]` to ease
75+
migration in case new constants are defined in the future.
76+
77+
[`rustix::process::Resource`]: https://docs.rs/rustix/1.0.0/rustix/process/enum.Resource.html
78+
[`rustix::thread::MembarrierCommand`]: https://docs.rs/rustix/1.0.0/rustix/thread/enum.MembarrierCommand.html
79+
[`rustix::thread::Capability`]: https://docs.rs/rustix/1.0.0/rustix/thread/enum.Capability.html
80+
7381
`rustix::process::WaitidOptions` and `rustix::process::WaitidStatus` are
7482
renamed to
7583
[`rustix::process::WaitIdOptions`] and [`rustix::process::WaitIdStatus`] (note

src/backend/libc/process/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::backend::c;
2424
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2525
#[cfg_attr(not(target_os = "l4re"), repr(u32))]
2626
#[cfg_attr(target_os = "l4re", repr(u64))]
27+
#[non_exhaustive]
2728
pub enum Resource {
2829
/// `RLIMIT_CPU`
2930
Cpu = bitcast!(c::RLIMIT_CPU),

src/backend/libc/thread/syscalls.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,8 @@ unsafe fn futex_old_timespec(
631631

632632
let old_timeout = if let Some(timeout) = timeout {
633633
Some(linux_raw_sys::general::__kernel_old_timespec {
634-
tv_sec: (*timeout).tv_sec.try_into().map_err(|_| io::Errno::INVAL)?,
635-
tv_nsec: (*timeout)
636-
.tv_nsec
637-
.try_into()
638-
.map_err(|_| io::Errno::INVAL)?,
634+
tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::INVAL)?,
635+
tv_nsec: timeout.tv_nsec.try_into().map_err(|_| io::Errno::INVAL)?,
639636
})
640637
} else {
641638
None

src/backend/libc/thread/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::backend::c;
1414
#[cfg(linux_kernel)]
1515
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
1616
#[repr(u32)]
17+
#[non_exhaustive]
1718
pub enum MembarrierCommand {
1819
/// `MEMBARRIER_CMD_GLOBAL`
1920
#[doc(alias = "Shared")]

src/backend/linux_raw/event/syscalls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: Option<&Timespec>) -> io::Re
3535
// a `__kernel_old_timespec`, the use `__NR_ppoll`.
3636
fn convert(timeout: &Timespec) -> Option<__kernel_old_timespec> {
3737
Some(__kernel_old_timespec {
38-
tv_sec: (*timeout).tv_sec.try_into().ok()?,
39-
tv_nsec: (*timeout).tv_nsec.try_into().ok()?,
38+
tv_sec: timeout.tv_sec.try_into().ok()?,
39+
tv_nsec: timeout.tv_nsec.try_into().ok()?,
4040
})
4141
}
4242
let old_timeout = if let Some(timeout) = timeout {
@@ -151,8 +151,8 @@ pub(crate) unsafe fn select(
151151
// a `__kernel_old_timespec`, the use `__NR_pselect6`.
152152
fn convert(timeout: &Timespec) -> Option<__kernel_old_timespec> {
153153
Some(__kernel_old_timespec {
154-
tv_sec: (*timeout).tv_sec.try_into().ok()?,
155-
tv_nsec: (*timeout).tv_nsec.try_into().ok()?,
154+
tv_sec: timeout.tv_sec.try_into().ok()?,
155+
tv_nsec: timeout.tv_nsec.try_into().ok()?,
156156
})
157157
}
158158
let old_timeout = if let Some(timeout) = timeout {

src/backend/linux_raw/fs/syscalls.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -763,17 +763,17 @@ fn stat_to_stat(s64: linux_raw_sys::general::stat64) -> io::Result<Stat> {
763763
st_size: s64.st_size.try_into().map_err(|_| io::Errno::OVERFLOW)?,
764764
st_blksize: s64.st_blksize.try_into().map_err(|_| io::Errno::OVERFLOW)?,
765765
st_blocks: s64.st_blocks.try_into().map_err(|_| io::Errno::OVERFLOW)?,
766-
st_atime: i64::from(s64.st_atime.as_signed()),
766+
st_atime: i64::from(s64.st_atime.to_signed()),
767767
st_atime_nsec: s64
768768
.st_atime_nsec
769769
.try_into()
770770
.map_err(|_| io::Errno::OVERFLOW)?,
771-
st_mtime: i64::from(s64.st_mtime.as_signed()),
771+
st_mtime: i64::from(s64.st_mtime.to_signed()),
772772
st_mtime_nsec: s64
773773
.st_mtime_nsec
774774
.try_into()
775775
.map_err(|_| io::Errno::OVERFLOW)?,
776-
st_ctime: i64::from(s64.st_ctime.as_signed()),
776+
st_ctime: i64::from(s64.st_ctime.to_signed()),
777777
st_ctime_nsec: s64
778778
.st_ctime_nsec
779779
.try_into()
@@ -795,17 +795,17 @@ fn stat_to_stat(s: linux_raw_sys::general::stat) -> io::Result<Stat> {
795795
st_size: s.st_size.try_into().map_err(|_| io::Errno::OVERFLOW)?,
796796
st_blksize: s.st_blksize.try_into().map_err(|_| io::Errno::OVERFLOW)?,
797797
st_blocks: s.st_blocks.try_into().map_err(|_| io::Errno::OVERFLOW)?,
798-
st_atime: i64::from(s.st_atime.as_signed()),
798+
st_atime: i64::from(s.st_atime.to_signed()),
799799
st_atime_nsec: s
800800
.st_atime_nsec
801801
.try_into()
802802
.map_err(|_| io::Errno::OVERFLOW)?,
803-
st_mtime: i64::from(s.st_mtime.as_signed()),
803+
st_mtime: i64::from(s.st_mtime.to_signed()),
804804
st_mtime_nsec: s
805805
.st_mtime_nsec
806806
.try_into()
807807
.map_err(|_| io::Errno::OVERFLOW)?,
808-
st_ctime: i64::from(s.st_ctime.as_signed()),
808+
st_ctime: i64::from(s.st_ctime.to_signed()),
809809
st_ctime_nsec: s
810810
.st_ctime_nsec
811811
.try_into()
@@ -1683,36 +1683,36 @@ fn test_sizes() {
16831683
target_arch = "mips64",
16841684
target_arch = "mips64r6"
16851685
))]
1686-
mod as_signed {
1687-
pub(super) trait AsSigned {
1686+
mod to_signed {
1687+
pub(super) trait ToSigned {
16881688
type Signed;
1689-
fn as_signed(self) -> Self::Signed;
1689+
fn to_signed(self) -> Self::Signed;
16901690
}
1691-
impl AsSigned for u32 {
1691+
impl ToSigned for u32 {
16921692
type Signed = i32;
16931693

1694-
fn as_signed(self) -> Self::Signed {
1694+
fn to_signed(self) -> Self::Signed {
16951695
self as _
16961696
}
16971697
}
1698-
impl AsSigned for i32 {
1698+
impl ToSigned for i32 {
16991699
type Signed = i32;
17001700

1701-
fn as_signed(self) -> Self::Signed {
1701+
fn to_signed(self) -> Self::Signed {
17021702
self
17031703
}
17041704
}
1705-
impl AsSigned for u64 {
1705+
impl ToSigned for u64 {
17061706
type Signed = i64;
17071707

1708-
fn as_signed(self) -> Self::Signed {
1708+
fn to_signed(self) -> Self::Signed {
17091709
self as _
17101710
}
17111711
}
1712-
impl AsSigned for i64 {
1712+
impl ToSigned for i64 {
17131713
type Signed = i64;
17141714

1715-
fn as_signed(self) -> Self::Signed {
1715+
fn to_signed(self) -> Self::Signed {
17161716
self
17171717
}
17181718
}
@@ -1722,4 +1722,4 @@ mod as_signed {
17221722
target_arch = "mips64",
17231723
target_arch = "mips64r6"
17241724
))]
1725-
use as_signed::*;
1725+
use to_signed::*;

src/backend/linux_raw/net/addr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl SocketAddrUnix {
103103
if !bytes.is_empty() && bytes[0] != 0 {
104104
if self.unix.sun_path.len() == bytes.len() {
105105
// SAFETY: no NULs are contained in bytes
106-
unsafe { self.path_with_termination(bytes) }
106+
unsafe { Self::path_with_termination(bytes) }
107107
} else {
108108
// SAFETY: `from_bytes_with_nul_unchecked` since the string is
109109
// NUL-terminated.
@@ -118,7 +118,8 @@ impl SocketAddrUnix {
118118
///
119119
/// SAFETY: the input `bytes` must not contain any NULs
120120
#[cfg(feature = "alloc")]
121-
unsafe fn path_with_termination(&self, bytes: &[u8]) -> Option<Cow<'_, CStr>> {
121+
#[cold]
122+
unsafe fn path_with_termination(bytes: &[u8]) -> Option<Cow<'_, CStr>> {
122123
let mut owned = Vec::with_capacity(bytes.len() + 1);
123124
owned.extend_from_slice(bytes);
124125
owned.push(b'\0');

src/backend/linux_raw/process/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/// [`prlimit`]: crate::process::prlimit
77
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
88
#[repr(u32)]
9+
#[non_exhaustive]
910
pub enum Resource {
1011
/// `RLIMIT_CPU`
1112
Cpu = linux_raw_sys::general::RLIMIT_CPU,

src/backend/linux_raw/runtime/syscalls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::signal::Signal;
2626
use crate::timespec::Timespec;
2727
use core::ffi::c_void;
2828
use core::mem::MaybeUninit;
29-
#[cfg(target_pointer_width = "32")]
29+
#[cfg(all(target_pointer_width = "32", not(feature = "linux_5_1")))]
3030
use linux_raw_sys::general::__kernel_old_timespec;
3131
#[cfg(target_arch = "x86_64")]
3232
use linux_raw_sys::general::ARCH_SET_FS;
@@ -266,8 +266,8 @@ pub(crate) unsafe fn kernel_sigtimedwait(
266266
// a `__kernel_old_timespec`, the use `__NR_futex`.
267267
fn convert(timeout: &Timespec) -> Option<__kernel_old_timespec> {
268268
Some(__kernel_old_timespec {
269-
tv_sec: (*timeout).tv_sec.try_into().ok()?,
270-
tv_nsec: (*timeout).tv_nsec.try_into().ok()?,
269+
tv_sec: timeout.tv_sec.try_into().ok()?,
270+
tv_nsec: timeout.tv_nsec.try_into().ok()?,
271271
})
272272
}
273273
let old_timeout = if let Some(timeout) = timeout {

src/backend/linux_raw/thread/syscalls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ pub(crate) unsafe fn futex_timeout(
292292
// a `__kernel_old_timespec`, the use `__NR_futex`.
293293
fn convert(timeout: &Timespec) -> Option<__kernel_old_timespec> {
294294
Some(__kernel_old_timespec {
295-
tv_sec: (*timeout).tv_sec.try_into().ok()?,
296-
tv_nsec: (*timeout).tv_nsec.try_into().ok()?,
295+
tv_sec: timeout.tv_sec.try_into().ok()?,
296+
tv_nsec: timeout.tv_nsec.try_into().ok()?,
297297
})
298298
}
299299
let old_timeout = if let Some(timeout) = timeout {

0 commit comments

Comments
 (0)