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-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
profile: minimal
components: clippy
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v1
- name: Check
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::verbose_file_reads,
clippy::unnested_or_patterns,
clippy::self_named_module_files,
rust_2018_idioms,
future_incompatible,
nonstandard_style,

View File

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

View File

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

View File

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

View File

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

View File

@ -3,8 +3,7 @@
//! See [`extractor_middleware`] for more details.
use super::{FromRequest, RequestParts};
use crate::BoxError;
use crate::{body::BoxBody, response::IntoResponse};
use crate::{body::BoxBody, response::IntoResponse, BoxError};
use bytes::Bytes;
use futures_util::{future::BoxFuture, ready};
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)]
mod tests {
use crate::test_helpers::*;
use crate::{routing::get, Router};
use crate::{routing::get, test_helpers::*, Router};
#[tokio::test]
async fn consume_body() {

View File

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

View File

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

View File

@ -131,7 +131,8 @@ impl WebSocketUpgrade {
/// Set the known protocols.
///
/// 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
///

View File

@ -64,9 +64,9 @@ where
#[inline]
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
// `Layered` which bufferes in `<Layered as Handler>::call` and is therefore also always
// ready.
// `IntoService` can only be constructed from async functions which are always ready, or
// from `Layered` which bufferes in `<Layered as Handler>::call` and is therefore
// also always ready.
Poll::Ready(Ok(()))
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -107,15 +107,14 @@ use futures_util::ready;
use http::{Method, Request, Response};
use http_body::Empty;
use pin_project_lite::pin_project;
use std::marker::PhantomData;
use std::{
fmt,
future::Future,
marker::PhantomData,
pin::Pin,
task::{Context, Poll},
};
use tower::util::Oneshot;
use tower::ServiceExt as _;
use tower::{util::Oneshot, ServiceExt as _};
use tower_service::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::{
error_handling::HandleErrorLayer,
extract::{self, Path},
handler::Handler,
response::IntoResponse,
routing::{any, delete, get, on, patch, post, service_method_routing as service, MethodFilter},
Json, Router,
test_helpers::*,
BoxError, Json, Router,
};
use bytes::Bytes;
use http::{header::HeaderMap, Method, Request, Response, StatusCode, Uri};
use hyper::Body;
use serde::Deserialize;
use serde_json::{json, Value};
use std::future::Ready;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{
convert::Infallible,
future::ready,
future::{ready, Ready},
sync::atomic::{AtomicUsize, Ordering},
task::{Context, Poll},
time::Duration,
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -148,6 +148,7 @@ async fn logout(
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct AuthRequest {
code: 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
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct Params {
#[serde(default, deserialize_with = "empty_string_as_none")]
foo: Option<String>,

View File

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

View File

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

View File

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