Skip to content

Commit

Permalink
Clippy & Fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
DanikVitek committed Feb 6, 2025
1 parent a226934 commit f645979
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 50 deletions.
20 changes: 7 additions & 13 deletions macros/src/async_generic_target/fn/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ pub trait Kind {
inputs
}

fn transform_variadic(
&mut self,
variadic: Option<Variadic>,
) -> Option<Variadic> {
fn transform_variadic(&mut self, variadic: Option<Variadic>) -> Option<Variadic> {
variadic
}

Expand Down Expand Up @@ -113,15 +110,12 @@ impl<const PRESERVE_IDENT: bool> Kind for Async<PRESERVE_IDENT> {
}
}

fn transform_variadic(
&mut self,
variadic: Option<Variadic>,
) -> Option<Variadic> {
if let Some(alt_variadic) = self.0.as_mut().and_then(|sig| {
sig.params
.as_mut()
.map(|params| params.variadic.take())
}) {
fn transform_variadic(&mut self, variadic: Option<Variadic>) -> Option<Variadic> {
if let Some(alt_variadic) = self
.0
.as_mut()
.and_then(|sig| sig.params.as_mut().map(|params| params.variadic.take()))
{
alt_variadic
} else {
variadic
Expand Down
6 changes: 3 additions & 3 deletions macros/src/async_generic_target/fn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ impl<const PRESERVE_IDENT: bool> CanSurround for kind::Async<PRESERVE_IDENT> {
}

fn visit_item(&mut self, _: &'ast Item) {
return;
// Do not recurse into items
}
}

Expand Down Expand Up @@ -701,7 +701,7 @@ struct IfAsyncRewriter<A>(PhantomData<A>);

impl<A> Clone for IfAsyncRewriter<A> {
fn clone(&self) -> Self {
Self(self.0)
*self
}
}

Expand Down Expand Up @@ -780,7 +780,7 @@ where
let Expr::Path(cond) = expr_if.cond.as_ref() else {
return;
};
if !cond.attrs.is_empty() || !cond.qself.is_none() {
if !cond.attrs.is_empty() || cond.qself.is_some() {
return;
}
let Some(ident) = cond.path.get_ident() else {
Expand Down
2 changes: 1 addition & 1 deletion macros/src/async_generic_target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
Ok(Args::from((async_signature, sync_signature)))
}

pub(self) fn parse_attrs(input: ParseStream) -> Result<Vec<Attribute>> {
fn parse_attrs(input: ParseStream) -> Result<Vec<Attribute>> {
let mut attrs = Vec::new();
while input.peek(Token![#]) {
let content;
Expand Down
2 changes: 1 addition & 1 deletion macros/src/async_generic_target/trait_part/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use super::{AsyncTrait, SyncTrait};

pub struct Sync<const SPLIT_FNS: bool>(pub(super) Option<SyncTrait>);

pub struct Async(pub(super) AsyncTrait);
pub struct Async(pub(super) AsyncTrait);
59 changes: 32 additions & 27 deletions macros/src/async_generic_target/trait_part/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ use syn::{
PathArguments, Token, TypeParamBound,
};

use super::{
parse_attrs, parse_in_order, r#fn,
r#fn::{AsyncGenericFn, TargetItemFn},
state, CanSetAttrs,
};
use super::{parse_attrs, parse_in_order, r#fn, r#fn::TargetItemFn, state, CanSetAttrs};
use crate::util::LetExt;

pub mod r#impl;
Expand Down Expand Up @@ -53,17 +49,20 @@ pub fn expand(target: impl Into<TargetTraitPart>, args: AsyncGenericArgs) -> Tok
.map(|res| res.into_token_stream())
.unwrap_or_else(|err| err.into_compile_error()),
Some(async_variant) => {
let sync_variant =
AsyncGenericTraitPart::new(target.clone(), kind::Sync::<false>(sync_variant))
let sync_variant = AsyncGenericTraitPart::new(
target.clone(),
kind::Sync::<false>(sync_variant),
)
.rewrite()
.map(|res| res.into_token_stream())
.unwrap_or_else(|err| err.into_compile_error());

let async_variant =
AsyncGenericTraitPart::new(target, kind::Async(async_variant))
.rewrite()
.map(|res| res.into_token_stream())
.unwrap_or_else(|err| err.into_compile_error());

let async_variant = AsyncGenericTraitPart::new(target, kind::Async(async_variant))
.rewrite()
.map(|res| res.into_token_stream())
.unwrap_or_else(|err| err.into_compile_error());

let mut tt = TokenStream2::new();
tt.extend([sync_variant, async_variant]);
tt
Expand Down Expand Up @@ -250,15 +249,15 @@ impl Parse for Options {
"expected at most one option, found multiple",
));
}
let copy_sync;
if idents.iter().any(|ident| **ident == "copy_sync") {
copy_sync = true;

let copy_sync = if idents.iter().any(|ident| **ident == "copy_sync") {
true
} else {
return Err(Error::new(
idents[0].span(),
"expected `copy_sync` as the only option",
));
}
};
Ok(Self { copy_sync })
}
}
Expand Down Expand Up @@ -323,7 +322,10 @@ pub trait TraitPart: Clone + ToTokens {
_ = path_args;
}

fn set_supertraits(&mut self, (colon_token, supertraits): (Token![:], Punctuated<TypeParamBound, Token![+]>)) {
fn set_supertraits(
&mut self,
(colon_token, supertraits): (Token![:], Punctuated<TypeParamBound, Token![+]>),
) {
let _ = colon_token;
let _ = supertraits;
}
Expand Down Expand Up @@ -399,10 +401,10 @@ where
}
};
let (
AsyncGenericFn {
r#fn::AsyncGenericFn {
target: sync_fn, ..
},
AsyncGenericFn {
r#fn::AsyncGenericFn {
target: async_fn, ..
},
) = super::r#fn::split::<false>(
Expand Down Expand Up @@ -470,9 +472,9 @@ where
return Ok(acc);
}
};
let AsyncGenericFn {
let r#fn::AsyncGenericFn {
target: sync_fn, ..
} = AsyncGenericFn::<r#fn::kind::Sync, state::Initial>::new(
} = r#fn::AsyncGenericFn::<r#fn::kind::Sync, state::Initial>::new(
trait_item_fn.into(),
async_generic_args.sync_signature,
)
Expand Down Expand Up @@ -540,9 +542,9 @@ where
}
};

