Skip to content

Commit

Permalink
fix clippy lints from the future (#3438)
Browse files Browse the repository at this point in the history
## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->
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._
  • Loading branch information
Velfi authored Feb 26, 2024
1 parent 07c8074 commit 5b9d0c0
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 30 deletions.
7 changes: 5 additions & 2 deletions rust-runtime/aws-smithy-checksums/src/body/calculate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>();
.fold(String::new(), |mut acc, byte| {
write!(acc, "{byte:02X?}").expect("string will always be writeable");
acc
});

format!("0x{}", decoded_checksum)
}
Expand Down
7 changes: 5 additions & 2 deletions rust-runtime/aws-smithy-checksums/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,18 @@ 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"#;

fn base64_encoded_checksum_to_hex_string(header_value: &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::<String>();
.fold(String::new(), |mut acc, byte| {
write!(acc, "{byte:02X?}").expect("string will always be writeable");
acc
});

format!("0x{}", decoded_checksum)
}
Expand Down
4 changes: 1 addition & 3 deletions rust-runtime/aws-smithy-http-server-python/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ impl<S> FromIterator<(String, S)> for AwsJsonRouter<S> {
#[inline]
fn from_iter<T: IntoIterator<Item = (String, S)>>(iter: T) -> Self {
Self {
routes: iter
.into_iter()
.map(|(svc, request_spec)| (svc, request_spec))
.collect(),
routes: iter.into_iter().collect(),
}
}
}
Expand Down
15 changes: 3 additions & 12 deletions rust-runtime/aws-smithy-http-server/src/protocol/rest/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ where
impl<S> FromIterator<(RequestSpec, S)> for RestRouter<S> {
#[inline]
fn from_iter<T: IntoIterator<Item = (RequestSpec, S)>>(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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
5 changes: 1 addition & 4 deletions rust-runtime/aws-smithy-json/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ fn read_codepoint(rest: &[u8]) -> Result<u16, EscapeError> {
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"))
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-mocks-experimental/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-mocks-experimental"
version = "0.1.0"
version = "0.1.1"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
description = "Experimental testing utilities for smithy-rs generated clients"
edition = "2021"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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#"<?xml version="1.0" encoding="UTF-8"?>
const S3_NO_SUCH_KEY: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchKey</Code>
<Message>The resource you requested does not exist</Message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5b9d0c0

Please sign in to comment.