refactor: inline format args

This commit is contained in:
Rob Ede 2025-08-29 00:57:13 +01:00
parent 160fdc5efc
commit b8ff2a47a6
No known key found for this signature in database
GPG Key ID: F5E3FCAA33CBF062
19 changed files with 89 additions and 48 deletions

4
.clippy.toml Normal file
View File

@ -0,0 +1,4 @@
disallowed-names = [
"..", # defaults
"e", # prefer `err`
]

View File

@ -3,8 +3,16 @@ words:
- actix
- addrs
- clippy
- deque
- itertools
- mptcp
- MSRV
- nonblocking
- oneshot
- pemfile
- rcgen
- Rustls
- rustup
- spki
- uring
- webpki

32
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,32 @@
{
"rust-analyzer.cargo.features": [
"accept",
"actix-macros",
"connect",
"default",
"macros",
"native-tls",
"openssl",
"rustls",
"rustls-021",
"rustls-0_20",
"rustls-0_20-native-roots",
"rustls-0_20-webpki-roots",
"rustls-0_21",
"rustls-0_21-native-roots",
"rustls-0_21-webpki-roots",
"rustls-0_22",
"rustls-0_22-native-roots",
"rustls-0_22-webpki-roots",
"rustls-0_23",
"rustls-0_23-native-roots",
"rustls-0_23-webpki-roots",
"rustls-webpki-0101",
"serde",
"tokio-rustls-023",
"tokio-rustls-024",
"uri",
"webpki-roots-022",
"webpki-roots-025",
]
}

View File

@ -38,7 +38,11 @@ opt-level = 3
codegen-units = 1
[workspace.lints.rust]
rust_2018_idioms = "deny"
rust-2018-idioms = "deny"
nonstandard-style = "deny"
future_incompatible = "deny"
missing_docs = { level = "warn", priority = -1 }
future-incompatible = "deny"
missing-docs = { level = "warn", priority = -1 }
[workspace.lints.clippy]
uninlined-format-args = "warn"
disallowed-names = "warn"

View File

@ -57,7 +57,7 @@ impl Write for Bilateral {
Ok(data.len())
}
Some(Err(err)) => Err(err),
None => panic!("unexpected write; {:?}", src),
None => panic!("unexpected write; {src:?}"),
}
}

View File

