From 678f65145f517cda2ca4451d89e710a2a9e1666f Mon Sep 17 00:00:00 2001 From: Dominic Date: Wed, 10 Apr 2024 13:51:31 +0200 Subject: [PATCH] Bump clippy to 1.77; resolve most lints --- .github/workflows/rust.yml | 2 +- gotham/src/extractor/internal.rs | 16 +++++++------- gotham/src/handler/assets/mod.rs | 1 + .../src/helpers/http/request/query_string.rs | 2 +- gotham/src/helpers/timing.rs | 2 +- gotham/src/lib.rs | 9 ++++---- gotham/src/middleware/chain.rs | 1 + gotham/src/router/builder/draw.rs | 4 ++-- gotham/src/router/builder/mod.rs | 4 ++-- .../src/router/route/matcher/lookup_table.rs | 2 +- gotham/src/router/tree/node.rs | 5 +---- gotham/src/test/async_test.rs | 2 +- gotham/src/test/mod.rs | 22 +++++++++---------- gotham/src/tls/test.rs | 4 ++-- middleware/diesel/src/lib.rs | 2 ++ middleware/diesel/src/repo.rs | 2 +- middleware/jwt/src/lib.rs | 3 ++- middleware/jwt/src/middleware.rs | 2 +- middleware/jwt/src/state_data.rs | 2 +- middleware/template/src/lib.rs | 6 ++--- misc/borrow_bag/src/lib.rs | 8 ++----- 21 files changed, 48 insertions(+), 53 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1097b1de3..260492e2d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -77,7 +77,7 @@ jobs: - uses: dtolnay/rust-toolchain@master id: rust-toolchain with: - toolchain: "1.72" + toolchain: "1.77" components: clippy - uses: actions/cache@v4 diff --git a/gotham/src/extractor/internal.rs b/gotham/src/extractor/internal.rs index ed06151b1..5c2a07c68 100644 --- a/gotham/src/extractor/internal.rs +++ b/gotham/src/extractor/internal.rs @@ -85,7 +85,7 @@ pub(crate) enum ExtractorError { } impl Display for ExtractorError { - fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result { out.write_fmt(format_args!("{:?}", self)) } } @@ -875,7 +875,7 @@ mod tests { impl<'de> Visitor<'de> for ByteBufVisitor { type Value = Vec; - fn expecting(&self, out: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result { out.write_str("string") } @@ -938,7 +938,7 @@ mod tests { impl<'de> Visitor<'de> for BorrowedBytesVisitor { type Value = &'de [u8]; - fn expecting(&self, out: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result { out.write_str("borrowed bytes") } @@ -958,7 +958,7 @@ mod tests { let mut sm = SegmentMapping::new(); sm.insert("bytes_val", vec![&bytes_val]); - let p = from_segment_mapping::(sm).unwrap(); + let p = from_segment_mapping::>(sm).unwrap(); assert_eq!(p.bytes_val, b"borrowed_bytes"); } @@ -971,7 +971,7 @@ mod tests { vec![FormUrlDecoded::new("borrowed_bytes").unwrap()], ); - let p = from_query_string_mapping::(&qsm).unwrap(); + let p = from_query_string_mapping::>(&qsm).unwrap(); assert_eq!(p.bytes_val, b"borrowed_bytes"); } @@ -1001,7 +1001,7 @@ mod tests { impl<'de> Visitor<'de> for BorrowedStrVisitor { type Value = &'de str; - fn expecting(&self, out: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result { out.write_str("borrowed string") } @@ -1018,7 +1018,7 @@ mod tests { let mut sm = SegmentMapping::new(); sm.insert("str_val", vec![&str_val]); - let p = from_segment_mapping::(sm).unwrap(); + let p = from_segment_mapping::>(sm).unwrap(); assert_eq!(p.str_val, "borrowed_str"); } @@ -1031,7 +1031,7 @@ mod tests { vec![FormUrlDecoded::new("borrowed_str").unwrap()], ); - let p = from_query_string_mapping::(&qsm).unwrap(); + let p = from_query_string_mapping::>(&qsm).unwrap(); assert_eq!(p.str_val, "borrowed_str"); } diff --git a/gotham/src/handler/assets/mod.rs b/gotham/src/handler/assets/mod.rs index e20293df3..87af59520 100644 --- a/gotham/src/handler/assets/mod.rs +++ b/gotham/src/handler/assets/mod.rs @@ -450,6 +450,7 @@ impl StaticResponseExtender for FilePathExtractor { // Inspired by Warp https://github.com/seanmonstar/warp/blob/master/src/filters/fs.rs // Inspired by tokio https://github.com/tokio-rs/tokio/blob/master/tokio/src/io/util/read_buf.rs // Thanks @seanmonstar and @carllerche. +#[allow(unsafe_code)] fn file_stream( mut f: File, buf_size: usize, diff --git a/gotham/src/helpers/http/request/query_string.rs b/gotham/src/helpers/http/request/query_string.rs index 106816cc8..135fa9aef 100644 --- a/gotham/src/helpers/http/request/query_string.rs +++ b/gotham/src/helpers/http/request/query_string.rs @@ -24,7 +24,7 @@ pub(crate) fn split<'r>(query: Option<&'r str>) -> QueryStringMapping { let (k, v) = (sp.next().unwrap(), sp.next().unwrap()); if let Ok(k) = form_url_decode(k) { - let vec = query_string_mapping.entry(k).or_insert_with(Vec::new); + let vec = query_string_mapping.entry(k).or_default(); if let Some(dv) = FormUrlDecoded::new(v) { vec.push(dv); } diff --git a/gotham/src/helpers/timing.rs b/gotham/src/helpers/timing.rs index ebd465773..6ef59b5e1 100644 --- a/gotham/src/helpers/timing.rs +++ b/gotham/src/helpers/timing.rs @@ -47,7 +47,7 @@ impl Timer { pub(crate) struct Timing(Duration); impl Display for Timing { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let duration = self.0; match duration.as_micros() { i if i < 1000 => { diff --git a/gotham/src/lib.rs b/gotham/src/lib.rs index bae9eb8f8..1f123335b 100644 --- a/gotham/src/lib.rs +++ b/gotham/src/lib.rs @@ -3,8 +3,8 @@ //! You can find out more about Gotham, including where to get help, at . //! //! We look forward to welcoming you into the Gotham community! -#![doc(html_root_url = "https://docs.rs/gotham/0.7.3")] // Update when changed in Cargo.toml -#![warn(deprecated, missing_docs, unreachable_pub)] +#![doc(html_root_url = "https://docs.rs/gotham/0.7.3")] +// Update when changed in Cargo.toml // Stricter requirements once we get to pull request stage, all warnings must be resolved. #![cfg_attr(feature = "ci", deny(warnings))] #![allow( @@ -18,10 +18,9 @@ clippy::borrowed_box, clippy::get_unwrap )] +#![warn(missing_docs, rust_2018_idioms, unreachable_pub)] +#![deny(elided_lifetimes_in_paths, unsafe_code)] #![doc(test(no_crate_inject, attr(deny(warnings))))] -// TODO: Remove this when it's a hard error by default (error E0446). -// See Rust issue #34537 -#![deny(private_in_public)] pub mod extractor; pub mod handler; diff --git a/gotham/src/middleware/chain.rs b/gotham/src/middleware/chain.rs index a30cdaa24..3de84f362 100644 --- a/gotham/src/middleware/chain.rs +++ b/gotham/src/middleware/chain.rs @@ -1,4 +1,5 @@ //! Defines the types for connecting multiple middleware into a "chain" when forming a pipeline. +#![allow(unsafe_code)] use log::trace; diff --git a/gotham/src/router/builder/draw.rs b/gotham/src/router/builder/draw.rs index b9a93f98f..c2d31fa76 100644 --- a/gotham/src/router/builder/draw.rs +++ b/gotham/src/router/builder/draw.rs @@ -513,7 +513,7 @@ where /// ``` fn scope(&mut self, path: &str, f: F) where - F: FnOnce(&mut ScopeBuilder), + F: FnOnce(&mut ScopeBuilder<'_, C, P>), { let (node_builder, pipeline_chain, pipelines) = self.component_refs(); let node_builder = descend(node_builder, path); @@ -625,7 +625,7 @@ where /// ``` fn with_pipeline_chain(&mut self, pipeline_chain: NC, f: F) where - F: FnOnce(&mut ScopeBuilder), + F: FnOnce(&mut ScopeBuilder<'_, NC, P>), NC: PipelineHandleChain

+ Copy + Send + Sync + 'static, { let (node_builder, _pipeline_chain, pipelines) = self.component_refs(); diff --git a/gotham/src/router/builder/mod.rs b/gotham/src/router/builder/mod.rs index 66b3984b3..8dcfd78ff 100644 --- a/gotham/src/router/builder/mod.rs +++ b/gotham/src/router/builder/mod.rs @@ -79,7 +79,7 @@ pub fn build_router(pipeline_chain: C, pipelines: PipelineSet

, f: F) where C: PipelineHandleChain

+ Copy + Send + Sync + 'static, P: Send + Sync + 'static, - F: FnOnce(&mut RouterBuilder), + F: FnOnce(&mut RouterBuilder<'_, C, P>), { let mut tree = Tree::new(); @@ -134,7 +134,7 @@ where /// ``` pub fn build_simple_router(f: F) -> Router where - F: FnOnce(&mut RouterBuilder<(), ()>), + F: FnOnce(&mut RouterBuilder<'_, (), ()>), { let pipelines = finalize_pipeline_set(new_pipeline_set()); build_router((), pipelines, f) diff --git a/gotham/src/router/route/matcher/lookup_table.rs b/gotham/src/router/route/matcher/lookup_table.rs index 66e715ac7..1cbd98cc7 100644 --- a/gotham/src/router/route/matcher/lookup_table.rs +++ b/gotham/src/router/route/matcher/lookup_table.rs @@ -14,7 +14,7 @@ fn insert(into: &mut LookupTable, key: T, value: usize) where T: Into + ?Sized, { - into.entry(key.into()).or_insert_with(Vec::new).push(value); + into.entry(key.into()).or_default().push(value); } impl LookupTableFromTypes for LookupTable { diff --git a/gotham/src/router/tree/node.rs b/gotham/src/router/tree/node.rs index 199b4b2cd..4d4050f8b 100644 --- a/gotham/src/router/tree/node.rs +++ b/gotham/src/router/tree/node.rs @@ -203,10 +203,7 @@ impl Node { // Globbing matches everything, so we append the segment value // to the parameters against the child segment name. SegmentType::Glob => { - params - .entry(&child.segment) - .or_insert_with(Vec::new) - .push(segment); + params.entry(&child.segment).or_default().push(segment); } // Static matches based on a raw string match, so we simply diff --git a/gotham/src/test/async_test.rs b/gotham/src/test/async_test.rs index 55e3c4463..5c09e29d0 100644 --- a/gotham/src/test/async_test.rs +++ b/gotham/src/test/async_test.rs @@ -349,7 +349,7 @@ impl DerefMut for AsyncTestResponse { } impl Debug for AsyncTestResponse { - fn fmt(&self, formatter: &mut Formatter) -> std::fmt::Result { + fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { formatter.write_str("AsyncTestResponse") } } diff --git a/gotham/src/test/mod.rs b/gotham/src/test/mod.rs index 1a158ae89..90b788f0e 100644 --- a/gotham/src/test/mod.rs +++ b/gotham/src/test/mod.rs @@ -171,7 +171,7 @@ pub struct TestClient { impl TestClient { /// Begin constructing a HEAD request using this `TestClient`. - pub fn head(&self, uri: U) -> TestRequest + pub fn head(&self, uri: U) -> TestRequest<'_, TS, C> where Uri: TryFrom, >::Error: Into, @@ -180,7 +180,7 @@ impl TestClien } /// Begin constructing a GET request using this `TestClient`. - pub fn get(&self, uri: U) -> TestRequest + pub fn get(&self, uri: U) -> TestRequest<'_, TS, C> where Uri: TryFrom, >::Error: Into, @@ -189,7 +189,7 @@ impl TestClien } /// Begin constructing an OPTIONS request using this `TestClient`. - pub fn options(&self, uri: U) -> TestRequest + pub fn options(&self, uri: U) -> TestRequest<'_, TS, C> where Uri: TryFrom, >::Error: Into, @@ -198,7 +198,7 @@ impl TestClien } /// Begin constructing a POST request using this `TestClient`. - pub fn post(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest + pub fn post(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<'_, TS, C> where B: Into, Uri: TryFrom, @@ -208,7 +208,7 @@ impl TestClien } /// Begin constructing a PUT request using this `TestClient`. - pub fn put(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest + pub fn put(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<'_, TS, C> where B: Into, Uri: TryFrom, @@ -218,7 +218,7 @@ impl TestClien } /// Begin constructing a PATCH request using this `TestClient`. - pub fn patch(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest + pub fn patch(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<'_, TS, C> where B: Into, Uri: TryFrom, @@ -228,7 +228,7 @@ impl TestClien } /// Begin constructing a DELETE request using this `TestClient`. - pub fn delete(&self, uri: U) -> TestRequest + pub fn delete(&self, uri: U) -> TestRequest<'_, TS, C> where Uri: TryFrom, >::Error: Into, @@ -237,7 +237,7 @@ impl TestClien } /// Begin constructing a request with the given HTTP method and URI. - pub fn build_request(&self, method: Method, uri: U) -> TestRequest + pub fn build_request(&self, method: Method, uri: U) -> TestRequest<'_, TS, C> where Uri: TryFrom, >::Error: Into, @@ -252,7 +252,7 @@ impl TestClien uri: U, body: B, mime: mime::Mime, - ) -> TestRequest + ) -> TestRequest<'_, TS, C> where B: Into, Uri: TryFrom, @@ -271,7 +271,7 @@ impl TestClien } /// Send a constructed request using this `TestClient`, and await the response. - pub fn perform(&self, req: TestRequest) -> anyhow::Result { + pub fn perform(&self, req: TestRequest<'_, TS, C>) -> anyhow::Result { let req_future = self.client.request(req.request()).map_err(|e| { warn!("Error from test client request {:?}", e); e @@ -346,7 +346,7 @@ impl DerefMut for TestResponse { } impl fmt::Debug for TestResponse { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "TestResponse") } } diff --git a/gotham/src/tls/test.rs b/gotham/src/tls/test.rs index 6be0f1ea0..54cf90891 100644 --- a/gotham/src/tls/test.rs +++ b/gotham/src/tls/test.rs @@ -206,8 +206,8 @@ where #[inline] fn poll_read( self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut ReadBuf, + cx: &mut Context<'_>, + buf: &mut ReadBuf<'_>, ) -> Poll> { self.project().0.poll_read(cx, buf) } diff --git a/middleware/diesel/src/lib.rs b/middleware/diesel/src/lib.rs index e1cb94688..32082f2a1 100644 --- a/middleware/diesel/src/lib.rs +++ b/middleware/diesel/src/lib.rs @@ -74,6 +74,8 @@ //! # assert_eq!(&body, "result: 1"); //! # } //! ``` +#![warn(rust_2018_idioms, unreachable_pub)] +#![forbid(elided_lifetimes_in_paths, unsafe_code)] #![doc(test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] use diesel::r2d2::R2D2Connection; diff --git a/middleware/diesel/src/repo.rs b/middleware/diesel/src/repo.rs index 9071b0e5d..f3d0f6e48 100644 --- a/middleware/diesel/src/repo.rs +++ b/middleware/diesel/src/repo.rs @@ -152,7 +152,7 @@ where } #[derive(Debug)] -pub struct TestConnectionCustomizer; +struct TestConnectionCustomizer; impl CustomizeConnection for TestConnectionCustomizer where diff --git a/middleware/jwt/src/lib.rs b/middleware/jwt/src/lib.rs index dae1adcb3..d0ef86bbc 100644 --- a/middleware/jwt/src/lib.rs +++ b/middleware/jwt/src/lib.rs @@ -6,7 +6,8 @@ //! Status Code `400: Bad Request`. Tokens that fail //! validation cause the middleware to return Status Code //! `401: Unauthorized`. -#![warn(missing_docs, rust_2018_idioms)] +#![warn(missing_docs, rust_2018_idioms, unreachable_pub)] +#![forbid(elided_lifetimes_in_paths, unsafe_code)] mod middleware; mod state_data; diff --git a/middleware/jwt/src/middleware.rs b/middleware/jwt/src/middleware.rs index 796e01b89..b03b4d5ea 100644 --- a/middleware/jwt/src/middleware.rs +++ b/middleware/jwt/src/middleware.rs @@ -191,7 +191,7 @@ mod tests { const SECRET: &str = "some-secret"; #[derive(Debug, Deserialize, Serialize)] - pub struct Claims { + struct Claims { sub: String, exp: usize, } diff --git a/middleware/jwt/src/state_data.rs b/middleware/jwt/src/state_data.rs index fc9593403..b3f300674 100644 --- a/middleware/jwt/src/state_data.rs +++ b/middleware/jwt/src/state_data.rs @@ -1,5 +1,5 @@ use gotham::prelude::*; -pub use jsonwebtoken::TokenData; +use jsonwebtoken::TokenData; /// Struct to contain the JSON Web Token on a per-request basis. #[derive(StateData, Debug)] diff --git a/middleware/template/src/lib.rs b/middleware/template/src/lib.rs index a8a2d5c59..dadc942d0 100644 --- a/middleware/template/src/lib.rs +++ b/middleware/template/src/lib.rs @@ -1,10 +1,8 @@ //! Documentation for your crate, explaining what this Middleware does -#![warn(missing_docs, deprecated)] +#![warn(missing_docs, unreachable_pub)] +#![forbid(elided_lifetimes_in_paths, unsafe_code)] #![doc(test(no_crate_inject, attr(deny(warnings))))] -// TODO: Remove this when it's a hard error by default (error E0446). -// See Rust issue #34537 -#![deny(private_in_public)] #[macro_use] extern crate log; diff --git a/misc/borrow_bag/src/lib.rs b/misc/borrow_bag/src/lib.rs index 0826e951f..d40d42417 100644 --- a/misc/borrow_bag/src/lib.rs +++ b/misc/borrow_bag/src/lib.rs @@ -5,14 +5,10 @@ //! lifetime of the `BorrowBag`. #![doc(html_root_url = "https://docs.rs/borrow-bag/1.1.1")] // Update when changed in Cargo.toml -#![warn(missing_docs, deprecated)] -// Stricter requirements once we get to pull request stage, all warnings must be resolved. -#![cfg_attr(feature = "ci", deny(warnings))] #![allow(clippy::should_implement_trait)] +#![warn(missing_docs)] +#![forbid(elided_lifetimes_in_paths, unsafe_code)] #![doc(test(attr(deny(warnings))))] -// TODO: Remove this when it's a hard error by default (error E0446). -// See Rust issue #34537 -#![deny(private_in_public)] mod append; mod handle;