From 8dd2c7716551bf9d9346b8dda830dfcf8bc7af67 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 14 Jan 2020 13:31:20 +0900 Subject: [PATCH] Make the lint stricter (#20) * Make the lint stricter * Add explicit lifetimes * Allow `needless_doctest_main` --- src/extractors/basic.rs | 6 ++++-- src/extractors/bearer.rs | 6 ++++-- src/extractors/errors.rs | 2 +- src/headers/authorization/errors.rs | 2 +- src/headers/authorization/header.rs | 4 ++-- src/headers/authorization/scheme/basic.rs | 6 +++--- src/headers/authorization/scheme/bearer.rs | 6 +++--- src/headers/www_authenticate/challenge/basic.rs | 10 +++++----- .../www_authenticate/challenge/bearer/challenge.rs | 6 +++--- .../www_authenticate/challenge/bearer/errors.rs | 2 +- src/lib.rs | 3 +++ src/middleware.rs | 4 ++-- src/utils.rs | 2 +- 13 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/extractors/basic.rs b/src/extractors/basic.rs index 700568267..467be7f02 100644 --- a/src/extractors/basic.rs +++ b/src/extractors/basic.rs @@ -50,11 +50,13 @@ impl AuthExtractorConfig for Config { } } +// Needs `fn main` to display complete example. +#[allow(clippy::needless_doctest_main)] /// Extractor for HTTP Basic auth. /// /// # Example /// -/// ```rust +/// ``` /// use actix_web::Result; /// use actix_web_httpauth::extractors::basic::BasicAuth; /// @@ -69,7 +71,7 @@ impl AuthExtractorConfig for Config { /// /// ## Example /// -/// ```rust +/// ``` /// use actix_web::{web, App}; /// use actix_web_httpauth::extractors::basic::{BasicAuth, Config}; /// diff --git a/src/extractors/bearer.rs b/src/extractors/bearer.rs index 37788d70f..566e77b8d 100644 --- a/src/extractors/bearer.rs +++ b/src/extractors/bearer.rs @@ -54,11 +54,13 @@ impl AuthExtractorConfig for Config { } } +// Needs `fn main` to display complete example. +#[allow(clippy::needless_doctest_main)] /// Extractor for HTTP Bearer auth /// /// # Example /// -/// ```rust +/// ``` /// use actix_web_httpauth::extractors::bearer::BearerAuth; /// /// async fn index(auth: BearerAuth) -> String { @@ -72,7 +74,7 @@ impl AuthExtractorConfig for Config { /// /// ## Example /// -/// ```rust +/// ``` /// use actix_web::{web, App}; /// use actix_web_httpauth::extractors::bearer::{BearerAuth, Config}; /// diff --git a/src/extractors/errors.rs b/src/extractors/errors.rs index 1834f6b8a..c136d6617 100644 --- a/src/extractors/errors.rs +++ b/src/extractors/errors.rs @@ -43,7 +43,7 @@ impl AuthenticationError { } impl fmt::Display for AuthenticationError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.status_code, f) } } diff --git a/src/headers/authorization/errors.rs b/src/headers/authorization/errors.rs index 4de1b72ce..f2c620063 100644 --- a/src/headers/authorization/errors.rs +++ b/src/headers/authorization/errors.rs @@ -26,7 +26,7 @@ pub enum ParseError { } impl fmt::Display for ParseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let display = match self { ParseError::Invalid => "Invalid header value".to_string(), ParseError::MissingScheme => { diff --git a/src/headers/authorization/header.rs b/src/headers/authorization/header.rs index d6f051124..3fb9531d2 100644 --- a/src/headers/authorization/header.rs +++ b/src/headers/authorization/header.rs @@ -21,7 +21,7 @@ use crate::headers::authorization::scheme::Scheme; /// /// # Example /// -/// ```rust +/// ``` /// # use actix_web::http::header::Header; /// # use actix_web::{HttpRequest, Result}; /// # use actix_web_httpauth::headers::authorization::{Authorization, Basic}; @@ -98,7 +98,7 @@ impl IntoHeaderValue for Authorization { } impl fmt::Display for Authorization { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, f) } } diff --git a/src/headers/authorization/scheme/basic.rs b/src/headers/authorization/scheme/basic.rs index 0cea7e18b..107217ba3 100644 --- a/src/headers/authorization/scheme/basic.rs +++ b/src/headers/authorization/scheme/basic.rs @@ -24,7 +24,7 @@ impl Basic { /// /// ## Example /// - /// ```rust + /// ``` /// # use actix_web_httpauth::headers::authorization::Basic; /// let credentials = Basic::new("Alladin", Some("open sesame")); /// ``` @@ -89,13 +89,13 @@ impl Scheme for Basic { } impl fmt::Debug for Basic { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_fmt(format_args!("Basic {}:******", self.user_id)) } } impl fmt::Display for Basic { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_fmt(format_args!("Basic {}:******", self.user_id)) } } diff --git a/src/headers/authorization/scheme/bearer.rs b/src/headers/authorization/scheme/bearer.rs index a1bd3434f..ed52ee1b5 100644 --- a/src/headers/authorization/scheme/bearer.rs +++ b/src/headers/authorization/scheme/bearer.rs @@ -23,7 +23,7 @@ impl Bearer { /// /// ## Example /// - /// ```rust + /// ``` /// # use actix_web_httpauth::headers::authorization::Bearer; /// let credentials = Bearer::new("mF_9.B5f-4.1JqM"); /// ``` @@ -64,13 +64,13 @@ impl Scheme for Bearer { } impl fmt::Debug for Bearer { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_fmt(format_args!("Bearer ******")) } } impl fmt::Display for Bearer { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_fmt(format_args!("Bearer {}", self.token)) } } diff --git a/src/headers/www_authenticate/challenge/basic.rs b/src/headers/www_authenticate/challenge/basic.rs index a1d066590..1a01c965d 100644 --- a/src/headers/www_authenticate/challenge/basic.rs +++ b/src/headers/www_authenticate/challenge/basic.rs @@ -18,7 +18,7 @@ use crate::utils; /// /// ## Example /// -/// ```rust +/// ``` /// # use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer}; /// use actix_web_httpauth::headers::www_authenticate::basic::Basic; /// use actix_web_httpauth::headers::www_authenticate::WwwAuthenticate; @@ -44,7 +44,7 @@ impl Basic { /// /// ## Example /// - /// ```rust + /// ``` /// # use actix_web_httpauth::headers::www_authenticate::basic::Basic; /// let challenge = Basic::new(); /// ``` @@ -56,12 +56,12 @@ impl Basic { /// /// ## Examples /// - /// ```rust + /// ``` /// # use actix_web_httpauth::headers::www_authenticate::basic::Basic; /// let challenge = Basic::with_realm("Restricted area"); /// ``` /// - /// ```rust + /// ``` /// # use actix_web_httpauth::headers::www_authenticate::basic::Basic; /// let my_realm = "Earth realm".to_string(); /// let challenge = Basic::with_realm(my_realm); @@ -94,7 +94,7 @@ impl Challenge for Basic { } impl fmt::Display for Basic { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { let bytes = self.to_bytes(); let repr = str::from_utf8(&bytes) // Should not happen since challenges are crafted manually diff --git a/src/headers/www_authenticate/challenge/bearer/challenge.rs b/src/headers/www_authenticate/challenge/bearer/challenge.rs index d30883263..9207b59d0 100644 --- a/src/headers/www_authenticate/challenge/bearer/challenge.rs +++ b/src/headers/www_authenticate/challenge/bearer/challenge.rs @@ -16,7 +16,7 @@ use crate::utils; /// /// ## Example /// -/// ```rust +/// ``` /// # use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer}; /// use actix_web_httpauth::headers::www_authenticate::bearer::{ /// Bearer, Error, @@ -53,7 +53,7 @@ impl Bearer { /// /// ## Example /// - /// ```rust + /// ``` /// # use actix_web_httpauth::headers::www_authenticate::bearer::{Bearer}; /// let challenge = Bearer::build() /// .realm("Restricted area") @@ -121,7 +121,7 @@ impl Challenge for Bearer { } impl fmt::Display for Bearer { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { let bytes = self.to_bytes(); let repr = str::from_utf8(&bytes) // Should not happen since challenges are crafted manually diff --git a/src/headers/www_authenticate/challenge/bearer/errors.rs b/src/headers/www_authenticate/challenge/bearer/errors.rs index 7bea8d4a4..fb2f9a3dd 100644 --- a/src/headers/www_authenticate/challenge/bearer/errors.rs +++ b/src/headers/www_authenticate/challenge/bearer/errors.rs @@ -45,7 +45,7 @@ impl Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.as_str()) } } diff --git a/src/lib.rs b/src/lib.rs index 422eace13..2807fa07d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,10 @@ #![deny(bare_trait_objects)] #![deny(missing_docs)] +#![deny(nonstandard_style)] +#![deny(rust_2018_idioms)] #![deny(unused)] +#![deny(clippy::all)] #![cfg_attr(feature = "nightly", feature(test))] pub mod extractors; diff --git a/src/middleware.rs b/src/middleware.rs index 3ef8a9018..f0ce7fc28 100644 --- a/src/middleware.rs +++ b/src/middleware.rs @@ -59,7 +59,7 @@ where /// /// ## Example /// - /// ```rust + /// ``` /// # use actix_web::Error; /// # use actix_web::dev::ServiceRequest; /// # use actix_web_httpauth::middleware::HttpAuthentication; @@ -94,7 +94,7 @@ where /// /// ## Example /// - /// ```rust + /// ``` /// # use actix_web::Error; /// # use actix_web::dev::ServiceRequest; /// # use actix_web_httpauth::middleware::HttpAuthentication; diff --git a/src/utils.rs b/src/utils.rs index 2b5c6ac31..b9296b037 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,7 +13,7 @@ struct Quoted<'a> { } impl<'a> Quoted<'a> { - pub fn new(s: &'a str) -> Quoted { + pub fn new(s: &'a str) -> Quoted<'_> { Quoted { inner: s.split('"').peekable(), state: State::YieldStr,