apply new rustfmt.toml changes, fix some clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0317cc8cc5
commit
77e0b76408
296 changed files with 7147 additions and 4300 deletions
|
@ -42,14 +42,14 @@ fn dispatch_arm(v: &Variant) -> Result<TokenStream2> {
|
|||
let target = camel_to_snake_string(&format!("{name}"));
|
||||
let handler = Ident::new(&target, Span::call_site().into());
|
||||
let res = match &v.fields {
|
||||
Fields::Named(fields) => {
|
||||
| Fields::Named(fields) => {
|
||||
let field = fields.named.iter().filter_map(|f| f.ident.as_ref());
|
||||
let arg = field.clone();
|
||||
quote! {
|
||||
#name { #( #field ),* } => Box::pin(context.#handler(#( #arg ),*)).await?,
|
||||
}
|
||||
},
|
||||
Fields::Unnamed(fields) => {
|
||||
| Fields::Unnamed(fields) => {
|
||||
let Some(ref field) = fields.unnamed.first() else {
|
||||
return Err(Error::new(Span::call_site().into(), "One unnamed field required"));
|
||||
};
|
||||
|
@ -57,7 +57,7 @@ fn dispatch_arm(v: &Variant) -> Result<TokenStream2> {
|
|||
#name ( #field ) => Box::pin(#handler::process(#field, context)).await?,
|
||||
}
|
||||
},
|
||||
Fields::Unit => {
|
||||
| Fields::Unit => {
|
||||
quote! {
|
||||
#name => Box::pin(context.#handler()).await?,
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ use proc_macro::TokenStream;
|
|||
use proc_macro2::Span;
|
||||
use quote::ToTokens;
|
||||
use syn::{
|
||||
parse::Parser, punctuated::Punctuated, spanned::Spanned, Error, Expr, ExprLit, Field, Fields, FieldsNamed,
|
||||
ItemStruct, Lit, Meta, MetaList, MetaNameValue, Type, TypePath,
|
||||
parse::Parser, punctuated::Punctuated, spanned::Spanned, Error, Expr, ExprLit, Field, Fields,
|
||||
FieldsNamed, ItemStruct, Lit, Meta, MetaList, MetaNameValue, Type, TypePath,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -29,9 +29,9 @@ pub(super) fn example_generator(input: ItemStruct, args: &[Meta]) -> Result<Toke
|
|||
fn generate_example(input: &ItemStruct, args: &[Meta]) -> Result<()> {
|
||||
let settings = get_simple_settings(args);
|
||||
|
||||
let filename = settings
|
||||
.get("filename")
|
||||
.ok_or_else(|| Error::new(args[0].span(), "missing required 'filename' attribute argument"))?;
|
||||
let filename = settings.get("filename").ok_or_else(|| {
|
||||
Error::new(args[0].span(), "missing required 'filename' attribute argument")
|
||||
})?;
|
||||
|
||||
let undocumented = settings
|
||||
.get("undocumented")
|
||||
|
@ -43,9 +43,9 @@ fn generate_example(input: &ItemStruct, args: &[Meta]) -> Result<()> {
|
|||
.split(' ')
|
||||
.collect();
|
||||
|
||||
let section = settings
|
||||
.get("section")
|
||||
.ok_or_else(|| Error::new(args[0].span(), "missing required 'section' attribute argument"))?;
|
||||
let section = settings.get("section").ok_or_else(|| {
|
||||
Error::new(args[0].span(), "missing required 'section' attribute argument")
|
||||
})?;
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
|
@ -53,7 +53,12 @@ fn generate_example(input: &ItemStruct, args: &[Meta]) -> Result<()> {
|
|||
.truncate(section == "global")
|
||||
.append(section != "global")
|
||||
.open(filename)
|
||||
.map_err(|e| Error::new(Span::call_site(), format!("Failed to open config file for generation: {e}")))?;
|
||||
.map_err(|e| {
|
||||
Error::new(
|
||||
Span::call_site(),
|
||||
format!("Failed to open config file for generation: {e}"),
|
||||
)
|
||||
})?;
|
||||
|
||||
if let Some(header) = settings.get("header") {
|
||||
file.write_all(header.as_bytes())
|
||||
|
@ -63,11 +68,7 @@ fn generate_example(input: &ItemStruct, args: &[Meta]) -> Result<()> {
|
|||
file.write_fmt(format_args!("\n[{section}]\n"))
|
||||
.expect("written to config file");
|
||||
|
||||
if let Fields::Named(FieldsNamed {
|
||||
named,
|
||||
..
|
||||
}) = &input.fields
|
||||
{
|
||||
if let Fields::Named(FieldsNamed { named, .. }) = &input.fields {
|
||||
for field in named {
|
||||
let Some(ident) = &field.ident else {
|
||||
continue;
|
||||
|
@ -120,12 +121,7 @@ fn generate_example(input: &ItemStruct, args: &[Meta]) -> Result<()> {
|
|||
|
||||
fn get_default(field: &Field) -> Option<String> {
|
||||
for attr in &field.attrs {
|
||||
let Meta::List(MetaList {
|
||||
path,
|
||||
tokens,
|
||||
..
|
||||
}) = &attr.meta
|
||||
else {
|
||||
let Meta::List(MetaList { path, tokens, .. }) = &attr.meta else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -149,23 +145,18 @@ fn get_default(field: &Field) -> Option<String> {
|
|||
};
|
||||
|
||||
match arg {
|
||||
Meta::NameValue(MetaNameValue {
|
||||
value: Expr::Lit(ExprLit {
|
||||
lit: Lit::Str(str),
|
||||
..
|
||||
}),
|
||||
| Meta::NameValue(MetaNameValue {
|
||||
value: Expr::Lit(ExprLit { lit: Lit::Str(str), .. }),
|
||||
..
|
||||
}) => {
|
||||
match str.value().as_str() {
|
||||
"HashSet::new" | "Vec::new" | "RegexSet::empty" => Some("[]".to_owned()),
|
||||
"true_fn" => return Some("true".to_owned()),
|
||||
_ => return None,
|
||||
| "HashSet::new" | "Vec::new" | "RegexSet::empty" => Some("[]".to_owned()),
|
||||
| "true_fn" => return Some("true".to_owned()),
|
||||
| _ => return None,
|
||||
};
|
||||
},
|
||||
Meta::Path {
|
||||
..
|
||||
} => return Some("false".to_owned()),
|
||||
_ => return None,
|
||||
| Meta::Path { .. } => return Some("false".to_owned()),
|
||||
| _ => return None,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -174,12 +165,7 @@ fn get_default(field: &Field) -> Option<String> {
|
|||
|
||||
fn get_doc_default(field: &Field) -> Option<String> {
|
||||
for attr in &field.attrs {
|
||||
let Meta::NameValue(MetaNameValue {
|
||||
path,
|
||||
value,
|
||||
..
|
||||
}) = &attr.meta
|
||||
else {
|
||||
let Meta::NameValue(MetaNameValue { path, value, .. }) = &attr.meta else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -187,11 +173,7 @@ fn get_doc_default(field: &Field) -> Option<String> {
|
|||
continue;
|
||||
}
|
||||
|
||||
let Expr::Lit(ExprLit {
|
||||
lit,
|
||||
..
|
||||
}) = &value
|
||||
else {
|
||||
let Expr::Lit(ExprLit { lit, .. }) = &value else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -217,12 +199,7 @@ fn get_doc_default(field: &Field) -> Option<String> {
|
|||
fn get_doc_comment(field: &Field) -> Option<String> {
|
||||
let mut out = String::new();
|
||||
for attr in &field.attrs {
|
||||
let Meta::NameValue(MetaNameValue {
|
||||
path,
|
||||
value,
|
||||
..
|
||||
}) = &attr.meta
|
||||
else {
|
||||
let Meta::NameValue(MetaNameValue { path, value, .. }) = &attr.meta else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -230,11 +207,7 @@ fn get_doc_comment(field: &Field) -> Option<String> {
|
|||
continue;
|
||||
}
|
||||
|
||||
let Expr::Lit(ExprLit {
|
||||
lit,
|
||||
..
|
||||
}) = &value
|
||||
else {
|
||||
let Expr::Lit(ExprLit { lit, .. }) = &value else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -254,11 +227,7 @@ fn get_doc_comment(field: &Field) -> Option<String> {
|
|||
}
|
||||
|
||||
fn get_type_name(field: &Field) -> Option<String> {
|
||||
let Type::Path(TypePath {
|
||||
path,
|
||||
..
|
||||
}) = &field.ty
|
||||
else {
|
||||
let Type::Path(TypePath { path, .. }) = &field.ty else {
|
||||
return None;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,12 +20,15 @@ pub(super) fn implement(item: ItemFn, args: &[Meta]) -> Result<TokenStream> {
|
|||
}
|
||||
|
||||
fn get_receiver(args: &[Meta]) -> Result<Path> {
|
||||
let receiver = &args
|
||||
.first()
|
||||
.ok_or_else(|| Error::new(Span::call_site().into(), "Missing required argument to receiver"))?;
|
||||
let receiver = &args.first().ok_or_else(|| {
|
||||
Error::new(Span::call_site().into(), "Missing required argument to receiver")
|
||||
})?;
|
||||
|
||||
let Meta::Path(receiver) = receiver else {
|
||||
return Err(Error::new(Span::call_site().into(), "First argument is not path to receiver"));
|
||||
return Err(Error::new(
|
||||
Span::call_site().into(),
|
||||
"First argument is not path to receiver",
|
||||
));
|
||||
};
|
||||
|
||||
Ok(receiver.clone())
|
||||
|
|
|
@ -9,11 +9,7 @@ pub(super) fn refutable(mut item: ItemFn, _args: &[Meta]) -> Result<TokenStream>
|
|||
let stmt = &mut item.block.stmts;
|
||||
let sig = &mut item.sig;
|
||||
for (i, input) in inputs.iter().enumerate() {
|
||||
let Typed(PatType {
|
||||
pat,
|
||||
..
|
||||
}) = input
|
||||
else {
|
||||
let Typed(PatType { pat, .. }) = input else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -24,11 +20,7 @@ pub(super) fn refutable(mut item: ItemFn, _args: &[Meta]) -> Result<TokenStream>
|
|||
let variant = &pat.path;
|
||||
let fields = &pat.fields;
|
||||
|
||||
let Some(Typed(PatType {
|
||||
ref mut pat,
|
||||
..
|
||||
})) = sig.inputs.get_mut(i)
|
||||
else {
|
||||
let Some(Typed(PatType { ref mut pat, .. })) = sig.inputs.get_mut(i) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ use quote::quote;
|
|||
pub(super) fn flags_capture(args: TokenStream) -> TokenStream {
|
||||
let cargo_crate_name = std::env::var("CARGO_CRATE_NAME");
|
||||
let crate_name = match cargo_crate_name.as_ref() {
|
||||
Err(_) => return args,
|
||||
Ok(crate_name) => crate_name.trim_start_matches("conduwuit_"),
|
||||
| Err(_) => return args,
|
||||
| Ok(crate_name) => crate_name.trim_start_matches("conduwuit_"),
|
||||
};
|
||||
|
||||
let flag = std::env::args().collect::<Vec<_>>();
|
||||
|
|
|
@ -6,23 +6,11 @@ use crate::Result;
|
|||
|
||||
pub(crate) fn get_simple_settings(args: &[Meta]) -> HashMap<String, String> {
|
||||
args.iter().fold(HashMap::new(), |mut map, arg| {
|
||||
let Meta::NameValue(MetaNameValue {
|
||||
path,
|
||||
value,
|
||||
..
|
||||
}) = arg
|
||||
else {
|
||||
let Meta::NameValue(MetaNameValue { path, value, .. }) = arg else {
|
||||
return map;
|
||||
};
|
||||
|
||||
let Expr::Lit(
|
||||
ExprLit {
|
||||
lit: Lit::Str(str),
|
||||
..
|
||||
},
|
||||
..,
|
||||
) = value
|
||||
else {
|
||||
let Expr::Lit(ExprLit { lit: Lit::Str(str), .. }, ..) = value else {
|
||||
return map;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue