Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ todo = "warn"
uninlined_format_args = "warn"
unnested_or_patterns = "warn"
unused_self = "warn"
use_self = "warn"
verbose_file_reads = "warn"

# configuration for https://github.com/crate-ci/typos
Expand Down
2 changes: 2 additions & 0 deletions axum-core/src/extract/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ where
{
type Rejection = T::Rejection;

#[allow(clippy::use_self)]
fn from_request_parts(
parts: &mut Parts,
state: &S,
Expand All @@ -57,6 +58,7 @@ where
{
type Rejection = T::Rejection;

#[allow(clippy::use_self)]
async fn from_request(req: Request, state: &S) -> Result<Option<T>, Self::Rejection> {
T::from_request(req, state).await
}
Expand Down
2 changes: 2 additions & 0 deletions axum-core/src/extract/request_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ where

async fn from_request(req: Request, _: &S) -> Result<Self, Self::Rejection> {
let mut body = req.into_limited_body();
#[allow(clippy::use_self)]
let mut bytes = BytesMut::new();
body_to_bytes_mut(&mut body, &mut bytes).await?;
Ok(bytes)
Expand Down Expand Up @@ -128,6 +129,7 @@ where
}
})?;

#[allow(clippy::use_self)]
let string = String::from_utf8(bytes.into()).map_err(InvalidUtf8::from_err)?;

Ok(string)
Expand Down
12 changes: 6 additions & 6 deletions axum-extra/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ where

fn layer(&self, inner: S) -> Self::Service {
match self {
Either::E1(layer) => Either::E1(layer.layer(inner)),
Either::E2(layer) => Either::E2(layer.layer(inner)),
Self::E1(layer) => Either::E1(layer.layer(inner)),
Self::E2(layer) => Either::E2(layer.layer(inner)),
}
}
}
Expand All @@ -300,15 +300,15 @@ where

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match self {
Either::E1(inner) => inner.poll_ready(cx),
Either::E2(inner) => inner.poll_ready(cx),
Self::E1(inner) => inner.poll_ready(cx),
Self::E2(inner) => inner.poll_ready(cx),
}
}

fn call(&mut self, req: R) -> Self::Future {
match self {
Either::E1(inner) => futures_util::future::Either::Left(inner.call(req)),
Either::E2(inner) => futures_util::future::Either::Right(inner.call(req)),
Self::E1(inner) => futures_util::future::Either::Left(inner.call(req)),
Self::E2(inner) => futures_util::future::Either::Right(inner.call(req)),
}
}
}
2 changes: 2 additions & 0 deletions axum-extra/src/extract/cookie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,14 @@ mod tests {
}

impl FromRef<AppState> for Key {
#[allow(clippy::use_self)]
fn from_ref(state: &AppState) -> Key {
state.key.clone()
}
}

