fix(clippy): follow the advice

This commit is contained in:
zjp 2022-08-22 00:57:09 +08:00
parent 70b0340b81
commit 0d7066c554
3 changed files with 13 additions and 17 deletions

View file

@ -55,10 +55,10 @@ impl syn::parse::Parse for Args {
} }
fn find_storage_field(input: &syn::ItemStruct) -> Result<syn::Ident, &'static str> { fn find_storage_field(input: &syn::ItemStruct) -> Result<syn::Ident, &'static str> {
let storage = format!("storage"); let storage = "storage";
for field in input.fields.iter() { for field in input.fields.iter() {
if let Some(i) = &field.ident { if let Some(i) = &field.ident {
if i.to_string() == storage { if i == storage {
return Ok(i.clone()); return Ok(i.clone());
} }
} else { } else {

View file

@ -12,7 +12,7 @@ pub(crate) fn tracked(
let args = syn::parse_macro_input!(args as Args); let args = syn::parse_macro_input!(args as Args);
match tracked_fn(args, item_fn) { match tracked_fn(args, item_fn) {
Ok(p) => p.into(), Ok(p) => p.into(),
Err(e) => return e.into_compile_error().into(), Err(e) => e.into_compile_error().into(),
} }
} }
@ -145,7 +145,7 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration {
let fn_ty = item_fn.sig.ident.clone(); let fn_ty = item_fn.sig.ident.clone();
let indices = (0..item_fn.sig.inputs.len() - 1).map(|i| Literal::usize_unsuffixed(i)); let indices = (0..item_fn.sig.inputs.len() - 1).map(Literal::usize_unsuffixed);
let (cycle_strategy, recover_fn) = if let Some(recovery_fn) = &args.recovery_fn { let (cycle_strategy, recover_fn) = if let Some(recovery_fn) = &args.recovery_fn {
// Create the `recover_from_cycle` function, which (a) maps from the interned id to the actual // Create the `recover_from_cycle` function, which (a) maps from the interned id to the actual
// keys and then (b) invokes the recover function itself. // keys and then (b) invokes the recover function itself.
@ -181,7 +181,7 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration {
// Create the `execute` function, which (a) maps from the interned id to the actual // Create the `execute` function, which (a) maps from the interned id to the actual
// keys and then (b) invokes the function itself (which we embed within). // keys and then (b) invokes the function itself (which we embed within).
let indices = (0..item_fn.sig.inputs.len() - 1).map(|i| Literal::usize_unsuffixed(i)); let indices = (0..item_fn.sig.inputs.len() - 1).map(Literal::usize_unsuffixed);
let execute_fn = parse_quote! { let execute_fn = parse_quote! {
fn execute(__db: &salsa::function::DynDb<Self>, __id: Self::Key) -> Self::Value { fn execute(__db: &salsa::function::DynDb<Self>, __id: Self::Key) -> Self::Value {
#inner_fn #inner_fn
@ -487,9 +487,7 @@ fn make_fn_return_ref(mut ref_getter_fn: syn::ItemFn) -> syn::Result<syn::ItemFn
/// then modifies the item function so that it is called `'__db` and returns that. /// then modifies the item function so that it is called `'__db` and returns that.
fn db_lifetime_and_ty(func: &mut syn::ItemFn) -> syn::Result<(syn::Lifetime, &syn::Type)> { fn db_lifetime_and_ty(func: &mut syn::ItemFn) -> syn::Result<(syn::Lifetime, &syn::Type)> {
match &mut func.sig.inputs[0] { match &mut func.sig.inputs[0] {
syn::FnArg::Receiver(r) => { syn::FnArg::Receiver(r) => Err(syn::Error::new(r.span(), "expected database, not self")),
return Err(syn::Error::new(r.span(), "expected database, not self"))
}
syn::FnArg::Typed(pat_ty) => match &mut *pat_ty.ty { syn::FnArg::Typed(pat_ty) => match &mut *pat_ty.ty {
syn::Type::Reference(ty) => match &ty.lifetime { syn::Type::Reference(ty) => match &ty.lifetime {
Some(lt) => Ok((lt.clone(), &pat_ty.ty)), Some(lt) => Ok((lt.clone(), &pat_ty.ty)),
@ -517,12 +515,10 @@ fn db_lifetime_and_ty(func: &mut syn::ItemFn) -> syn::Result<(syn::Lifetime, &sy
Ok((db_lifetime, &pat_ty.ty)) Ok((db_lifetime, &pat_ty.ty))
} }
}, },
_ => { _ => Err(syn::Error::new(
return Err(syn::Error::new( pat_ty.span(),
pat_ty.span(), "expected database to be a `&` type",
"expected database to be a `&` type", )),
))
}
}, },
} }
} }
@ -574,7 +570,7 @@ fn accumulated_fn(
/// * the name(s) of the key arguments /// * the name(s) of the key arguments
fn fn_args(item_fn: &syn::ItemFn) -> syn::Result<(proc_macro2::Ident, Vec<proc_macro2::Ident>)> { fn fn_args(item_fn: &syn::ItemFn) -> syn::Result<(proc_macro2::Ident, Vec<proc_macro2::Ident>)> {
// Check that we have no receiver and that all argments have names // Check that we have no receiver and that all argments have names
if item_fn.sig.inputs.len() == 0 { if item_fn.sig.inputs.is_empty() {
return Err(syn::Error::new( return Err(syn::Error::new(
item_fn.sig.span(), item_fn.sig.span(),
"method needs a database argument", "method needs a database argument",

View file

@ -279,14 +279,14 @@ impl TrackedStruct {
/// of the function ingredients within that tuple. /// of the function ingredients within that tuple.
fn value_field_indices(&self) -> Vec<Literal> { fn value_field_indices(&self) -> Vec<Literal> {
(0..self.value_fields().count()) (0..self.value_fields().count())
.map(|i| Literal::usize_unsuffixed(i)) .map(Literal::usize_unsuffixed)
.collect() .collect()
} }
/// Indices of each of the id fields /// Indices of each of the id fields
fn id_field_indices(&self) -> Vec<Literal> { fn id_field_indices(&self) -> Vec<Literal> {
(0..self.id_fields().count()) (0..self.id_fields().count())
.map(|i| Literal::usize_unsuffixed(i)) .map(Literal::usize_unsuffixed)
.collect() .collect()
} }
} }