diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 00000000..91c31177 --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,4 @@ +disallowed-names = [ + "..", # defaults + "e", # prefer `err` +] diff --git a/.cspell.yml b/.cspell.yml index e203ed1a..3aa9eea1 100644 --- a/.cspell.yml +++ b/.cspell.yml @@ -3,8 +3,16 @@ words: - actix - addrs - clippy + - deque + - itertools - mptcp - MSRV - nonblocking - oneshot + - pemfile + - rcgen + - Rustls - rustup + - spki + - uring + - webpki diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b1d9e0ae --- /dev/null +++ b/.vscode/settings.json @@ -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", + ] +} diff --git a/Cargo.toml b/Cargo.toml index f3a83a39..a1de08cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/actix-codec/tests/test_framed_sink.rs b/actix-codec/tests/test_framed_sink.rs index 4c911199..280fec3d 100644 --- a/actix-codec/tests/test_framed_sink.rs +++ b/actix-codec/tests/test_framed_sink.rs @@ -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:?}"), } } diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs index 1da76c52..b2d723e6 100644 --- a/actix-rt/src/arbiter.rs +++ b/actix-rt/src/arbiter.rs @@ -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::<()>(); diff --git a/actix-rt/src/system.rs b/actix-rt/src/system.rs index 5d8187cd..77b11f4b 100644 --- a/actix-rt/src/system.rs +++ b/actix-rt/src/system.rs @@ -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}"))), } } diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index 997c9699..921a7b1e 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -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 } diff --git a/actix-server/src/signals.rs b/actix-server/src/signals.rs index c41d0e33..07090b6c 100644 --- a/actix-server/src/signals.rs +++ b/actix-server/src/signals.rs @@ -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() diff --git a/actix-server/src/socket.rs b/actix-server/src/socket.rs index 91a73be8..f690ab95 100644 --- a/actix-server/src/socket.rs +++ b/actix-server/src/socket.rs @@ -105,9 +105,9 @@ impl From 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")); } } } diff --git a/actix-server/src/waker_queue.rs b/actix-server/src/waker_queue.rs index a7280901..b6d4e5b0 100644 --- a/actix-server/src/waker_queue.rs +++ b/actix-server/src/waker_queue.rs @@ -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) { - std::mem::swap(&mut VecDeque::::with_capacity(16), queue); + *queue = VecDeque::::with_capacity(16); } } diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 92a2c007..dcecda0e 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -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(); diff --git a/actix-tls/examples/accept-rustls.rs b/actix-tls/examples/accept-rustls.rs index b94a01e7..7033ba1a 100644 --- a/actix-tls/examples/accept-rustls.rs +++ b/actix-tls/examples/accept-rustls.rs @@ -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| { let num = count.fetch_add(1, Ordering::Relaxed); info!("[{}] Got TLS connection: {:?}", num, &*stream); diff --git a/actix-tls/src/connect/native_tls.rs b/actix-tls/src/connect/native_tls.rs index 16863ce0..674de842 100644 --- a/actix-tls/src/connect/native_tls.rs +++ b/actix-tls/src/connect/native_tls.rs @@ -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}")) }) }) } diff --git a/actix-tls/src/connect/openssl.rs b/actix-tls/src/connect/openssl.rs index ab2841bb..0b17f9a2 100644 --- a/actix-tls/src/connect/openssl.rs +++ b/actix-tls/src/connect/openssl.rs @@ -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}")))) } } } diff --git a/actix-tls/src/connect/rustls_0_20.rs b/actix-tls/src/connect/rustls_0_20.rs index fc65b686..27d26292 100644 --- a/actix-tls/src/connect/rustls_0_20.rs +++ b/actix-tls/src/connect/rustls_0_20.rs @@ -159,8 +159,7 @@ where fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { 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.", ))), diff --git a/actix-tls/tests/accept-openssl.rs b/actix-tls/tests/accept-openssl.rs index 41fb1d7b..ebac10d1 100644 --- a/actix-tls/tests/accept-openssl.rs +++ b/actix-tls/tests/accept-openssl.rs @@ -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| ok(())) } }); diff --git a/actix-tls/tests/accept-rustls.rs b/actix-tls/tests/accept-rustls.rs index f31606e7..c556050e 100644 --- a/actix-tls/tests/accept-rustls.rs +++ b/actix-tls/tests/accept-rustls.rs @@ -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| ok(())) } }); diff --git a/actix-tls/tests/test_resolvers.rs b/actix-tls/tests/test_resolvers.rs index 7543c4e0..b6629b0b 100644 --- a/actix-tls/tests/test_resolvers.rs +++ b/actix-tls/tests/test_resolvers.rs @@ -26,7 +26,7 @@ async fn custom_resolver() { port: u16, ) -> LocalBoxFuture<'a, Result, Box>> { 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]) }) }