Skip to content

Commit fb80246

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

File tree

11 files changed

+54
-71
lines changed

11 files changed

+54
-71
lines changed

src/sys/aio.rs

+1-1
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ mod tests {
23732373
sdl_slen: 0,
23742374
..unsafe { mem::zeroed() }
23752375
});
2376-
format!("{}", la);
2376+
format!("{la}");
23772377
}
23782378

23792379
#[cfg(all(
@@ -2495,7 +2495,7 @@ mod tests {
24952495
fn display() {
24962496
let s = "127.0.0.1:8080";
24972497
let addr = SockaddrIn::from_str(s).unwrap();
2498-
assert_eq!(s, format!("{}", addr));
2498+
assert_eq!(s, format!("{addr}"));
24992499
}
25002500

25012501
#[test]
@@ -2515,7 +2515,7 @@ mod tests {
25152515
fn display() {
25162516
let s = "[1234:5678:90ab:cdef::1111:2222]:8080";
25172517
let addr = SockaddrIn6::from_str(s).unwrap();
2518-
assert_eq!(s, format!("{}", addr));
2518+
assert_eq!(s, format!("{addr}"));
25192519
}
25202520

25212521
#[test]

src/sys/socket/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use libc::{
1212
self, c_int, c_void, iovec, size_t, socklen_t, CMSG_DATA, CMSG_FIRSTHDR,
1313
CMSG_LEN, CMSG_NXTHDR,
1414
};
15-
use std::convert::TryFrom;
1615
use std::io::{IoSlice, IoSliceMut};
1716
#[cfg(feature = "net")]
1817
use std::net;

src/sys/socket/sockopt.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ use crate::Result;
66
use cfg_if::cfg_if;
77
use libc::{self, c_int, c_void, socklen_t};
88
use std::ffi::{OsStr, OsString};
9+
use std::mem::{self, MaybeUninit};
910
#[cfg(target_family = "unix")]
1011
use std::os::unix::ffi::OsStrExt;
1112
use std::os::unix::io::RawFd;
12-
use std::{
13-
convert::TryFrom,
14-
mem::{self, MaybeUninit},
15-
};
1613

1714
// Constants
1815
// TCP_CA_NAME_MAX isn't defined in user space include files

src/sys/time.rs

+15-17
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

+1-1
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

+3-5
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ mod recvfrom {
626626
println!("IPv6 not available, skipping test.");
627627
return;
628628
}
629-
Err(e) => panic!("bind: {}", e),
629+
Err(e) => panic!("bind: {e}"),
630630
Ok(()) => (),
631631
}
632632
let ssock = socket(
@@ -1272,7 +1272,7 @@ fn test_scm_credentials() {
12721272
ControlMessageOwned::ScmCredentials(cred) => cred,
12731273
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
12741274
ControlMessageOwned::ScmCreds(cred) => cred,
1275-
other => panic!("unexpected cmsg {:?}", other),
1275+
other => panic!("unexpected cmsg {other:?}"),
12761276
};
12771277
assert!(received_cred.is_none());
12781278
assert_eq!(cred.pid(), getpid().as_raw());
@@ -1550,7 +1550,7 @@ fn loopback_address(
15501550
Err(e) => {
15511551
let stdioerr = io::stderr();
15521552
let mut handle = stdioerr.lock();
1553-
writeln!(handle, "getifaddrs: {:?}", e).unwrap();
1553+
writeln!(handle, "getifaddrs: {e:?}").unwrap();
15541554
return None;
15551555
}
15561556
};
@@ -2347,7 +2347,7 @@ mod linux_errqueue {
23472347
}
23482348
*ext_err
23492349
} else {
2350-
panic!("Unexpected control message {:?}", cmsg);
2350+
panic!("Unexpected control message {cmsg:?}");
23512351
}
23522352
},
23532353
)
@@ -2398,7 +2398,7 @@ mod linux_errqueue {
23982398
}
23992399
*ext_err
24002400
} else {
2401-
panic!("Unexpected control message {:?}", cmsg);
2401+
panic!("Unexpected control message {cmsg:?}");
24022402
}
24032403
},
24042404
)
@@ -2432,7 +2432,7 @@ mod linux_errqueue {
24322432
MsgFlags::empty(),
24332433
) {
24342434
assert_eq!(e, Errno::EADDRNOTAVAIL);
2435-
println!("{:?} not available, skipping test.", af);
2435+
println!("{af:?} not available, skipping test.");
24362436
return;
24372437
}
24382438

test/test_fcntl.rs

+1-1
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
}

test/test_mount.rs

+19-23
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exit 23";
3838
MsFlags::empty(),
3939
NONE,
4040
)
41-
.unwrap_or_else(|e| panic!("mount failed: {}", e));
41+
.unwrap_or_else(|e| panic!("mount failed: {e}"));
4242

4343
let test_path = tempdir.path().join("test");
4444

@@ -67,31 +67,30 @@ exit 23";
6767
.unwrap();
6868
process::exit(0);
6969
} else {
70-
panic!("open failed: {}", e);
70+
panic!("open failed: {e}");
7171
}
7272
})
7373
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
74-
.unwrap_or_else(|e| panic!("write failed: {}", e));
74+
.unwrap_or_else(|e| panic!("write failed: {e}"));
7575

7676
// Verify read.
7777
let mut buf = Vec::new();
7878
File::open(&test_path)
7979
.and_then(|mut f| f.read_to_end(&mut buf))
80-
.unwrap_or_else(|e| panic!("read failed: {}", e));
80+
.unwrap_or_else(|e| panic!("read failed: {e}"));
8181
assert_eq!(buf, SCRIPT_CONTENTS);
8282