let AsyncGenericFn {
let r#fn::AsyncGenericFn {
target: async_fn, ..
} = AsyncGenericFn::<r#fn::kind::Async<true>, state::Initial>::new(
} = r#fn::AsyncGenericFn::<r#fn::kind::Async<true>, state::Initial>::new(
trait_item_fn.into(),
async_generic_args.async_signature,
)
Expand All @@ -563,9 +565,12 @@ where
if let Some(supertraits) = self.kind.0.supertraits.take() {
self.target.set_supertraits(supertraits);
}
self.target.set_generics(core::mem::take(&mut self.kind.0.generics));
self.target.set_path_args(core::mem::take(&mut self.kind.0.path_args));
self.target.update_ident(|ident| Ident::new(&format!("{ident}Async"), ident.span()));
self.target
.set_generics(core::mem::take(&mut self.kind.0.generics));
self.target
.set_path_args(core::mem::take(&mut self.kind.0.path_args));
self.target
.update_ident(|ident| Ident::new(&format!("{ident}Async"), ident.span()));

Ok(AsyncGenericTraitPart {
target: self.target,
Expand Down Expand Up @@ -593,7 +598,7 @@ fn take_async_generic_args<T: HasAttributes>(
) -> Result<syn::Result<r#fn::AsyncGenericArgs>, ()> {
match &trait_item_fn.attrs()[i].meta {
Meta::Path(_) => {
trait_item_fn.remove_attr(i).meta;
trait_item_fn.remove_attr(i);
Ok(Ok(r#fn::AsyncGenericArgs::default()))
}
Meta::List(_) => {
Expand Down
5 changes: 1 addition & 4 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
use proc_macro::TokenStream;
use syn::parse_macro_input;

use crate::async_generic_target::{
r#fn,
trait_part, TargetItem,
};
use crate::async_generic_target::{r#fn, trait_part, TargetItem};

mod async_generic_target;
mod util;
Expand Down
3 changes: 2 additions & 1 deletion macros/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ macro_rules! test_expand {
};
}

pub(crate) use {local_assert_snapshot, test_expand};
pub(crate) use local_assert_snapshot;
pub(crate) use test_expand;

0 comments on commit f645979

Please sign in to comment.