From aa2a5dfe7a9db431887f0f5aa687fcf9ec5ece3e Mon Sep 17 00:00:00 2001 From: Blake Hildebrand Date: Sat, 6 Feb 2021 13:41:23 -0600 Subject: [PATCH] Fix clippy errors Fix all clippy errors currently present. Additionally add clippy check to actions. --- .github/workflows/build.yml | 13 ++++++++++++- lambda-http/Cargo.toml | 1 + lambda/Cargo.toml | 7 ++++--- lambda/src/client.rs | 20 ++++++++++++-------- lambda/src/lib.rs | 1 + 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f23ef207..c2b6161e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: Rust -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: build: @@ -68,6 +68,17 @@ jobs: override: true - name: Run fmt check run: cargo fmt --all -- --check + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: clippy + override: true + - name: Run clippy check + run: cargo clippy # publish rustdoc to a gh-pages branch on pushes to master # this can be helpful to those depending on the mainline branch diff --git a/lambda-http/Cargo.toml b/lambda-http/Cargo.toml index 575c2d3e..526f45f3 100644 --- a/lambda-http/Cargo.toml +++ b/lambda-http/Cargo.toml @@ -9,6 +9,7 @@ license = "Apache-2.0" homepage = "https://github.com/awslabs/aws-lambda-rust-runtime" repository = "https://github.com/awslabs/aws-lambda-rust-runtime" documentation = "https://docs.rs/lambda_runtime" +categories = ["web-programming::http-server"] readme = "../README.md" [badges] diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 37a30f26..6ef7e1b0 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -6,6 +6,8 @@ description = "AWS Lambda Runtime" edition = "2018" license = "Apache License 2.0" repository = "https://github.com/awslabs/aws-lambda-rust-runtime" +categories = ["web-programming::http-server"] +keywords = ["AWS", "Lambda", "API"] readme = "../README.md" [features] @@ -16,14 +18,13 @@ simulated = [] tokio = { version = "1.0", features = ["macros", "io-util", "sync", "rt-multi-thread"] } hyper = { version = "0.14", features = ["http1", "client", "server", "stream", "runtime"] } serde = { version = "1", features = ["derive"] } -serde_json = "1.0.39" +serde_json = "^1" bytes = "1.0" http = "0.2" async-stream = "0.3" futures = "0.3" tracing-error = "0.1.2" tracing = { version = "0.1", features = ["log"] } -tracing-futures = "0.2" tower-service = "0.3" tokio-stream = "0.1.2" @@ -31,5 +32,5 @@ tokio-stream = "0.1.2" tracing-subscriber = "0.2" once_cell = "1.4.0" simple_logger = "1.6.0" -log = "0.4" +log = "^0.4" simple-error = "0.2" diff --git a/lambda/src/client.rs b/lambda/src/client.rs index b24b2e78..148ec62c 100644 --- a/lambda/src/client.rs +++ b/lambda/src/client.rs @@ -31,11 +31,15 @@ where .scheme(scheme.clone()) .authority(authority.clone()) .path_and_query(path.clone()) - .build() - .expect("Unable to build URI"); + .build(); - parts.uri = uri; - Ok(Request::from_parts(parts, body)) + match uri { + Ok(u) => { + parts.uri = u; + Ok(Request::from_parts(parts, body)) + } + Err(e) => Err(Box::new(e)), + } } pub(crate) async fn call(&self, req: Request) -> Result, Error> { @@ -178,7 +182,7 @@ mod endpoint_tests { tx.send(()).expect("Receiver has been dropped"); match server.await { Ok(_) => Ok(()), - Err(e) if e.is_panic() => return Err::<(), Error>(e.into()), + Err(e) if e.is_panic() => Err::<(), Error>(e.into()), Err(_) => unreachable!("This branch shouldn't be reachable"), } } @@ -209,7 +213,7 @@ mod endpoint_tests { tx.send(()).expect("Receiver has been dropped"); match server.await { Ok(_) => Ok(()), - Err(e) if e.is_panic() => return Err::<(), Error>(e.into()), + Err(e) if e.is_panic() => Err::<(), Error>(e.into()), Err(_) => unreachable!("This branch shouldn't be reachable"), } } @@ -242,7 +246,7 @@ mod endpoint_tests { tx.send(()).expect("Receiver has been dropped"); match server.await { Ok(_) => Ok(()), - Err(e) if e.is_panic() => return Err::<(), Error>(e.into()), + Err(e) if e.is_panic() => Err::<(), Error>(e.into()), Err(_) => unreachable!("This branch shouldn't be reachable"), } } @@ -277,7 +281,7 @@ mod endpoint_tests { tx.send(()).expect("Receiver has been dropped"); match server.await { Ok(_) => Ok(()), - Err(e) if e.is_panic() => return Err::<(), Error>(e.into()), + Err(e) if e.is_panic() => Err::<(), Error>(e.into()), Err(_) => unreachable!("This branch shouldn't be reachable"), } } diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 44077f0e..ac454c33 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -156,6 +156,7 @@ where let handler = Arc::clone(&handler); let request_id = &ctx.request_id.clone(); + #[allow(clippy::async_yields_async)] let task = tokio::spawn(async move { handler.call(body, ctx) }); let req = match task.await {