From 5429ed9bd53d7804282e2d8c07ee590c08146bcc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 3 Apr 2025 23:22:19 +0200 Subject: [PATCH] Fix new clippy lints (#3304) --- axum-extra/src/json_lines.rs | 2 +- axum-extra/src/response/error_response.rs | 4 ++-- axum/src/middleware/map_request.rs | 1 + axum/src/routing/path_router.rs | 1 + axum/src/test_helpers/tracing_helpers.rs | 5 +---- examples/stream-to-file/src/main.rs | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/axum-extra/src/json_lines.rs b/axum-extra/src/json_lines.rs index 7c513f96..38ac735d 100644 --- a/axum-extra/src/json_lines.rs +++ b/axum-extra/src/json_lines.rs @@ -110,7 +110,7 @@ where // so we can call `AsyncRead::lines` and then convert it back to a `Stream` let body = req.into_body(); let stream = body.into_data_stream(); - let stream = stream.map_err(|err| io::Error::new(io::ErrorKind::Other, err)); + let stream = stream.map_err(io::Error::other); let read = StreamReader::new(stream); let lines_stream = LinesStream::new(read.lines()); diff --git a/axum-extra/src/response/error_response.rs b/axum-extra/src/response/error_response.rs index 07069505..97558c7a 100644 --- a/axum-extra/src/response/error_response.rs +++ b/axum-extra/src/response/error_response.rs @@ -41,11 +41,11 @@ impl IntoResponse for InternalServerError { #[cfg(test)] mod tests { use super::*; - use std::io::{Error, ErrorKind}; + use std::io::Error; #[test] fn internal_server_error() { - let response = InternalServerError(Error::new(ErrorKind::Other, "Test")).into_response(); + let response = InternalServerError(Error::other("Test")).into_response(); assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR); } } diff --git a/axum/src/middleware/map_request.rs b/axum/src/middleware/map_request.rs index 488a19b1..5098cfe3 100644 --- a/axum/src/middleware/map_request.rs +++ b/axum/src/middleware/map_request.rs @@ -366,6 +366,7 @@ mod private { /// This trait is sealed such that it cannot be implemented outside this crate. pub trait IntoMapRequestResult: private::Sealed { /// Perform the conversion. + #[allow(clippy::result_large_err)] fn into_map_request_result(self) -> Result, Response>; } diff --git a/axum/src/routing/path_router.rs b/axum/src/routing/path_router.rs index 83f33e4e..f9f6de6f 100644 --- a/axum/src/routing/path_router.rs +++ b/axum/src/routing/path_router.rs @@ -367,6 +367,7 @@ where } } + #[allow(clippy::result_large_err)] pub(super) fn call_with_state( &self, #[cfg_attr(not(feature = "original-uri"), allow(unused_mut))] mut req: Request, diff --git a/axum/src/test_helpers/tracing_helpers.rs b/axum/src/test_helpers/tracing_helpers.rs index f7769ee9..adf4331f 100644 --- a/axum/src/test_helpers/tracing_helpers.rs +++ b/axum/src/test_helpers/tracing_helpers.rs @@ -120,10 +120,7 @@ impl io::Write for Writer<'_> { vec.extend(buf); Ok(len) } - None => Err(io::Error::new( - io::ErrorKind::Other, - "inner writer has been taken", - )), + None => Err(io::Error::other("inner writer has been taken")), } } diff --git a/examples/stream-to-file/src/main.rs b/examples/stream-to-file/src/main.rs index 7c44286d..8bb2cb7e 100644 --- a/examples/stream-to-file/src/main.rs +++ b/examples/stream-to-file/src/main.rs @@ -111,7 +111,7 @@ where async { // Convert the stream into an `AsyncRead`. - let body_with_io_error = stream.map_err(|err| io::Error::new(io::ErrorKind::Other, err)); + let body_with_io_error = stream.map_err(io::Error::other); let body_reader = StreamReader::new(body_with_io_error); futures::pin_mut!(body_reader);