From 5b9d0c0fffa45d9eece1371104a1e30c91ef4f95 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Mon, 26 Feb 2024 09:30:51 -0600 Subject: [PATCH] fix clippy lints from the future (#3438) ## Motivation and Context Because the build pipeline is checking for these. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- .../aws-smithy-checksums/src/body/calculate.rs | 7 +++++-- rust-runtime/aws-smithy-checksums/src/lib.rs | 7 +++++-- .../aws-smithy-http-server-python/src/server.rs | 4 +--- .../src/protocol/aws_json/router.rs | 5 +---- .../src/protocol/rest/router.rs | 15 +++------------ rust-runtime/aws-smithy-json/src/escape.rs | 5 +---- .../aws-smithy-mocks-experimental/Cargo.toml | 2 +- .../tests/get-object-mocks.rs | 2 +- .../http/body/minimum_throughput/throughput.rs | 2 +- 9 files changed, 19 insertions(+), 30 deletions(-) diff --git a/rust-runtime/aws-smithy-checksums/src/body/calculate.rs b/rust-runtime/aws-smithy-checksums/src/body/calculate.rs index 8c9fcb368b..a1f6c25a19 100644 --- a/rust-runtime/aws-smithy-checksums/src/body/calculate.rs +++ b/rust-runtime/aws-smithy-checksums/src/body/calculate.rs @@ -104,14 +104,17 @@ mod tests { use bytes::Buf; use bytes_utils::SegmentedBuf; use http_body::Body; + use std::fmt::Write; use std::io::Read; fn header_value_as_checksum_string(header_value: &http::HeaderValue) -> String { let decoded_checksum = base64::decode(header_value.to_str().unwrap()).unwrap(); let decoded_checksum = decoded_checksum .into_iter() - .map(|byte| format!("{:02X?}", byte)) - .collect::(); + .fold(String::new(), |mut acc, byte| { + write!(acc, "{byte:02X?}").expect("string will always be writeable"); + acc + }); format!("0x{}", decoded_checksum) } diff --git a/rust-runtime/aws-smithy-checksums/src/lib.rs b/rust-runtime/aws-smithy-checksums/src/lib.rs index 1bc7b2fda3..e969918dd7 100644 --- a/rust-runtime/aws-smithy-checksums/src/lib.rs +++ b/rust-runtime/aws-smithy-checksums/src/lib.rs @@ -304,6 +304,7 @@ mod tests { use aws_smithy_types::base64; use http::HeaderValue; use pretty_assertions::assert_eq; + use std::fmt::Write; const TEST_DATA: &str = r#"test data"#; @@ -311,8 +312,10 @@ mod tests { let decoded_checksum = base64::decode(header_value.to_str().unwrap()).unwrap(); let decoded_checksum = decoded_checksum .into_iter() - .map(|byte| format!("{:02X?}", byte)) - .collect::(); + .fold(String::new(), |mut acc, byte| { + write!(acc, "{byte:02X?}").expect("string will always be writeable"); + acc + }); format!("0x{}", decoded_checksum) } diff --git a/rust-runtime/aws-smithy-http-server-python/src/server.rs b/rust-runtime/aws-smithy-http-server-python/src/server.rs index aca77fcef2..84c295adf6 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/server.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/server.rs @@ -499,9 +499,7 @@ event_loop.add_signal_handler(signal.SIGINT, } fn addr_incoming_from_socket(socket: Socket) -> AddrIncoming { - let std_listener: StdTcpListener = socket - .try_into() - .expect("unable to convert `socket2::Socket` into `std::net::TcpListener`"); + let std_listener: StdTcpListener = socket.into(); // StdTcpListener::from_std doesn't set O_NONBLOCK std_listener .set_nonblocking(true) diff --git a/rust-runtime/aws-smithy-http-server/src/protocol/aws_json/router.rs b/rust-runtime/aws-smithy-http-server/src/protocol/aws_json/router.rs index cba990ffbf..cf9308124d 100644 --- a/rust-runtime/aws-smithy-http-server/src/protocol/aws_json/router.rs +++ b/rust-runtime/aws-smithy-http-server/src/protocol/aws_json/router.rs @@ -110,10 +110,7 @@ impl FromIterator<(String, S)> for AwsJsonRouter { #[inline] fn from_iter>(iter: T) -> Self { Self { - routes: iter - .into_iter() - .map(|(svc, request_spec)| (svc, request_spec)) - .collect(), + routes: iter.into_iter().collect(), } } } diff --git a/rust-runtime/aws-smithy-http-server/src/protocol/rest/router.rs b/rust-runtime/aws-smithy-http-server/src/protocol/rest/router.rs index fbbb98ee81..19a644e7e4 100644 --- a/rust-runtime/aws-smithy-http-server/src/protocol/rest/router.rs +++ b/rust-runtime/aws-smithy-http-server/src/protocol/rest/router.rs @@ -95,10 +95,7 @@ where impl FromIterator<(RequestSpec, S)> for RestRouter { #[inline] fn from_iter>(iter: T) -> Self { - let mut routes: Vec<(RequestSpec, S)> = iter - .into_iter() - .map(|(request_spec, svc)| (request_spec, svc)) - .collect(); + let mut routes: Vec<(RequestSpec, S)> = iter.into_iter().collect(); // Sort them once by specificity, with the more specific routes sorted before the less // specific ones, so that when routing a request we can simply iterate through the routes @@ -167,10 +164,7 @@ mod tests { ]; // Test both RestJson1 and RestXml routers. - let router: RestRouter<_> = request_specs - .into_iter() - .map(|(spec, svc_name)| (spec, svc_name)) - .collect(); + let router: RestRouter<_> = request_specs.into_iter().collect(); let hits = vec![ ("A", Method::GET, "/a/b/c"), @@ -255,10 +249,7 @@ mod tests { ), ]; - let router: RestRouter<_> = request_specs - .into_iter() - .map(|(spec, svc_name)| (spec, svc_name)) - .collect(); + let router: RestRouter<_> = request_specs.into_iter().collect(); let hits = vec![ ("A1", Method::GET, "/a/foo"), diff --git a/rust-runtime/aws-smithy-json/src/escape.rs b/rust-runtime/aws-smithy-json/src/escape.rs index fb8ee35c3e..d87e57c6da 100644 --- a/rust-runtime/aws-smithy-json/src/escape.rs +++ b/rust-runtime/aws-smithy-json/src/escape.rs @@ -176,10 +176,7 @@ fn read_codepoint(rest: &[u8]) -> Result { std::str::from_utf8(&rest[2..6]).map_err(|_| EscapeErrorKind::InvalidUtf8)?; // Error on characters `u16::from_str_radix` would otherwise accept, such as `+` - if codepoint_str - .bytes() - .any(|byte| !matches!(byte, b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F')) - { + if codepoint_str.bytes().any(|byte| !byte.is_ascii_hexdigit()) { return Err(EscapeErrorKind::InvalidUnicodeEscape(codepoint_str.into()).into()); } Ok(u16::from_str_radix(codepoint_str, 16).expect("hex string is valid 16-bit value")) diff --git a/rust-runtime/aws-smithy-mocks-experimental/Cargo.toml b/rust-runtime/aws-smithy-mocks-experimental/Cargo.toml index ef06256e5d..13fcb7b337 100644 --- a/rust-runtime/aws-smithy-mocks-experimental/Cargo.toml +++ b/rust-runtime/aws-smithy-mocks-experimental/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-mocks-experimental" -version = "0.1.0" +version = "0.1.1" authors = ["AWS Rust SDK Team "] description = "Experimental testing utilities for smithy-rs generated clients" edition = "2021" diff --git a/rust-runtime/aws-smithy-mocks-experimental/tests/get-object-mocks.rs b/rust-runtime/aws-smithy-mocks-experimental/tests/get-object-mocks.rs index fb7010ca3d..2448df010b 100644 --- a/rust-runtime/aws-smithy-mocks-experimental/tests/get-object-mocks.rs +++ b/rust-runtime/aws-smithy-mocks-experimental/tests/get-object-mocks.rs @@ -16,7 +16,7 @@ use aws_smithy_types::error::ErrorMetadata; use aws_smithy_mocks_experimental::{mock, MockResponseInterceptor}; -const S3_NO_SUCH_KEY: &'static str = r#" +const S3_NO_SUCH_KEY: &str = r#" NoSuchKey The resource you requested does not exist diff --git a/rust-runtime/aws-smithy-runtime/src/client/http/body/minimum_throughput/throughput.rs b/rust-runtime/aws-smithy-runtime/src/client/http/body/minimum_throughput/throughput.rs index c4d9223b21..e2a9b294e6 100644 --- a/rust-runtime/aws-smithy-runtime/src/client/http/body/minimum_throughput/throughput.rs +++ b/rust-runtime/aws-smithy-runtime/src/client/http/body/minimum_throughput/throughput.rs @@ -140,7 +140,7 @@ impl ThroughputLogs { .iter() .last()? .0 - .duration_since(self.inner.get(0)?.0) + .duration_since(self.inner.front()?.0) .ok()?; // during a "healthy" request we'll only have a few milliseconds of logs (shorter than the check window) if total_length < time_window {