8383
// Verify execute.
8484
assert_eq!(
8585
EXPECTED_STATUS,
8686
Command::new(&test_path)
8787
.status()
88-
.unwrap_or_else(|e| panic!("exec failed: {}", e))
88+
.unwrap_or_else(|e| panic!("exec failed: {e}"))
8989
.code()
9090
.unwrap_or_else(|| panic!("child killed by signal"))
9191
);
9292

93-
umount(tempdir.path())
94-
.unwrap_or_else(|e| panic!("umount failed: {}", e));
93+
umount(tempdir.path()).unwrap_or_else(|e| panic!("umount failed: {e}"));
9594
}
9695

9796
pub fn test_mount_rdonly_disallows_write() {
@@ -104,7 +103,7 @@ exit 23";
104103
MsFlags::MS_RDONLY,
105104
NONE,
106105
)
107-
.unwrap_or_else(|e| panic!("mount failed: {}", e));
106+
.unwrap_or_else(|e| panic!("mount failed: {e}"));
108107

109108
// EROFS: Read-only file system
110109
assert_eq!(
@@ -115,8 +114,7 @@ exit 23";
115114
.unwrap()
116115
);
117116

118-
umount(tempdir.path())
119-
.unwrap_or_else(|e| panic!("umount failed: {}", e));
117+
umount(tempdir.path()).unwrap_or_else(|e| panic!("umount failed: {e}"));
120118
}
121119

122120
pub fn test_mount_noexec_disallows_exec() {
@@ -129,7 +127,7 @@ exit 23";
129127
MsFlags::MS_NOEXEC,
130128
NONE,
131129
)
132-
.unwrap_or_else(|e| panic!("mount failed: {}", e));
130+
.unwrap_or_else(|e| panic!("mount failed: {e}"));
133131

134132
let test_path = tempdir.path().join("test");
135133

@@ -139,13 +137,13 @@ exit 23";
139137
.mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits())
140138
.open(&test_path)
141139
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
142-
.unwrap_or_else(|e| panic!("write failed: {}", e));
140+
.unwrap_or_else(|e| panic!("write failed: {e}"));
143141

144142
// Verify that we cannot execute despite a+x permissions being set.
145143
let mode = stat::Mode::from_bits_truncate(
146144
fs::metadata(&test_path)
147145
.map(|md| md.permissions().mode())
148-
.unwrap_or_else(|e| panic!("metadata failed: {}", e)),
146+
.unwrap_or_else(|e| panic!("metadata failed: {e}")),
149147
);
150148

151149
assert!(
@@ -164,8 +162,7 @@ exit 23";
164162
.unwrap()
165163
);
166164

167-
umount(tempdir.path())
168-
.unwrap_or_else(|e| panic!("umount failed: {}", e));
165+
umount(tempdir.path()).unwrap_or_else(|e| panic!("umount failed: {e}"));
169166
}
170167

171168
pub fn test_mount_bind() {
@@ -182,18 +179,18 @@ exit 23";
182179
MsFlags::MS_BIND,
183180
NONE,
184181
)
185-
.unwrap_or_else(|e| panic!("mount failed: {}", e));
182+
.unwrap_or_else(|e| panic!("mount failed: {e}"));
186183

187184
fs::OpenOptions::new()
188185
.create(true)
189186
.write(true)
190187
.mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits())
191188
.open(mount_point.path().join(file_name))
192189
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
193-
.unwrap_or_else(|e| panic!("write failed: {}", e));
190+
.unwrap_or_else(|e| panic!("write failed: {e}"));
194191

195192
umount(mount_point.path())
196-
.unwrap_or_else(|e| panic!("umount failed: {}", e));
193+
.unwrap_or_else(|e| panic!("umount failed: {e}"));
197194
}
198195

199196
// Verify the file written in the mount shows up in source directory, even
@@ -202,7 +199,7 @@ exit 23";
202199
let mut buf = Vec::new();
203200
File::open(tempdir.path().join(file_name))
204201
.and_then(|mut f| f.read_to_end(&mut buf))
205-
.unwrap_or_else(|e| panic!("read failed: {}", e));
202+
.unwrap_or_else(|e| panic!("read failed: {e}"));
206203
assert_eq!(buf, SCRIPT_CONTENTS);
207204
}
208205

@@ -214,8 +211,7 @@ exit 23";
214211
let stderr = io::stderr();
215212
let mut handle = stderr.lock();
216213
writeln!(handle,
217-
"unshare failed: {}. Are unprivileged user namespaces available?",
218-
e).unwrap();
214+
"unshare failed: {e}. Are unprivileged user namespaces available?").unwrap();
219215
writeln!(handle, "mount is not being tested").unwrap();
220216
// Exit with success because not all systems support unprivileged user namespaces, and
221217
// that's not what we're testing for.
@@ -226,8 +222,8 @@ exit 23";
226222
fs::OpenOptions::new()
227223
.write(true)
228224
.open("/proc/self/uid_map")
229-
.and_then(|mut f| f.write(format!("1000 {} 1\n", uid).as_bytes()))
230-
.unwrap_or_else(|e| panic!("could not write uid map: {}", e));
225+
.and_then(|mut f| f.write(format!("1000 {uid} 1\n").as_bytes()))
226+
.unwrap_or_else(|e| panic!("could not write uid map: {e}"));
231227
}
232228
}
233229

0 commit comments

Comments
 (0)