Skip to content

Commit f36363c

Browse files
authored
Miscellaneous clippy fixes. (#696)
1 parent de35289 commit f36363c

File tree

17 files changed

+77
-46
lines changed

17 files changed

+77
-46
lines changed

benches/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
target_os = "wasi",
1919
))]
2020
fn main() {
21-
unimplemented!("Add --cfg=criterion to RUSTFLAGS and enable the \"fs\", \"time\", and \"process\" cargo features.")
21+
unimplemented!(
22+
"Add --cfg=criterion to RUSTFLAGS and enable the \"fs\", \"time\", and \"process\" cargo \
23+
features."
24+
)
2225
}
2326

2427
#[cfg(not(any(

src/backend/libc/event/epoll.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,14 @@ pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> i
268268

269269
/// An iterator over the `Event`s in an `EventVec`.
270270
pub struct Iter<'a> {
271-
iter: slice::Iter<'a, Event>,
271+
/// Use `Copied` to copy the struct, since `Event` is `packed` on some
272+
/// platforms, and it's common for users to directly destructure it,
273+
/// which would lead to errors about forming references to packed fields.
274+
iter: core::iter::Copied<slice::Iter<'a, Event>>,
272275
}
273276

274277
impl<'a> Iterator for Iter<'a> {
275-
type Item = &'a Event;
278+
type Item = Event;
276279

277280
#[inline]
278281
fn next(&mut self) -> Option<Self::Item> {
@@ -293,6 +296,7 @@ impl<'a> Iterator for Iter<'a> {
293296
),
294297
repr(packed)
295298
)]
299+
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
296300
pub struct Event {
297301
/// Which specific event(s) occurred.
298302
pub flags: EventFlags,
@@ -354,7 +358,7 @@ impl EventData {
354358

355359
impl PartialEq for EventData {
356360
#[inline]
357-
fn eq(&self, other: &EventData) -> bool {
361+
fn eq(&self, other: &Self) -> bool {
358362
self.u64() == other.u64()
359363
}
360364
}
@@ -444,7 +448,7 @@ impl EventVec {
444448
#[inline]
445449
pub fn iter(&self) -> Iter<'_> {
446450
Iter {
447-
iter: self.events.iter(),
451+
iter: self.events.iter().copied(),
448452
}
449453
}
450454

@@ -463,7 +467,7 @@ impl EventVec {
463467

464468
impl<'a> IntoIterator for &'a EventVec {
465469
type IntoIter = Iter<'a>;
466-
type Item = &'a Event;
470+
type Item = Event;
467471

468472
#[inline]
469473
fn into_iter(self) -> Self::IntoIter {

src/backend/libc/fs/syscalls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,13 @@ pub(crate) fn copy_file_range(
977977
let mut off_out_val: c::loff_t = 0;
978978
// Silently cast; we'll get `EINVAL` if the value is negative.
979979
let off_in_ptr = if let Some(off_in) = &off_in {
980-
off_in_val = (**off_in) as i64;
980+
off_in_val = **off_in as i64;
981981
&mut off_in_val
982982
} else {
983983
null_mut()
984984
};
985985
let off_out_ptr = if let Some(off_out) = &off_out {
986-
off_out_val = (**off_out) as i64;
986+
off_out_val = **off_out as i64;
987987
&mut off_out_val
988988
} else {
989989
null_mut()

src/backend/libc/io/syscalls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ pub(crate) fn is_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> {
286286
if unsafe { c::send(borrowed_fd(fd), [].as_ptr(), 0, c::MSG_DONTWAIT) } == -1 {
287287
#[allow(unreachable_patterns)] // `EAGAIN` may equal `EWOULDBLOCK`
288288
match errno().0 {
289-
c::EAGAIN | c::EWOULDBLOCK => (),
290-
c::ENOTSOCK => (),
289+
c::EAGAIN | c::EWOULDBLOCK | c::ENOTSOCK => (),
291290
c::EPIPE => write = false,
292291
err => return Err(io::Errno(err)),
293292
}

src/backend/libc/process/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub const EXIT_SIGNALED_SIGABRT: c::c_int = 128 + c::SIGABRT;
111111
/// A CPU identifier as a raw integer.
112112
#[cfg(linux_kernel)]
113113
pub type RawCpuid = u32;
114-
#[cfg(target_os = "freebsd")]
114+
#[cfg(freebsdlike)]
115115
pub type RawId = c::id_t;
116116

117117
#[cfg(any(linux_kernel, target_os = "dragonfly", target_os = "fuchsia"))]

src/backend/linux_raw/event/epoll.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,14 @@ pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> i
254254

255255
/// An iterator over the `Event`s in an `EventVec`.
256256
pub struct Iter<'a> {
257-
iter: slice::Iter<'a, Event>,
257+
/// Use `Copied` to copy the struct, since `Event` is `packed` on some
258+
/// platforms, and it's common for users to directly destructure it,
259+
/// which would lead to errors about forming references to packed fields.
260+
iter: core::iter::Copied<slice::Iter<'a, Event>>,
258261
}
259262

260263
impl<'a> Iterator for Iter<'a> {
261-
type Item = &'a Event;
264+
type Item = Event;
262265

263266
#[inline]
264267
fn next(&mut self) -> Option<Self::Item> {
@@ -269,6 +272,7 @@ impl<'a> Iterator for Iter<'a> {
269272
/// A record of an event that occurred.
270273
#[repr(C)]
271274
#[cfg_attr(target_arch = "x86_64", repr(packed))]
275+
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
272276
pub struct Event {
273277
/// Which specific event(s) occurred.
274278
pub flags: EventFlags,
@@ -420,7 +424,7 @@ impl EventVec {
420424
#[inline]
421425
pub fn iter(&self) -> Iter<'_> {
422426
Iter {
423-
iter: self.events.iter(),
427+
iter: self.events.iter().copied(),
424428
}
425429
}
426430

@@ -439,7 +443,7 @@ impl EventVec {
439443

440444
impl<'a> IntoIterator for &'a EventVec {
441445
type IntoIter = Iter<'a>;
442-
type Item = &'a Event;
446+
type Item = Event;
443447

444448
#[inline]
445449
fn into_iter(self) -> Self::IntoIter {

src/backend/linux_raw/net/read_sockaddr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(crate) unsafe fn read_sockaddr(
6262
if len < size_of::<c::sockaddr_in>() {
6363
return Err(io::Errno::INVAL);
6464
}
65-
let decode = *storage.cast::<c::sockaddr_in>();
65+
let decode = &*storage.cast::<c::sockaddr_in>();
6666
Ok(SocketAddrAny::V4(SocketAddrV4::new(
6767
Ipv4Addr::from(u32::from_be(decode.sin_addr.s_addr)),
6868
u16::from_be(decode.sin_port),
@@ -72,7 +72,7 @@ pub(crate) unsafe fn read_sockaddr(
7272
if len < size_of::<c::sockaddr_in6>() {
7373
return Err(io::Errno::INVAL);
7474
}
75-
let decode = *storage.cast::<c::sockaddr_in6>();
75+
let decode = &*storage.cast::<c::sockaddr_in6>();
7676
Ok(SocketAddrAny::V6(SocketAddrV6::new(
7777
Ipv6Addr::from(decode.sin6_addr.in6_u.u6_addr8),
7878
u16::from_be(decode.sin6_port),
@@ -87,7 +87,7 @@ pub(crate) unsafe fn read_sockaddr(
8787
if len == offsetof_sun_path {
8888
Ok(SocketAddrAny::Unix(SocketAddrUnix::new(&[][..])?))
8989
} else {
90-
let decode = *storage.cast::<c::sockaddr_un>();
90+
let decode = &*storage.cast::<c::sockaddr_un>();
9191

9292
// On Linux check for Linux's [abstract namespace].
9393
//
@@ -138,15 +138,15 @@ pub(crate) unsafe fn read_sockaddr_os(storage: *const c::sockaddr, len: usize) -
138138
match read_ss_family(storage).into() {
139139
c::AF_INET => {
140140
assert!(len >= size_of::<c::sockaddr_in>());
141-
let decode = *storage.cast::<c::sockaddr_in>();
141+
let decode = &*storage.cast::<c::sockaddr_in>();
142142
SocketAddrAny::V4(SocketAddrV4::new(
143143
Ipv4Addr::from(u32::from_be(decode.sin_addr.s_addr)),
144144
u16::from_be(decode.sin_port),
145145
))
146146
}
147147
c::AF_INET6 => {
148148
assert!(len >= size_of::<c::sockaddr_in6>());
149-
let decode = *storage.cast::<c::sockaddr_in6>();
149+
let decode = &*storage.cast::<c::sockaddr_in6>();
150150
SocketAddrAny::V6(SocketAddrV6::new(
151151
Ipv6Addr::from(decode.sin6_addr.in6_u.u6_addr8),
152152
u16::from_be(decode.sin6_port),
@@ -159,7 +159,7 @@ pub(crate) unsafe fn read_sockaddr_os(storage: *const c::sockaddr, len: usize) -
159159
if len == offsetof_sun_path {
160160
SocketAddrAny::Unix(SocketAddrUnix::new(&[][..]).unwrap())
161161
} else {
162-
let decode = *storage.cast::<c::sockaddr_un>();
162+
let decode = &*storage.cast::<c::sockaddr_un>();
163163

164164
// On Linux check for Linux's [abstract namespace].
165165
//

src/event/kqueue.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ impl Event {
124124
ident: self.inner.ident as _,
125125
timer: {
126126
let (data, fflags) = (self.inner.data, self.inner.fflags);
127+
#[cfg(not(any(apple, target_os = "freebsd", target_os = "netbsd")))]
128+
let _ = fflags;
127129
#[cfg(any(apple, target_os = "freebsd", target_os = "netbsd"))]
128130
match fflags as _ {
129131
c::NOTE_SECONDS => Some(Duration::from_secs(data as _)),

src/process/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use crate::ugid::{Gid, Uid};
3030
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
3131
pub struct Cpuid(RawCpuid);
3232

33-
#[cfg(any(target_os = "android", target_os = "linux"))]
33+
#[cfg(linux_kernel)]
3434
impl Cpuid {
3535
/// Converts a `RawCpuid` into a `Cpuid`.
3636
///

src/process/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod pidfd_getfd;
2020
mod prctl;
2121
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] // WASI doesn't have [gs]etpriority.
2222
mod priority;
23-
#[cfg(target_os = "freebsd")]
23+
#[cfg(freebsdlike)]
2424
mod procctl;
2525
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
2626
mod rlimit;
@@ -52,7 +52,7 @@ pub use pidfd_getfd::*;
5252
pub use prctl::*;
5353
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
5454
pub use priority::*;
55-
#[cfg(target_os = "freebsd")]
55+
#[cfg(freebsdlike)]
5656
pub use procctl::*;
5757
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
5858
pub use rlimit::*;

0 commit comments

Comments
 (0)