Skip to content

Commit

Permalink
Bump clippy to 1.77; resolve most lints
Browse files Browse the repository at this point in the history
  • Loading branch information
msrd0 committed Apr 10, 2024
1 parent 82b5a03 commit 678f651
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions gotham/src/extractor/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -875,7 +875,7 @@ mod tests {
impl<'de> Visitor<'de> for ByteBufVisitor {
type Value = Vec<u8>;

fn expecting(&self, out: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
out.write_str("string")
}

Expand Down Expand Up @@ -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")
}

Expand All @@ -958,7 +958,7 @@ mod tests {
let mut sm = SegmentMapping::new();
sm.insert("bytes_val", vec![&bytes_val]);

let p = from_segment_mapping::<WithBorrowedBytes>(sm).unwrap();
let p = from_segment_mapping::<WithBorrowedBytes<'_>>(sm).unwrap();

assert_eq!(p.bytes_val, b"borrowed_bytes");
}
Expand All @@ -971,7 +971,7 @@ mod tests {
vec![FormUrlDecoded::new("borrowed_bytes").unwrap()],
);

let p = from_query_string_mapping::<WithBorrowedBytes>(&qsm).unwrap();
let p = from_query_string_mapping::<WithBorrowedBytes<'_>>(&qsm).unwrap();

assert_eq!(p.bytes_val, b"borrowed_bytes");
}
Expand Down Expand Up @@ -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")
}

Expand All @@ -1018,7 +1018,7 @@ mod tests {
let mut sm = SegmentMapping::new();
sm.insert("str_val", vec![&str_val]);

let p = from_segment_mapping::<WithBorrowedString>(sm).unwrap();
let p = from_segment_mapping::<WithBorrowedString<'_>>(sm).unwrap();

assert_eq!(p.str_val, "borrowed_str");
}
Expand All @@ -1031,7 +1031,7 @@ mod tests {
vec![FormUrlDecoded::new("borrowed_str").unwrap()],
);

let p = from_query_string_mapping::<WithBorrowedString>(&qsm).unwrap();
let p = from_query_string_mapping::<WithBorrowedString<'_>>(&qsm).unwrap();

assert_eq!(p.str_val, "borrowed_str");
}
Expand Down
1 change: 1 addition & 0 deletions gotham/src/handler/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion gotham/src/helpers/http/request/query_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion gotham/src/helpers/timing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
9 changes: 4 additions & 5 deletions gotham/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! You can find out more about Gotham, including where to get help, at <https://gotham.rs>.
//!
//! 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(
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/34537>
#![deny(private_in_public)]

pub mod extractor;
pub mod handler;
Expand Down
1 change: 1 addition & 0 deletions gotham/src/middleware/chain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Defines the types for connecting multiple middleware into a "chain" when forming a pipeline.
#![allow(unsafe_code)]

use log::trace;