@ -115,7 +115,7 @@ impl Arbiter {
let system_id = sys.id();
let arb_id = COUNT.fetch_add(1, Ordering::Relaxed);
let name = format!("actix-rt|system:{}|arbiter:{}", system_id, arb_id);
let name = format!("actix-rt|system:{system_id}|arbiter:{arb_id}");
let (tx, rx) = mpsc::unbounded_channel();
let (ready_tx, ready_rx) = std::sync::mpsc::channel::<()>();

View File

@ -187,7 +187,7 @@ impl SystemRunner {
match exit_code {
0 => Ok(()),
nonzero => Err(io::Error::other(format!("Non-zero exit code: {}", nonzero))),
nonzero => Err(io::Error::other(format!("Non-zero exit code: {nonzero}"))),
}
}

View File

@ -130,7 +130,7 @@ impl Accept {
if let Err(err) = self.poll.poll(&mut events, self.timeout) {
match err.kind() {
io::ErrorKind::Interrupted => {}
_ => panic!("Poll error: {}", err),
_ => panic!("Poll error: {err}"),
}
}
@ -165,7 +165,6 @@ impl Accept {
// task is done. Take care not to take the guard again inside this loop.
let mut guard = self.waker_queue.guard();
#[allow(clippy::significant_drop_in_scrutinee)]
match guard.pop_front() {
// Worker notified it became available.
Some(WakerInterest::WorkerAvailable(idx)) => {
@ -455,8 +454,8 @@ impl Accept {
/// All other errors will incur a timeout before next `accept()` call is attempted. The timeout is
/// useful to handle resource exhaustion errors like `ENFILE` and `EMFILE`. Otherwise, it could
/// enter into a temporary spin loop.
fn connection_error(e: &io::Error) -> bool {
e.kind() == io::ErrorKind::ConnectionRefused
|| e.kind() == io::ErrorKind::ConnectionAborted
|| e.kind() == io::ErrorKind::ConnectionReset
fn connection_error(err: &io::Error) -> bool {
err.kind() == io::ErrorKind::ConnectionRefused
|| err.kind() == io::ErrorKind::ConnectionAborted
|| err.kind() == io::ErrorKind::ConnectionReset
}

View File

@ -92,11 +92,9 @@ impl OsSignals {
.filter_map(|(kind, sig)| {
unix::signal(*kind)
.map(|tokio_sig| (*sig, tokio_sig))
.map_err(|e| {
.map_err(|err| {
tracing::error!(
"can not initialize stream handler for {:?} err: {}",
sig,
e
"can not initialize stream handler for {sig:?} err: {err}",
)
})
.ok()

View File

@ -105,9 +105,9 @@ impl From<StdUnixListener> for MioListener {
impl fmt::Debug for MioListener {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
MioListener::Tcp(ref lst) => write!(f, "{:?}", lst),
MioListener::Tcp(ref lst) => write!(f, "{lst:?}"),
#[cfg(unix)]
MioListener::Uds(ref lst) => write!(f, "{:?}", lst),
MioListener::Uds(ref lst) => write!(f, "{lst:?}"),
}
}
}
@ -115,9 +115,9 @@ impl fmt::Debug for MioListener {
impl fmt::Display for MioListener {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
MioListener::Tcp(ref lst) => write!(f, "{:?}", lst),
MioListener::Tcp(ref lst) => write!(f, "{lst:?}"),
#[cfg(unix)]
MioListener::Uds(ref lst) => write!(f, "{:?}", lst),
MioListener::Uds(ref lst) => write!(f, "{lst:?}"),
}
}
}
@ -133,9 +133,9 @@ impl fmt::Display for SocketAddr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Unknown => write!(f, "Unknown SocketAddr"),
Self::Tcp(ref addr) => write!(f, "{}", addr),
Self::Tcp(ref addr) => write!(f, "{addr}"),
#[cfg(unix)]
Self::Uds(ref addr) => write!(f, "{:?}", addr),
Self::Uds(ref addr) => write!(f, "{addr:?}"),
}
}
}
@ -144,9 +144,9 @@ impl fmt::Debug for SocketAddr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Unknown => write!(f, "Unknown SocketAddr"),
Self::Tcp(ref addr) => write!(f, "{:?}", addr),
Self::Tcp(ref addr) => write!(f, "{addr:?}"),
#[cfg(unix)]
Self::Uds(ref addr) => write!(f, "{:?}", addr),
Self::Uds(ref addr) => write!(f, "{addr:?}"),
}
}
}
@ -266,14 +266,14 @@ mod tests {
#[test]
fn socket_addr() {
let addr = SocketAddr::Tcp("127.0.0.1:8080".parse().unwrap());
assert!(format!("{:?}", addr).contains("127.0.0.1:8080"));
assert_eq!(format!("{}", addr), "127.0.0.1:8080");
assert!(format!("{addr:?}").contains("127.0.0.1:8080"));
assert_eq!(format!("{addr}"), "127.0.0.1:8080");
let addr: StdSocketAddr = "127.0.0.1:0".parse().unwrap();
let lst = create_mio_tcp_listener(addr, 128, &MpTcp::Disabled).unwrap();
let lst = MioListener::Tcp(lst);
assert!(format!("{:?}", lst).contains("TcpListener"));
assert!(format!("{}", lst).contains("127.0.0.1"));
assert!(format!("{lst:?}").contains("TcpListener"));
assert!(format!("{lst}").contains("127.0.0.1"));
}
#[test]
@ -283,12 +283,12 @@ mod tests {
if let Ok(socket) = MioUnixListener::bind("/tmp/sock.xxxxx") {
let addr = socket.local_addr().expect("Couldn't get local address");
let a = SocketAddr::Uds(addr);
assert!(format!("{:?}", a).contains("/tmp/sock.xxxxx"));
assert!(format!("{}", a).contains("/tmp/sock.xxxxx"));
assert!(format!("{a:?}").contains("/tmp/sock.xxxxx"));
assert!(format!("{a}").contains("/tmp/sock.xxxxx"));
let lst = MioListener::Uds(socket);
assert!(format!("{:?}", lst).contains("/tmp/sock.xxxxx"));
assert!(format!("{}", lst).contains("/tmp/sock.xxxxx"));
assert!(format!("{lst:?}").contains("/tmp/sock.xxxxx"));
assert!(format!("{lst}").contains("/tmp/sock.xxxxx"));
}
}
}

View File

@ -52,7 +52,7 @@ impl WakerQueue {
waker
.wake()
.unwrap_or_else(|e| panic!("can not wake up Accept Poll: {}", e));
.unwrap_or_else(|err| panic!("can not wake up Accept Poll: {err}"));
}
/// Get a MutexGuard of the waker queue.
@ -62,7 +62,7 @@ impl WakerQueue {
/// Reset the waker queue so it does not grow infinitely.
pub(crate) fn reset(queue: &mut VecDeque<WakerInterest>) {
std::mem::swap(&mut VecDeque::<WakerInterest>::with_capacity(16), queue);
*queue = VecDeque::<WakerInterest>::with_capacity(16);
}
}

View File

@ -325,7 +325,7 @@ impl ServerWorker {
// no actix system
(None, Some(rt_handle)) => {
std::thread::Builder::new()
.name(format!("actix-server worker {}", idx))
.name(format!("actix-server worker {idx}"))
.spawn(move || {
let (worker_stopped_tx, worker_stopped_rx) = oneshot::channel();

View File

@ -80,7 +80,7 @@ async fn main() -> io::Result<()> {
// Set up TLS service factory
tls_acceptor
.clone()
.map_err(|err| println!("Rustls error: {:?}", err))
.map_err(|err| println!("Rustls error: {err:?}"))
.and_then(move |stream: TlsStream<TcpStream>| {
let num = count.fetch_add(1, Ordering::Relaxed);
info!("[{}] Got TLS connection: {:?}", num, &*stream);

View File

@ -81,9 +81,9 @@ where
trace!("TLS handshake success: {:?}", stream.hostname());
stream.replace_io(res).1
})
.map_err(|e| {
trace!("TLS handshake error: {:?}", e);
io::Error::new(io::ErrorKind::Other, format!("{}", e))
.map_err(|err| {
trace!("TLS handshake error: {err:?}");
io::Error::other(format!("{err}"))
})
})
}

View File

@ -141,10 +141,7 @@ where
}
Err(err) => {
trace!("TLS handshake error: {:?}", err);
Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
format!("{}", err),
)))
Poll::Ready(Err(io::Error::other(format!("{err}"))))
}
}
}

View File

@ -159,8 +159,7 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.get_mut() {
Self::InvalidDns => Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
Self::InvalidDns => Poll::Ready(Err(io::Error::other(
"Rustls v0.20 can only handle hostname-based connections. Enable the `rustls-0_21` \
feature and use the Rustls v0.21 utilities to gain this feature.",
))),

View File

@ -126,7 +126,7 @@ async fn accepts_connections() {
let tls_acceptor = Acceptor::new(openssl_acceptor);
tls_acceptor
.map_err(|err| println!("OpenSSL error: {:?}", err))
.map_err(|err| println!("OpenSSL error: {err:?}"))
.and_then(move |_stream: TlsStream<TcpStream>| ok(()))
}
});

View File

@ -87,7 +87,7 @@ async fn accepts_connections() {
let tls_acceptor = Acceptor::new(rustls_server_config(cert.clone(), key.clone()));
tls_acceptor
.map_err(|err| println!("Rustls error: {:?}", err))
.map_err(|err| println!("Rustls error: {err:?}"))
.and_then(move |_stream: TlsStream<TcpStream>| ok(()))
}
});

View File

@ -26,7 +26,7 @@ async fn custom_resolver() {
port: u16,
) -> LocalBoxFuture<'a, Result<Vec<SocketAddr>, Box<dyn std::error::Error>>> {
Box::pin(async move {
let local = format!("127.0.0.1:{}", port).parse().unwrap();
let local = format!("127.0.0.1:{port}").parse().unwrap();
Ok(vec![local])
})
}