fix some lints caught by Clippy

Most of these changes are very simple. Among the changes made involve
taking advantage of auto-deref (`(*val).foo()` -> `val.foo()`) and
removing instances where we create a ref and immediately dereference it
(`&*val` -> `val`). There was a pretty neat case in `posix_openpt` where
some pointer verbosity was able to be reduced by using the more modern C
strings rather than the byte strings with an explicit NUL at the end.

Additionally, `exit()` now calls `unreachable!()` at the end. We
previously did `loop {}`, but clippy didn't like this. It can be up for
debate whether we want to make this `unreachable_unchecked` or similar.

There is only one change that might cause any sort of concern, and that
is the change from `.skip_while(!p).next()` -> `.find(p)`. This, like
everything else, was caught in a Clippy lint but I believe it deserves
some explanation because it isn't immediately obvious. Info about the
lint is here: https://rust-lang.github.io/rust-clippy/rust-1.89.0/index.html#skip_while_next
This commit is contained in:
Connor-GH
2026-04-30 19:02:35 -05:00
parent c1912066a1
commit 7c8259dfd6
11 changed files with 14 additions and 15 deletions
+1 -1
View File
@@ -200,7 +200,7 @@ impl<'a, T> IntoIterator for &'a CVec<T> {
type Item = <&'a [T] as IntoIterator>::Item;
type IntoIter = <&'a [T] as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
<&[T]>::into_iter(&*self)
<&[T]>::into_iter(self)
}
}
impl<'a, T> IntoIterator for &'a mut CVec<T> {
+1 -1
View File
@@ -449,7 +449,7 @@ pub unsafe extern "C" fn getgrent() -> *mut group {
#[unsafe(no_mangle)]
pub unsafe extern "C" fn endgrent() {
unsafe {
*(&mut *LINE_READER.get()) = None;
*LINE_READER.get() = None;
}
}
+2 -2
View File
@@ -59,7 +59,7 @@ impl Dns {
}
pub fn parse(data: &[u8]) -> Result<Self, String> {
let name_ind = 0b1100_0000;
let name_ind = 0b1100_0000u8;
let mut i = 0;
macro_rules! pop_u8 {
@@ -106,7 +106,7 @@ impl Dns {
let name_len = pop_u8!();
if name_len & name_ind == name_ind {
i -= 1;
i = (pop_n16!() - ((name_ind as u16) << 8)) as usize;
i = (pop_n16!() - ((u16::from(name_ind)) << 8)) as usize;
continue;
}
if name_len == 0 {
+2 -2
View File
@@ -63,7 +63,7 @@ pub fn lookup_host(host: &str) -> Result<LookupHost, c_int> {
let packet_data_len = packet_data.len();
let packet_data_box = packet_data.into_boxed_slice();
let packet_data_ptr = Box::into_raw(packet_data_box) as *mut _ as *mut c_void;
let packet_data_ptr = Box::into_raw(packet_data_box).cast::<c_void>();
let dest = sockaddr_in {
sin_family: AF_INET as u16,
@@ -164,7 +164,7 @@ pub fn lookup_addr(addr: in_addr) -> Result<Vec<Vec<u8>>, c_int> {
let packet_data = packet.compile();
let packet_data_len = packet_data.len();
let packet_data_box = packet_data.into_boxed_slice();
let packet_data_ptr = Box::into_raw(packet_data_box) as *mut _ as *mut c_void;
let packet_data_ptr = Box::into_raw(packet_data_box).cast::<c_void>();
let dest = sockaddr_in {
sin_family: AF_INET as u16,
+1 -1
View File
@@ -203,7 +203,7 @@ pub unsafe extern "C" fn ppoll(
-1
} else {
let tmo = unsafe { &*tmo_p };
if tmo.tv_sec > (c_int::MAX / 1000) as _ {
if tmo.tv_sec > (c_int::MAX / 1000).into() {
c_int::MAX
} else {
((tmo.tv_sec as c_int) * 1000) + ((tmo.tv_nsec as c_int) / 1000000)
+1 -2
View File
@@ -1275,8 +1275,7 @@ pub unsafe extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut
[tmpdir, dir, P_tmpdir.as_ptr().cast()]
.iter()
.copied()
.skip_while(|&d| !unsafe { is_appropriate(d) })
.next()
.find(|&d| unsafe { is_appropriate(d) })
.unwrap_or(c"/tmp".as_ptr().cast())
};
let dirname_len = unsafe { string::strlen(dirname) };
+2 -2
View File
@@ -920,10 +920,10 @@ pub unsafe extern "C" fn posix_memalign(
#[unsafe(no_mangle)]
pub unsafe extern "C" fn posix_openpt(flags: c_int) -> c_int {
#[cfg(target_os = "redox")]
let r = unsafe { open((b"/scheme/pty\0" as *const u8).cast(), O_CREAT) };
let r = unsafe { open(c"/scheme/pty".as_ptr(), O_CREAT) };
#[cfg(target_os = "linux")]
let r = unsafe { open((b"/dev/ptmx\0" as *const u8).cast(), flags) };
let r = unsafe { open(c"/dev/ptmx".as_ptr(), flags) };
if r < 0 && platform::ERRNO.get() == ENOSPC {
platform::ERRNO.set(EAGAIN);
+1 -1
View File
@@ -1261,7 +1261,7 @@ unsafe fn with_argv(
// NULL
unsafe { va.arg::<*const c_char>() };
f(unsafe { (&*out).assume_init_ref() }, va);
f(unsafe { out.assume_init_ref() }, va);
// f only returns if it fails
if argc >= 32 {
+1 -1
View File
@@ -1040,7 +1040,7 @@ pub unsafe extern "C" fn vfwscanf(
unsafe {
let format = WStr::from_ptr(format);
wscanf::scanf(reader, format.into(), __valist)
wscanf::scanf(reader, format, __valist)
}
}
+1 -1
View File
@@ -775,7 +775,7 @@ impl DSO {
let strtab_size = strtab_size.expect("mandatory DT_STRSZ not present");
let dynstrtab = StringTable::new(
&*mmap,
mmap,
strtab_offset as u64,
strtab_offset as u64 + strtab_size as u64,
);
+1 -1
View File
@@ -164,7 +164,7 @@ impl Pal for Sys {
unsafe {
syscall!(EXIT, status);
}
loop {}
unreachable!();
}
unsafe fn exit_thread(_stack_base: *mut (), _stack_size: usize) -> ! {
// TODO