Expand Down
4 changes: 2 additions & 2 deletions gotham/src/router/builder/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ where
/// ```
fn scope<F>(&mut self, path: &str, f: F)
where
F: FnOnce(&mut ScopeBuilder<C, P>),
F: FnOnce(&mut ScopeBuilder<'_, C, P>),
{
let (node_builder, pipeline_chain, pipelines) = self.component_refs();
let node_builder = descend(node_builder, path);
Expand Down Expand Up @@ -625,7 +625,7 @@ where
/// ```
fn with_pipeline_chain<F, NC>(&mut self, pipeline_chain: NC, f: F)
where
F: FnOnce(&mut ScopeBuilder<NC, P>),
F: FnOnce(&mut ScopeBuilder<'_, NC, P>),
NC: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
{
let (node_builder, _pipeline_chain, pipelines) = self.component_refs();
Expand Down
4 changes: 2 additions & 2 deletions gotham/src/router/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn build_router<C, P, F>(pipeline_chain: C, pipelines: PipelineSet<P>, f: F)
where
C: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P: Send + Sync + 'static,
F: FnOnce(&mut RouterBuilder<C, P>),
F: FnOnce(&mut RouterBuilder<'_, C, P>),
{
let mut tree = Tree::new();

Expand Down Expand Up @@ -134,7 +134,7 @@ where
/// ```
pub fn build_simple_router<F>(f: F) -> Router
where
F: FnOnce(&mut RouterBuilder<(), ()>),
F: FnOnce(&mut RouterBuilder<'_, (), ()>),
{
let pipelines = finalize_pipeline_set(new_pipeline_set());
build_router((), pipelines, f)
Expand Down
2 changes: 1 addition & 1 deletion gotham/src/router/route/matcher/lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn insert<T>(into: &mut LookupTable, key: T, value: usize)
where
T: Into<String> + ?Sized,
{
into.entry(key.into()).or_insert_with(Vec::new).push(value);
into.entry(key.into()).or_default().push(value);
}

impl LookupTableFromTypes for LookupTable {
Expand Down
5 changes: 1 addition & 4 deletions gotham/src/router/tree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gotham/src/test/async_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
22 changes: 11 additions & 11 deletions gotham/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub struct TestClient<TS: Server, C: Connect> {

impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClient<TS, C> {
/// Begin constructing a HEAD request using this `TestClient`.
pub fn head<U>(&self, uri: U) -> TestRequest<TS, C>
pub fn head<U>(&self, uri: U) -> TestRequest<'_, TS, C>
where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<http::Error>,
Expand All @@ -180,7 +180,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Begin constructing a GET request using this `TestClient`.
pub fn get<U>(&self, uri: U) -> TestRequest<TS, C>
pub fn get<U>(&self, uri: U) -> TestRequest<'_, TS, C>
where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<http::Error>,
Expand All @@ -189,7 +189,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Begin constructing an OPTIONS request using this `TestClient`.
pub fn options<U>(&self, uri: U) -> TestRequest<TS, C>
pub fn options<U>(&self, uri: U) -> TestRequest<'_, TS, C>
where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<http::Error>,
Expand All @@ -198,7 +198,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Begin constructing a POST request using this `TestClient`.
pub fn post<B, U>(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<TS, C>
pub fn post<B, U>(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<'_, TS, C>
where
B: Into<Body>,
Uri: TryFrom<U>,
Expand All @@ -208,7 +208,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Begin constructing a PUT request using this `TestClient`.
pub fn put<B, U>(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<TS, C>
pub fn put<B, U>(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<'_, TS, C>
where
B: Into<Body>,
Uri: TryFrom<U>,
Expand All @@ -218,7 +218,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Begin constructing a PATCH request using this `TestClient`.
pub fn patch<B, U>(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<TS, C>
pub fn patch<B, U>(&self, uri: U, body: B, mime: mime::Mime) -> TestRequest<'_, TS, C>
where
B: Into<Body>,
Uri: TryFrom<U>,
Expand All @@ -228,7 +228,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Begin constructing a DELETE request using this `TestClient`.
pub fn delete<U>(&self, uri: U) -> TestRequest<TS, C>
pub fn delete<U>(&self, uri: U) -> TestRequest<'_, TS, C>
where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<http::Error>,
Expand All @@ -237,7 +237,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Begin constructing a request with the given HTTP method and URI.
pub fn build_request<U>(&self, method: Method, uri: U) -> TestRequest<TS, C>
pub fn build_request<U>(&self, method: Method, uri: U) -> TestRequest<'_, TS, C>
where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<http::Error>,
Expand All @@ -252,7 +252,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
uri: U,
body: B,
mime: mime::Mime,
) -> TestRequest<TS, C>
) -> TestRequest<'_, TS, C>
where
B: Into<Body>,
Uri: TryFrom<U>,
Expand All @@ -271,7 +271,7 @@ impl<TS: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestClien
}

/// Send a constructed request using this `TestClient`, and await the response.
pub fn perform(&self, req: TestRequest<TS, C>) -> anyhow::Result<TestResponse> {
pub fn perform(&self, req: TestRequest<'_, TS, C>) -> anyhow::Result<TestResponse> {
let req_future = self.client.request(req.request()).map_err(|e| {
warn!("Error from test client request {:?}", e);
e
Expand Down Expand Up @@ -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")
}
}
Expand Down
4 changes: 2 additions & 2 deletions gotham/src/tls/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<(), io::Error>> {
self.project().0.poll_read(cx, buf)
}
Expand Down
2 changes: 2 additions & 0 deletions middleware/diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion middleware/diesel/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ where
}

#[derive(Debug)]
pub struct TestConnectionCustomizer;
struct TestConnectionCustomizer;

impl<C, E> CustomizeConnection<C, E> for TestConnectionCustomizer
where
Expand Down
3 changes: 2 additions & 1 deletion middleware/jwt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion middleware/jwt/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod tests {
const SECRET: &str = "some-secret";

#[derive(Debug, Deserialize, Serialize)]
pub struct Claims {
struct Claims {
sub: String,
exp: usize,
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/jwt/src/state_data.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 2 additions & 4 deletions middleware/template/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/34537>
#![deny(private_in_public)]

#[macro_use]
extern crate log;
Expand Down
8 changes: 2 additions & 6 deletions misc/borrow_bag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/34537>
#![deny(private_in_public)]

mod append;
mod handle;
Expand Down

0 comments on commit 678f651

Please sign in to comment.