impl FromRef<AppState> for CustomKey {
#[allow(clippy::use_self)]
fn from_ref(state: &AppState) -> CustomKey {
state.custom_key.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/extract/cookie/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ where
key,
_marker: _,
} = PrivateCookieJar::from_headers(&parts.headers, key);
Ok(PrivateCookieJar {
Ok(Self {
jar,
key,
_marker: PhantomData,
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/extract/cookie/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ where
key,
_marker: _,
} = SignedCookieJar::from_headers(&parts.headers, key);
Ok(SignedCookieJar {
Ok(Self {
jar,
key,
_marker: PhantomData,
Expand Down
10 changes: 5 additions & 5 deletions axum-extra/src/extract/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where

async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
parts
.extract::<Option<Host>>()
.extract::<Option<Self>>()
.await
.ok()
.flatten()
Expand All @@ -55,27 +55,27 @@ where
_state: &S,
) -> Result<Option<Self>, Self::Rejection> {
if let Some(host) = parse_forwarded(&parts.headers) {
return Ok(Some(Host(host.to_owned())));
return Ok(Some(Self(host.to_owned())));
}

if let Some(host) = parts
.headers
.get(X_FORWARDED_HOST_HEADER_KEY)
.and_then(|host| host.to_str().ok())
{
return Ok(Some(Host(host.to_owned())));
return Ok(Some(Self(host.to_owned())));
}

if let Some(host) = parts
.headers
.get(http::header::HOST)
.and_then(|host| host.to_str().ok())
{
return Ok(Some(Host(host.to_owned())));
return Ok(Some(Self(host.to_owned())));
}

if let Some(authority) = parts.uri.authority() {
return Ok(Some(Host(parse_authority(authority).to_owned())));
return Ok(Some(Self(parse_authority(authority).to_owned())));
}

Ok(None)
Expand Down
6 changes: 3 additions & 3 deletions axum-extra/src/extract/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where
serde_html_form::Deserializer::new(form_urlencoded::parse(query.as_bytes()));
let value = serde_path_to_error::deserialize(deserializer)
.map_err(FailedToDeserializeQueryString::from_err)?;
Ok(Query(value))
Ok(Self(value))
}
}

Expand Down Expand Up @@ -170,9 +170,9 @@ where
serde_html_form::Deserializer::new(form_urlencoded::parse(query.as_bytes()));
let value = serde_path_to_error::deserialize(deserializer)
.map_err(FailedToDeserializeQueryString::from_err)?;
Ok(OptionalQuery(Some(value)))
Ok(Self(Some(value)))
} else {
Ok(OptionalQuery(None))
Ok(Self(None))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions axum-extra/src/extract/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
// Within Forwarded header
if let Some(scheme) = parse_forwarded(&parts.headers) {
return Ok(Scheme(scheme.to_owned()));
return Ok(Self(scheme.to_owned()));
}

// X-Forwarded-Proto
Expand All @@ -47,12 +47,12 @@ where
.get(X_FORWARDED_PROTO_HEADER_KEY)
.and_then(|scheme| scheme.to_str().ok())
{
return Ok(Scheme(scheme.to_owned()));
return Ok(Self(scheme.to_owned()));
}

// From parts of an HTTP/2 request
if let Some(scheme) = parts.uri.scheme_str() {
return Ok(Scheme(scheme.to_owned()));
return Ok(Self(scheme.to_owned()));
}

Err(SchemeMissing)
Expand Down
6 changes: 3 additions & 3 deletions axum-extra/src/extract/with_rejection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ where

async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
let extractor = E::from_request(req, state).await?;
Ok(WithRejection(extractor, PhantomData))
Ok(Self(extractor, PhantomData))
}
}

Expand All @@ -133,7 +133,7 @@ where

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let extractor = E::from_request_parts(parts, state).await?;
Ok(WithRejection(extractor, PhantomData))
Ok(Self(extractor, PhantomData))
}
}

Expand Down Expand Up @@ -188,7 +188,7 @@ mod tests {

impl From<()> for TestRejection {
fn from(_: ()) -> Self {
TestRejection
Self
}
}

Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ where
.aggregate();

match T::decode(&mut buf) {
Ok(value) => Ok(Protobuf(value)),
Ok(value) => Ok(Self(value)),
Err(err) => Err(ProtobufDecodeError::from_err(err).into()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/response/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl MultipartForm {
/// let form = MultipartForm::with_parts(parts);
/// ```
pub fn with_parts(parts: Vec<Part>) -> Self {
MultipartForm { parts }
Self { parts }
}
}

Expand Down
8 changes: 4 additions & 4 deletions axum-macros/src/debug_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ pub(crate) enum FunctionKind {
impl fmt::Display for FunctionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FunctionKind::Handler => f.write_str("handler"),
FunctionKind::Middleware => f.write_str("middleware"),
Self::Handler => f.write_str("handler"),
Self::Middleware => f.write_str("middleware"),
}
}
}

impl FunctionKind {
fn name_uppercase_plural(&self) -> &'static str {
match self {
FunctionKind::Handler => "Handlers",
FunctionKind::Middleware => "Middleware",
Self::Handler => "Handlers",
Self::Middleware => "Middleware",
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions axum-macros/src/from_request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ pub(crate) enum Trait {
impl Trait {
fn via_marker_type(&self) -> Option<Type> {
match self {
Trait::FromRequest => Some(parse_quote!(M)),
Trait::FromRequestParts => None,
Self::FromRequest => Some(parse_quote!(M)),
Self::FromRequestParts => None,
}
}
}

impl fmt::Display for Trait {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Trait::FromRequest => f.write_str("FromRequest"),
Trait::FromRequestParts => f.write_str("FromRequestParts"),
Self::FromRequest => f.write_str("FromRequest"),
Self::FromRequestParts => f.write_str("FromRequestParts"),
}
}
}
Expand All @@ -50,9 +50,9 @@ impl State {
/// ```
fn impl_generics(&self) -> impl Iterator<Item = Type> {
match self {
State::Default(inner) => Some(inner.clone()),
State::Custom(_) => None,
State::CannotInfer => Some(parse_quote!(S)),
Self::Default(inner) => Some(inner.clone()),
Self::Custom(_) => None,
Self::CannotInfer => Some(parse_quote!(S)),
}
.into_iter()
}
Expand All @@ -63,18 +63,18 @@ impl State {
/// ```
fn trait_generics(&self) -> impl Iterator<Item = Type> {
match self {
State::Default(inner) | State::Custom(inner) => iter::once(inner.clone()),
State::CannotInfer => iter::once(parse_quote!(S)),
Self::Default(inner) | Self::Custom(inner) => iter::once(inner.clone()),
Self::CannotInfer => iter::once(parse_quote!(S)),
}
}

fn bounds(&self) -> TokenStream {
match self {
State::Custom(_) => quote! {},
State::Default(inner) => quote! {
Self::Custom(_) => quote! {},
Self::Default(inner) => quote! {
#inner: ::std::marker::Send + ::std::marker::Sync,
},
State::CannotInfer => quote! {
Self::CannotInfer => quote! {
S: ::std::marker::Send + ::std::marker::Sync,
},
}
Expand All @@ -84,8 +84,8 @@ impl State {
impl ToTokens for State {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
State::Custom(inner) | State::Default(inner) => inner.to_tokens(tokens),
State::CannotInfer => quote! { S }.to_tokens(tokens),
Self::Custom(inner) | Self::Default(inner) => inner.to_tokens(tokens),
Self::CannotInfer => quote! { S }.to_tokens(tokens),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions axum-macros/src/with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl<I> WithPosition<I>
where
I: Iterator,
{
pub(crate) fn new(iter: impl IntoIterator<IntoIter = I>) -> WithPosition<I> {
WithPosition {
pub(crate) fn new(iter: impl IntoIterator<IntoIter = I>) -> Self {
Self {
handled_first: false,
peekable: iter.into_iter().fuse().peekable(),
}
Expand Down Expand Up @@ -72,7 +72,7 @@ pub(crate) enum Position<T> {
impl<T> Position<T> {
pub(crate) fn into_inner(self) -> T {
match self {
Position::First(x) | Position::Middle(x) | Position::Last(x) | Position::Only(x) => x,
Self::First(x) | Self::Middle(x) | Self::Last(x) | Self::Only(x) => x,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions axum/src/extract/connect_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const _: () = {
}
};

#[allow(clippy::use_self)]
impl Connected<SocketAddr> for SocketAddr {
fn connect_info(remote_addr: SocketAddr) -> Self {
remote_addr
Expand Down
2 changes: 1 addition & 1 deletion axum/src/extract/original_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let uri = Extension::<Self>::from_request_parts(parts, state)
.await
.unwrap_or_else(|_| Extension(OriginalUri(parts.uri.clone())))
.unwrap_or_else(|_| Extension(Self(parts.uri.clone())))
.0;
Ok(uri)
}
Expand Down
Loading
Loading