Skip to content

Commit f4f46e3

Browse files
committed
Fix clippy lints
Signed-off-by: Alex Saveau <[email protected]>
1 parent 967e3de commit f4f46e3

File tree

10 files changed

+96
-99
lines changed

10 files changed

+96
-99
lines changed

src/sys/aio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl AioCb {
163163
0 => Ok(()),
164164
num if num > 0 => Err(Errno::from_i32(num)),
165165
-1 => Err(Errno::last()),
166-
num => panic!("unknown aio_error return value {:?}", num),
166+
num => panic!("unknown aio_error return value {num:?}"),
167167
}
168168
}
169169

src/sys/socket/addr.rs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,15 @@ pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr {
4444
static_assertions::assert_eq_size!(net::Ipv4Addr, libc::in_addr);
4545
// Safe because both types have the same memory layout, and no fancy Drop
4646
// impls.
47-
unsafe {
48-
mem::transmute(addr)
49-
}
47+
unsafe { mem::transmute(addr) }
5048
}
5149

5250
/// Convert a std::net::Ipv6Addr into the libc form.
5351
#[cfg(feature = "net")]
5452
pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr {
5553
static_assertions::assert_eq_size!(net::Ipv6Addr, libc::in6_addr);
5654
// Safe because both are Newtype wrappers around the same libc type
57-
unsafe {
58-
mem::transmute(*addr)
59-
}
55+
unsafe { mem::transmute(*addr) }
6056
}
6157

6258
/// These constants specify the protocol family to be used
@@ -81,7 +77,11 @@ pub enum AddressFamily {
8177
#[cfg_attr(docsrs, doc(cfg(all())))]
8278
Netlink = libc::AF_NETLINK,
8379
/// Kernel interface for interacting with the routing table
84-
#[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))]
80+
#[cfg(not(any(
81+
target_os = "redox",
82+
target_os = "linux",
83+
target_os = "android"
84+
)))]
8585
Route = libc::PF_ROUTE,
8686
/// Low level packet interface (see [`packet(7)`](https://man7.org/linux/man-pages/man7/packet.7.html))
8787
#[cfg(any(
@@ -424,7 +424,11 @@ impl AddressFamily {
424424
libc::AF_NETLINK => Some(AddressFamily::Netlink),
425425
#[cfg(any(target_os = "macos", target_os = "macos"))]
426426
libc::AF_SYSTEM => Some(AddressFamily::System),
427-
#[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))]
427+
#[cfg(not(any(
428+
target_os = "redox",
429+
target_os = "linux",
430+
target_os = "android"
431+
)))]
428432
libc::PF_ROUTE => Some(AddressFamily::Route),
429433
#[cfg(any(target_os = "android", target_os = "linux"))]
430434
libc::AF_PACKET => Some(AddressFamily::Packet),
@@ -550,7 +554,7 @@ impl InetAddr {
550554

551555
#[deprecated(since = "0.23.0", note = "use .to_string() instead")]
552556
pub fn to_str(&self) -> String {
553-
format!("{}", self)
557+
format!("{self}")
554558
}
555559
}
556560

@@ -896,10 +900,11 @@ impl UnixAddr {
896900
pub fn new_unnamed() -> UnixAddr {
897901
let ret = libc::sockaddr_un {
898902
sun_family: AddressFamily::Unix as sa_family_t,
899-
.. unsafe { mem::zeroed() }
903+
..unsafe { mem::zeroed() }
900904
};
901905

902-
let sun_len: u8 = offset_of!(libc::sockaddr_un, sun_path).try_into().unwrap();
906+
let sun_len: u8 =
907+
offset_of!(libc::sockaddr_un, sun_path).try_into().unwrap();
903908

904909
unsafe { UnixAddr::from_raw_parts(ret, sun_len) }
905910
}
@@ -1572,7 +1577,9 @@ impl SockaddrLike for SockaddrStorage {
15721577
if i32::from(ss.ss_family) == libc::AF_UNIX {
15731578
// Safe because we UnixAddr is strictly smaller than
15741579
// SockaddrStorage, and we just initialized the structure.
1575-
(*(&mut ss as *mut libc::sockaddr_storage as *mut UnixAddr)).sun_len = len as u8;
1580+
(*(&mut ss as *mut libc::sockaddr_storage
1581+
as *mut UnixAddr))
1582+
.sun_len = len as u8;
15761583
}
15771584
Some(Self { ss })
15781585
}
@@ -1647,7 +1654,7 @@ impl SockaddrLike for SockaddrStorage {
16471654
// The UnixAddr type knows its own length
16481655
Some(ua) => ua.len(),
16491656
// For all else, we're just a boring SockaddrStorage
1650-
None => mem::size_of_val(self) as libc::socklen_t
1657+
None => mem::size_of_val(self) as libc::socklen_t,
16511658
}
16521659
}
16531660
}
@@ -1707,12 +1714,13 @@ impl SockaddrStorage {
17071714
}
17081715
}
17091716
// Sanity checks
1710-
if self.family() != Some(AddressFamily::Unix) ||
1711-
len < offset_of!(libc::sockaddr_un, sun_path) ||
1712-
len > mem::size_of::<libc::sockaddr_un>() {
1717+
if self.family() != Some(AddressFamily::Unix)
1718+
|| len < offset_of!(libc::sockaddr_un, sun_path)
1719+
|| len > mem::size_of::<libc::sockaddr_un>()
1720+
{
17131721
None
17141722
} else {
1715-
Some(unsafe{&self.su})
1723+
Some(unsafe { &self.su })
17161724
}
17171725
}
17181726

