Use nightly clippy & rustfmt for more style checks (#487)

This commit is contained in:
Jonas Platte 2021-11-09 12:53:57 +01:00 committed by GitHub
parent bcd18a03bc
commit 9c77ee0295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 69 additions and 65 deletions

View File

@ -14,10 +14,10 @@ jobs:
- uses: actions/checkout@master - uses: actions/checkout@master
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
toolchain: stable toolchain: nightly
override: true override: true
profile: minimal profile: minimal
components: clippy components: clippy, rustfmt
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v1
- name: Check - name: Check
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1

2
.rustfmt.toml Normal file
View File

@ -0,0 +1,2 @@
# Merge multiple `use`s from the same crate
imports_granularity = "Crate"

View File

@ -125,6 +125,7 @@
clippy::option_option, clippy::option_option,
clippy::verbose_file_reads, clippy::verbose_file_reads,
clippy::unnested_or_patterns, clippy::unnested_or_patterns,
clippy::self_named_module_files,
rust_2018_idioms, rust_2018_idioms,
future_incompatible, future_incompatible,
nonstandard_style, nonstandard_style,

View File

@ -1,7 +1,6 @@
//! HTTP body utilities. //! HTTP body utilities.
use crate::BoxError; use crate::{BoxError, Error};
use crate::Error;
mod stream_body; mod stream_body;

View File

@ -3,8 +3,8 @@
use crate::{body::BoxBody, response::IntoResponse, BoxError}; use crate::{body::BoxBody, response::IntoResponse, BoxError};
use bytes::Bytes; use bytes::Bytes;
use http::{Request, Response}; use http::{Request, Response};
use std::convert::Infallible;
use std::{ use std::{
convert::Infallible,
fmt, fmt,
marker::PhantomData, marker::PhantomData,
task::{Context, Poll}, task::{Context, Poll},
@ -159,8 +159,8 @@ pub mod future {
use futures_util::ready; use futures_util::ready;
use http::Response; use http::Response;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::convert::Infallible;
use std::{ use std::{
convert::Infallible,
future::Future, future::Future,
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},

View File

@ -8,10 +8,10 @@ use super::{Extension, FromRequest, RequestParts};
use crate::{AddExtension, AddExtensionLayer}; use crate::{AddExtension, AddExtensionLayer};
use async_trait::async_trait; use async_trait::async_trait;
use hyper::server::conn::AddrStream; use hyper::server::conn::AddrStream;
use std::future::ready;
use std::{ use std::{
convert::Infallible, convert::Infallible,
fmt, fmt,
future::ready,
marker::PhantomData, marker::PhantomData,
net::SocketAddr, net::SocketAddr,
task::{Context, Poll}, task::{Context, Poll},
@ -144,8 +144,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::Server; use crate::{routing::get, Router, Server};
use crate::{routing::get, Router};
use std::net::{SocketAddr, TcpListener}; use std::net::{SocketAddr, TcpListener};
#[tokio::test] #[tokio::test]

View File

@ -88,6 +88,7 @@ mod tests {
use std::iter::repeat; use std::iter::repeat;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct Input { struct Input {
foo: String, foo: String,
} }

View File

@ -3,8 +3,7 @@
//! See [`extractor_middleware`] for more details. //! See [`extractor_middleware`] for more details.
use super::{FromRequest, RequestParts}; use super::{FromRequest, RequestParts};
use crate::BoxError; use crate::{body::BoxBody, response::IntoResponse, BoxError};
use crate::{body::BoxBody, response::IntoResponse};
use bytes::Bytes; use bytes::Bytes;
use futures_util::{future::BoxFuture, ready}; use futures_util::{future::BoxFuture, ready};
use http::{Request, Response}; use http::{Request, Response};

View File

@ -359,8 +359,7 @@ pub(crate) fn take_body<B>(req: &mut RequestParts<B>) -> Result<B, BodyAlreadyEx
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::test_helpers::*; use crate::{routing::get, test_helpers::*, Router};
use crate::{routing::get, Router};
#[tokio::test] #[tokio::test]
async fn consume_body() { async fn consume_body() {

View File

@ -176,8 +176,7 @@ mod tests {
use http::StatusCode; use http::StatusCode;
use super::*; use super::*;
use crate::test_helpers::*; use crate::{routing::get, test_helpers::*, Router};
use crate::{routing::get, Router};
use std::collections::HashMap; use std::collections::HashMap;
#[tokio::test] #[tokio::test]

View File

@ -1,10 +1,9 @@
//! Rejection response types. //! Rejection response types.
use super::IntoResponse; use super::IntoResponse;
use crate::BoxError;
use crate::{ use crate::{
body::{box_body, BoxBody}, body::{box_body, BoxBody},
Error, BoxError, Error,
}; };
use bytes::Bytes; use bytes::Bytes;
use http_body::Full; use http_body::Full;

View File

@ -131,7 +131,8 @@ impl WebSocketUpgrade {
/// Set the known protocols. /// Set the known protocols.
/// ///
/// If the protocol name specified by `Sec-WebSocket-Protocol` header /// If the protocol name specified by `Sec-WebSocket-Protocol` header
/// to match any of them, the upgrade response will include `Sec-WebSocket-Protocol` header and return the protocol name. /// to match any of them, the upgrade response will include `Sec-WebSocket-Protocol` header and
/// return the protocol name.
/// ///
/// # Examples /// # Examples
/// ///

View File

@ -64,9 +64,9 @@ where
#[inline] #[inline]
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
// `IntoService` can only be constructed from async functions which are always ready, or from // `IntoService` can only be constructed from async functions which are always ready, or
// `Layered` which bufferes in `<Layered as Handler>::call` and is therefore also always // from `Layered` which bufferes in `<Layered as Handler>::call` and is therefore
// ready. // also always ready.
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }

View File

@ -407,8 +407,7 @@ mod tests {
#[test] #[test]
fn traits() { fn traits() {
use crate::routing::MethodRouter; use crate::{routing::MethodRouter, test_helpers::*};
use crate::test_helpers::*;
assert_send::<MethodRouter<(), NotSendSync, NotSendSync, ()>>(); assert_send::<MethodRouter<(), NotSendSync, NotSendSync, ()>>();
assert_sync::<MethodRouter<(), NotSendSync, NotSendSync, ()>>(); assert_sync::<MethodRouter<(), NotSendSync, NotSendSync, ()>>();
} }

View File

@ -1,7 +1,7 @@
use crate::BoxError;
use crate::{ use crate::{
extract::{rejection::*, take_body, FromRequest, RequestParts}, extract::{rejection::*, take_body, FromRequest, RequestParts},
response::IntoResponse, response::IntoResponse,
BoxError,
}; };
use async_trait::async_trait; use async_trait::async_trait;
use bytes::Bytes; use bytes::Bytes;
@ -50,8 +50,8 @@ use std::{
/// # }; /// # };
/// ``` /// ```
/// ///
/// When used as a response, it can serialize any type that implements [`serde::Serialize`] to `JSON`, /// When used as a response, it can serialize any type that implements [`serde::Serialize`] to
/// and will automatically set `Content-Type: application/json` header. /// `JSON`, and will automatically set `Content-Type: application/json` header.
/// ///
/// # Response example /// # Response example
/// ///

View File

@ -295,6 +295,7 @@
clippy::option_option, clippy::option_option,
clippy::verbose_file_reads, clippy::verbose_file_reads,
clippy::unnested_or_patterns, clippy::unnested_or_patterns,
clippy::self_named_module_files,
rust_2018_idioms, rust_2018_idioms,
future_incompatible, future_incompatible,
nonstandard_style, nonstandard_style,

View File

@ -4,8 +4,10 @@ use crate::{
BoxError, BoxError,
}; };
use bytes::Bytes; use bytes::Bytes;
use http::header::{HeaderMap, HeaderName, HeaderValue}; use http::{
use http::{Response, StatusCode}; header::{HeaderMap, HeaderName, HeaderValue},
Response, StatusCode,
};
use http_body::{Body, Full}; use http_body::{Body, Full};
use std::{convert::TryInto, fmt}; use std::{convert::TryInto, fmt};
use tower::util::Either; use tower::util::Either;

View File

@ -27,8 +27,7 @@
//! # }; //! # };
//! ``` //! ```
use crate::response::IntoResponse; use crate::{response::IntoResponse, BoxError};
use crate::BoxError;
use bytes::Bytes; use bytes::Bytes;
use futures_util::{ use futures_util::{
ready, ready,

View File

@ -7,8 +7,7 @@ use crate::{
util::{Either, EitherProj}, util::{Either, EitherProj},
}; };
use futures_util::{future::BoxFuture, ready}; use futures_util::{future::BoxFuture, ready};
use http::Method; use http::{Method, Request, Response};
use http::{Request, Response};
use http_body::Empty; use http_body::Empty;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::{ use std::{
@ -19,8 +18,7 @@ use std::{
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
}; };
use tower::util::Oneshot; use tower::{util::Oneshot, ServiceExt};
use tower::ServiceExt;
use tower_service::Service; use tower_service::Service;
/// Route requests with any standard HTTP method to the given handler. /// Route requests with any standard HTTP method to the given handler.

View File

@ -1,7 +1,6 @@
//! Routing between [`Service`]s and handlers. //! Routing between [`Service`]s and handlers.
use self::future::RouterFuture; use self::{future::RouterFuture, not_found::NotFound};
use self::not_found::NotFound;
use crate::{ use crate::{
body::{box_body, Body, BoxBody}, body::{box_body, Body, BoxBody},
extract::{ extract::{

View File

@ -107,15 +107,14 @@ use futures_util::ready;
use http::{Method, Request, Response}; use http::{Method, Request, Response};
use http_body::Empty; use http_body::Empty;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::marker::PhantomData;
use std::{ use std::{
fmt, fmt,
future::Future, future::Future,
marker::PhantomData,
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
}; };
use tower::util::Oneshot; use tower::{util::Oneshot, ServiceExt as _};
use tower::ServiceExt as _;
use tower_service::Service; use tower_service::Service;
/// Route requests with any standard HTTP method to the given service. /// Route requests with any standard HTTP method to the given service.

View File

@ -1,23 +1,21 @@
use crate::error_handling::HandleErrorLayer;
use crate::test_helpers::*;
use crate::BoxError;
use crate::{ use crate::{
error_handling::HandleErrorLayer,
extract::{self, Path}, extract::{self, Path},
handler::Handler, handler::Handler,
response::IntoResponse, response::IntoResponse,
routing::{any, delete, get, on, patch, post, service_method_routing as service, MethodFilter}, routing::{any, delete, get, on, patch, post, service_method_routing as service, MethodFilter},
Json, Router, test_helpers::*,
BoxError, Json, Router,
}; };
use bytes::Bytes; use bytes::Bytes;
use http::{header::HeaderMap, Method, Request, Response, StatusCode, Uri}; use http::{header::HeaderMap, Method, Request, Response, StatusCode, Uri};
use hyper::Body; use hyper::Body;
use serde::Deserialize; use serde::Deserialize;
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::future::Ready;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{ use std::{
convert::Infallible, convert::Infallible,
future::ready, future::{ready, Ready},
sync::atomic::{AtomicUsize, Ordering},
task::{Context, Poll}, task::{Context, Poll},
time::Duration, time::Duration,
}; };

View File

@ -1,7 +1,5 @@
use super::*; use super::*;
use crate::body::box_body; use crate::{body::box_body, error_handling::HandleErrorExt, extract::Extension};
use crate::error_handling::HandleErrorExt;
use crate::extract::Extension;
use std::collections::HashMap; use std::collections::HashMap;
#[tokio::test] #[tokio::test]

View File

@ -6,8 +6,10 @@ use http::{
Request, StatusCode, Request, StatusCode,
}; };
use hyper::{Body, Server}; use hyper::{Body, Server};
use std::net::SocketAddr; use std::{
use std::{convert::TryFrom, net::TcpListener}; convert::TryFrom,
net::{SocketAddr, TcpListener},
};
use tower::make::Shared; use tower::make::Shared;
use tower_service::Service; use tower_service::Service;

View File

@ -1,9 +1,15 @@
mod starwars; mod starwars;
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig}; use async_graphql::{
use async_graphql::{EmptyMutation, EmptySubscription, Request, Response, Schema}; http::{playground_source, GraphQLPlaygroundConfig},
use axum::response::IntoResponse; EmptyMutation, EmptySubscription, Request, Response, Schema,
use axum::{extract::Extension, response::Html, routing::get, AddExtensionLayer, Json, Router}; };
use axum::{
extract::Extension,
response::{Html, IntoResponse},
routing::get,
AddExtensionLayer, Json, Router,
};
use starwars::{QueryRoot, StarWars, StarWarsSchema}; use starwars::{QueryRoot, StarWars, StarWarsSchema};
async fn graphql_handler(schema: Extension<StarWarsSchema>, req: Json<Request>) -> Json<Response> { async fn graphql_handler(schema: Extension<StarWarsSchema>, req: Json<Request>) -> Json<Response> {

View File

@ -1,6 +1,8 @@
use super::StarWars; use super::StarWars;
use async_graphql::connection::{query, Connection, Edge, EmptyFields}; use async_graphql::{
use async_graphql::{Context, Enum, FieldResult, Interface, Object}; connection::{query, Connection, Edge, EmptyFields},
Context, Enum, FieldResult, Interface, Object,
};
/// One of the films in the Star Wars Trilogy /// One of the films in the Star Wars Trilogy
#[derive(Enum, Copy, Clone, Eq, PartialEq)] #[derive(Enum, Copy, Clone, Eq, PartialEq)]

View File

@ -6,8 +6,7 @@
use axum::{ use axum::{
async_trait, async_trait,
extract::rejection::JsonRejection, extract::{rejection::JsonRejection, FromRequest, RequestParts},
extract::{FromRequest, RequestParts},
http::StatusCode, http::StatusCode,
routing::post, routing::post,
BoxError, Router, BoxError, Router,

View File

@ -148,6 +148,7 @@ async fn logout(
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct AuthRequest { struct AuthRequest {
code: String, code: String,
state: String, state: String,

View File

@ -31,6 +31,7 @@ async fn handler(Query(params): Query<Params>) -> String {
/// ///
/// [`serde_with`]: https://docs.rs/serde_with/1.11.0/serde_with/rust/string_empty_as_none/index.html /// [`serde_with`]: https://docs.rs/serde_with/1.11.0/serde_with/rust/string_empty_as_none/index.html
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct Params { struct Params {
#[serde(default, deserialize_with = "empty_string_as_none")] #[serde(default, deserialize_with = "empty_string_as_none")]
foo: Option<String>, foo: Option<String>,

View File

@ -47,8 +47,10 @@ fn app() -> Router {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use axum::body::Body; use axum::{
use axum::http::{self, Request, StatusCode}; body::Body,
http::{self, Request, StatusCode},
};
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::net::{SocketAddr, TcpListener}; use std::net::{SocketAddr, TcpListener};
use tower::ServiceExt; // for `app.oneshot()` use tower::ServiceExt; // for `app.oneshot()`

View File

@ -23,10 +23,9 @@ use std::{
sync::Arc, sync::Arc,
task::{Context, Poll}, task::{Context, Poll},
}; };
use tokio::net::{unix::UCred, UnixListener};
use tokio::{ use tokio::{
io::{AsyncRead, AsyncWrite}, io::{AsyncRead, AsyncWrite},
net::UnixStream, net::{unix::UCred, UnixListener, UnixStream},
}; };
use tower::BoxError; use tower::BoxError;
@ -150,6 +149,7 @@ impl Connection for ClientConnection {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[allow(dead_code)]
struct UdsConnectInfo { struct UdsConnectInfo {
peer_addr: Arc<tokio::net::unix::SocketAddr>, peer_addr: Arc<tokio::net::unix::SocketAddr>,
peer_cred: UCred, peer_cred: UCred,

View File

@ -13,8 +13,7 @@ use axum::{
routing::get, routing::get,
Router, Router,
}; };
use std::collections::HashMap; use std::{collections::HashMap, net::SocketAddr};
use std::net::SocketAddr;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {