From 6efcb75d99a437fa80c81e2308ec8234b023e1a7 Mon Sep 17 00:00:00 2001 From: Benjamin Sparks Date: Mon, 9 Sep 2024 20:55:15 +0200 Subject: [PATCH] Fix warnings and errors from beta Rust (#2904) --- axum/src/extract/ws.rs | 25 ++++++++++++++++--------- axum/src/handler/mod.rs | 2 ++ axum/src/middleware/from_fn.rs | 2 ++ axum/src/middleware/map_response.rs | 2 ++ axum/src/routing/route.rs | 2 ++ examples/serve-with-hyper/src/main.rs | 2 ++ examples/unix-domain-socket/src/main.rs | 1 + 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index cfd10c56..e91915cb 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -783,8 +783,9 @@ pub mod close_code { pub const PROTOCOL: u16 = 1002; /// Indicates that an endpoint is terminating the connection because it has received a type of - /// data it cannot accept (e.g., an endpoint that understands only text data MAY send this if - /// it receives a binary message). + /// data that it cannot accept. + /// + /// For example, an endpoint MAY send this if it understands only text data, but receives a binary message. pub const UNSUPPORTED: u16 = 1003; /// Indicates that no status code was included in a closing frame. @@ -794,12 +795,15 @@ pub mod close_code { pub const ABNORMAL: u16 = 1006; /// Indicates that an endpoint is terminating the connection because it has received data - /// within a message that was not consistent with the type of the message (e.g., non-UTF-8 - /// RFC3629 data within a text message). + /// within a message that was not consistent with the type of the message. + /// + /// For example, an endpoint received non-UTF-8 RFC3629 data within a text message. pub const INVALID: u16 = 1007; /// Indicates that an endpoint is terminating the connection because it has received a message - /// that violates its policy. This is a generic status code that can be returned when there is + /// that violates its policy. + /// + /// This is a generic status code that can be returned when there is /// no other more suitable status code (e.g., `UNSUPPORTED` or `SIZE`) or if there is a need to /// hide specific details about the policy. pub const POLICY: u16 = 1008; @@ -808,10 +812,13 @@ pub mod close_code { /// that is too big for it to process. pub const SIZE: u16 = 1009; - /// Indicates that an endpoint (client) is terminating the connection because it has expected - /// the server to negotiate one or more extension, but the server didn't return them in the - /// response message of the WebSocket handshake. The list of extensions that are needed should - /// be given as the reason for closing. Note that this status code is not used by the server, + /// Indicates that an endpoint (client) is terminating the connection because the server + /// did not respond to extension negotiation correctly. + /// + /// Specifically, the client has expected the server to negotiate one or more extension(s), + /// but the server didn't return them in the response message of the WebSocket handshake. + /// The list of extensions that are needed should be given as the reason for closing. + /// Note that this status code is not used by the server, /// because it can fail the WebSocket handshake instead. pub const EXTENSION: u16 = 1010; diff --git a/axum/src/handler/mod.rs b/axum/src/handler/mod.rs index 783e02e3..04c66c4a 100644 --- a/axum/src/handler/mod.rs +++ b/axum/src/handler/mod.rs @@ -328,6 +328,8 @@ where ) -> _, > = svc.oneshot(req).map(|result| match result { Ok(res) => res.into_response(), + + #[allow(unreachable_patterns)] Err(err) => match err {}, }); diff --git a/axum/src/middleware/from_fn.rs b/axum/src/middleware/from_fn.rs index 3ed7a959..f0f47611 100644 --- a/axum/src/middleware/from_fn.rs +++ b/axum/src/middleware/from_fn.rs @@ -341,6 +341,8 @@ impl Next { pub async fn run(mut self, req: Request) -> Response { match self.inner.call(req).await { Ok(res) => res, + + #[allow(unreachable_patterns)] Err(err) => match err {}, } } diff --git a/axum/src/middleware/map_response.rs b/axum/src/middleware/map_response.rs index 2510cdc2..e4c1c397 100644 --- a/axum/src/middleware/map_response.rs +++ b/axum/src/middleware/map_response.rs @@ -278,6 +278,8 @@ macro_rules! impl_service { Ok(res) => { f($($ty,)* res).await.into_response() } + + #[allow(unreachable_patterns)] Err(err) => match err {} } }); diff --git a/axum/src/routing/route.rs b/axum/src/routing/route.rs index 2bde8c8c..242e25f3 100644 --- a/axum/src/routing/route.rs +++ b/axum/src/routing/route.rs @@ -236,6 +236,8 @@ impl Future for InfallibleRouteFuture { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match futures_util::ready!(self.project().future.poll(cx)) { Ok(response) => Poll::Ready(response), + + #[allow(unreachable_patterns)] Err(err) => match err {}, } } diff --git a/examples/serve-with-hyper/src/main.rs b/examples/serve-with-hyper/src/main.rs index 8bad2acd..9da67fc1 100644 --- a/examples/serve-with-hyper/src/main.rs +++ b/examples/serve-with-hyper/src/main.rs @@ -11,6 +11,8 @@ //! //! [hyper-util]: https://crates.io/crates/hyper-util +#![allow(unreachable_patterns)] + use std::convert::Infallible; use std::net::SocketAddr; diff --git a/examples/unix-domain-socket/src/main.rs b/examples/unix-domain-socket/src/main.rs index d11792dd..fbb4c3b0 100644 --- a/examples/unix-domain-socket/src/main.rs +++ b/examples/unix-domain-socket/src/main.rs @@ -3,6 +3,7 @@ //! ```not_rust //! cargo run -p example-unix-domain-socket //! ``` +#![allow(unreachable_patterns)] #[cfg(unix)] #[tokio::main]