@@ -1736,12 +1744,13 @@ impl SockaddrStorage {
17361744
}
17371745
}
17381746
// Sanity checks
1739-
if self.family() != Some(AddressFamily::Unix) ||
1740-
len < offset_of!(libc::sockaddr_un, sun_path) ||
1741-
len > mem::size_of::<libc::sockaddr_un>() {
1747+
if self.family() != Some(AddressFamily::Unix)
1748+
|| len < offset_of!(libc::sockaddr_un, sun_path)
1749+
|| len > mem::size_of::<libc::sockaddr_un>()
1750+
{
17421751
None
17431752
} else {
1744-
Some(unsafe{&mut self.su})
1753+
Some(unsafe { &mut self.su })
17451754
}
17461755
}
17471756

@@ -2105,7 +2114,7 @@ impl SockAddr {
21052114

21062115
#[deprecated(since = "0.23.0", note = "use .to_string() instead")]
21072116
pub fn to_str(&self) -> String {
2108-
format!("{}", self)
2117+
format!("{self}")
21092118
}
21102119

21112120
/// Creates a `SockAddr` struct from libc's sockaddr.
@@ -3142,7 +3151,7 @@ mod tests {
31423151
fn display() {
31433152
let s = "127.0.0.1:8080";
31443153
let addr = SockaddrIn::from_str(s).unwrap();
3145-
assert_eq!(s, format!("{}", addr));
3154+
assert_eq!(s, format!("{addr}"));
31463155
}
31473156

31483157
#[test]
@@ -3162,7 +3171,7 @@ mod tests {
31623171
fn display() {
31633172
let s = "[1234:5678:90ab:cdef::1111:2222]:8080";
31643173
let addr = SockaddrIn6::from_str(s).unwrap();
3165-
assert_eq!(s, format!("{}", addr));
3174+
assert_eq!(s, format!("{addr}"));
31663175
}
31673176

31683177
#[test]
@@ -3181,9 +3190,8 @@ mod tests {
31813190
fn from_sockaddr_un_named() {
31823191
let ua = UnixAddr::new("/var/run/mysock").unwrap();
31833192
let ptr = ua.as_ptr() as *const libc::sockaddr;
3184-
let ss = unsafe {
3185-
SockaddrStorage::from_raw(ptr, Some(ua.len()))
3186-
}.unwrap();
3193+
let ss = unsafe { SockaddrStorage::from_raw(ptr, Some(ua.len())) }
3194+
.unwrap();
31873195
assert_eq!(ss.len(), ua.len());
31883196
}
31893197

@@ -3193,9 +3201,8 @@ mod tests {
31933201
let name = String::from("nix\0abstract\0test");
31943202
let ua = UnixAddr::new_abstract(name.as_bytes()).unwrap();
31953203
let ptr = ua.as_ptr() as *const libc::sockaddr;
3196-
let ss = unsafe {
3197-
SockaddrStorage::from_raw(ptr, Some(ua.len()))
3198-
}.unwrap();
3204+
let ss = unsafe { SockaddrStorage::from_raw(ptr, Some(ua.len())) }
3205+
.unwrap();
31993206
assert_eq!(ss.len(), ua.len());
32003207
}
32013208

@@ -3204,9 +3211,8 @@ mod tests {
32043211
fn from_sockaddr_un_abstract_unnamed() {
32053212
let ua = UnixAddr::new_unnamed();
32063213
let ptr = ua.as_ptr() as *const libc::sockaddr;
3207-
let ss = unsafe {
3208-
SockaddrStorage::from_raw(ptr, Some(ua.len()))
3209-
}.unwrap();
3214+
let ss = unsafe { SockaddrStorage::from_raw(ptr, Some(ua.len())) }
3215+
.unwrap();
32103216
assert_eq!(ss.len(), ua.len());
32113217
}
32123218
}

src/sys/socket/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl TryFrom<i32> for SockType {
121121
libc::SOCK_RAW => Ok(Self::Raw),
122122
#[cfg(not(any(target_os = "haiku")))]
123123
libc::SOCK_RDM => Ok(Self::Rdm),
124-
_ => Err(Errno::EINVAL)
124+
_ => Err(Errno::EINVAL),
125125
}
126126
}
127127
}
@@ -2447,7 +2447,7 @@ pub fn sockaddr_storage_to_addr(
24472447
let svm = unsafe { *(addr as *const _ as *const sockaddr_vm) };
24482448
Ok(SockAddr::Vsock(VsockAddr(svm)))
24492449
}
2450-
af => panic!("unexpected address family {}", af),
2450+
af => panic!("unexpected address family {af}"),
24512451
}
24522452
}
24532453

@@ -2485,7 +2485,11 @@ mod tests {
24852485
let _ = cmsg_space!(u8);
24862486
}
24872487

2488-
#[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))]
2488+
#[cfg(not(any(
2489+
target_os = "redox",
2490+
target_os = "linux",
2491+
target_os = "android"
2492+
)))]
24892493
#[test]
24902494
fn can_open_routing_socket() {
24912495
let _ = super::socket(

src/sys/time.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ impl TimeValLike for TimeSpec {
261261
fn seconds(seconds: i64) -> TimeSpec {
262262
assert!(
263263
(TS_MIN_SECONDS..=TS_MAX_SECONDS).contains(&seconds),
264-
"TimeSpec out of bounds; seconds={}",
265-
seconds
264+
"TimeSpec out of bounds; seconds={seconds}",
266265
);
267266
let mut ts = zero_init_timespec();
268267
ts.tv_sec = seconds as time_t;
@@ -428,20 +427,20 @@ impl fmt::Display for TimeSpec {
428427

429428
let sec = abs.tv_sec();
430429

431-
write!(f, "{}", sign)?;
430+
write!(f, "{sign}")?;
432431

433432
if abs.tv_nsec() == 0 {
434-
if abs.tv_sec() == 1 {
435-
write!(f, "{} second", sec)?;
433+
if sec == 1 {
434+
write!(f, "1 second")?;
436435
} else {
437-
write!(f, "{} seconds", sec)?;
436+
write!(f, "{sec} seconds")?;
438437
}
439438
} else if abs.tv_nsec() % 1_000_000 == 0 {
440-
write!(f, "{}.{:03} seconds", sec, abs.tv_nsec() / 1_000_000)?;
439+
write!(f, "{sec}.{:03} seconds", abs.tv_nsec() / 1_000_000)?;
441440
} else if abs.tv_nsec() % 1_000 == 0 {
442-
write!(f, "{}.{:06} seconds", sec, abs.tv_nsec() / 1_000)?;
441+
write!(f, "{sec}.{:06} seconds", abs.tv_nsec() / 1_000)?;
443442
} else {
444-
write!(f, "{}.{:09} seconds", sec, abs.tv_nsec())?;
443+
write!(f, "{sec}.{:09} seconds", abs.tv_nsec())?;
445444
}
446445

447446
Ok(())
@@ -497,8 +496,7 @@ impl TimeValLike for TimeVal {
497496
fn seconds(seconds: i64) -> TimeVal {
498497
assert!(
499498
(TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&seconds),
500-
"TimeVal out of bounds; seconds={}",
501-
seconds
499+
"TimeVal out of bounds; seconds={seconds}"
502500
);
503501
#[cfg_attr(target_env = "musl", allow(deprecated))]
504502
// https://github.com/rust-lang/libc/issues/1848
@@ -662,18 +660,18 @@ impl fmt::Display for TimeVal {
662660

663661
let sec = abs.tv_sec();
664662

665-
write!(f, "{}", sign)?;
663+
write!(f, "{sign}")?;
666664

667665
if abs.tv_usec() == 0 {
668-
if abs.tv_sec() == 1 {
669-
write!(f, "{} second", sec)?;
666+
if sec == 1 {
667+
write!(f, "1 second")?;
670668
} else {
671-
write!(f, "{} seconds", sec)?;
669+
write!(f, "{sec} seconds")?;
672670
}
673671
} else if abs.tv_usec() % 1000 == 0 {
674-
write!(f, "{}.{:03} seconds", sec, abs.tv_usec() / 1000)?;
672+
write!(f, "{sec}.{:03} seconds", abs.tv_usec() / 1000)?;
675673
} else {
676-
write!(f, "{}.{:06} seconds", sec, abs.tv_usec())?;
674+
write!(f, "{sec}.{:06} seconds", abs.tv_usec())?;
677675
}
678676

679677
Ok(())

test/sys/test_aio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ fn test_aio_suspend() {
610610
let r = aio_suspend(&cbbuf[..], Some(timeout));
611611
match r {
612612
Err(Errno::EINTR) => continue,
613-
Err(e) => panic!("aio_suspend returned {:?}", e),
613+
Err(e) => panic!("aio_suspend returned {e:?}"),
614614
Ok(_) => (),
615615
};
616616
}

test/sys/test_signal.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ fn test_sigprocmask() {
5454
// test don't make sense.
5555
assert!(
5656
!old_signal_set.contains(SIGNAL),
57-
"the {:?} signal is already blocked, please change to a \
58-
different one",
59-
SIGNAL
57+
"the {SIGNAL:?} signal is already blocked, please change to a \
58+
different one"
6059
);
6160

6261
// Now block the signal.
@@ -71,8 +70,7 @@ fn test_sigprocmask() {
7170
.expect("expect to be able to retrieve old signals");
7271
assert!(
7372
old_signal_set.contains(SIGNAL),
74-
"expected the {:?} to be blocked",
75-
SIGNAL
73+
"expected the {SIGNAL:?} to be blocked"
7674
);
7775

7876
// Reset the signal.

test/sys/test_socket.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ mod recvfrom {
722722
println!("IPv6 not available, skipping test.");
723723
return;
724724
}
725-
Err(e) => panic!("bind: {}", e),
725+
Err(e) => panic!("bind: {e}"),
726726
Ok(()) => (),
727727
}
728728
let ssock = socket(
@@ -1368,7 +1368,7 @@ fn test_scm_credentials() {
13681368
ControlMessageOwned::ScmCredentials(cred) => cred,
13691369
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
13701370
ControlMessageOwned::ScmCreds(cred) => cred,
1371-
other => panic!("unexpected cmsg {:?}", other),
1371+
other => panic!("unexpected cmsg {other:?}"),
13721372
};
13731373
assert!(received_cred.is_none());
13741374
assert_eq!(cred.pid(), getpid().as_raw());
@@ -1646,7 +1646,7 @@ fn loopback_address(
16461646
Err(e) => {
16471647
let stdioerr = io::stderr();
16481648
let mut handle = stdioerr.lock();
1649-
writeln!(handle, "getifaddrs: {:?}", e).unwrap();
1649+
writeln!(handle, "getifaddrs: {e:?}").unwrap();
16501650
return None;
16511651
}
16521652
};
@@ -2443,7 +2443,7 @@ mod linux_errqueue {
24432443
}
24442444
*ext_err
24452445
} else {
2446-
panic!("Unexpected control message {:?}", cmsg);
2446+
panic!("Unexpected control message {cmsg:?}");
24472447
}
24482448
},
24492449
)
@@ -2494,7 +2494,7 @@ mod linux_errqueue {
24942494
}
24952495
*ext_err
24962496
} else {
2497-
panic!("Unexpected control message {:?}", cmsg);
2497+
panic!("Unexpected control message {cmsg:?}");
24982498
}
24992499
},
25002500
)
@@ -2528,7 +2528,7 @@ mod linux_errqueue {
25282528
MsgFlags::empty(),
25292529
) {
25302530
assert_eq!(e, Errno::EADDRNOTAVAIL);
2531-
println!("{:?} not available, skipping test.", af);
2531+
println!("{af:?} not available, skipping test.");
25322532
return;
25332533
}
25342534

test/test_fcntl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ mod test_posix_fallocate {
559559
let err = posix_fallocate(rd as RawFd, 0, 100).unwrap_err();
560560
match err {
561561
Errno::EINVAL | Errno::ENODEV | Errno::ESPIPE | Errno::EBADF => (),
562-
errno => panic!("unexpected errno {}", errno,),
562+
errno => panic!("unexpected errno {errno}",),
563563
}
564564
}
565565
}

0 commit comments

Comments
 (0)