From 75afb61153a698e431922ed9b74b341b976b48a9 Mon Sep 17 00:00:00 2001 From: Behrang Shafei <50267830+bertiqwerty@users.noreply.github.com> Date: Sun, 3 Sep 2023 16:04:17 +0200 Subject: [PATCH] clippy redundant closures in macros --- src/expression/partial.rs | 9 ++++----- src/value.rs | 17 ++++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/expression/partial.rs b/src/expression/partial.rs index 2e2df1e..ed7cb1e 100644 --- a/src/expression/partial.rs +++ b/src/expression/partial.rs @@ -197,7 +197,7 @@ where LM: MatchLiteral, ::Err: Debug, { - let factorexes = deepex + let mut factorexes = deepex .unary_op() .reprs .iter() @@ -214,10 +214,9 @@ where } unary_deri_op(new_deepex) }); - factorexes.fold( - Ok(DeepEx::one()), - |dp1, dp2| -> ExResult> { dp1? * dp2? }, - ) + factorexes.try_fold(DeepEx::one(), |dp1, dp2| -> ExResult> { + dp2.and_then(|dp2| dp2 * dp1) + }) } fn partial_derivative_inner<'a, T: NeutralElts + DataType + From, OF, LM>( diff --git a/src/value.rs b/src/value.rs index 7c5e445..84de964 100644 --- a/src/value.rs +++ b/src/value.rs @@ -228,7 +228,6 @@ base_arith!(add, checked_add); base_arith!(sub, checked_sub); base_arith!(mul, checked_mul); base_arith!(div, checked_div); - macro_rules! single_type_arith { ($name:ident, $variant:ident, $op:expr) => { fn $name(a: Val, b: Val) -> Val @@ -236,6 +235,8 @@ macro_rules! single_type_arith { I: DataType + PrimInt + Signed, F: DataType + Float, { + // https://github.com/rust-lang/rust-clippy/issues/11274 + #[allow(clippy::redundant_closure_call)] match (a, b) { (Val::$variant(na), Val::$variant(nb)) => $op(na, nb), _ => Val::Error(format_exerr!( @@ -320,8 +321,10 @@ macro_rules! unary_match_name { macro_rules! unary_match_op { ($name:ident, $scalar:ident, $(($ops:expr, $variants:ident)),+) => { + // https://github.com/rust-lang/rust-clippy/issues/11274 + #[allow(clippy::redundant_closure_call)] match $scalar { - $(Val::$variants(x) => $ops(x),)+ + $(Val::$variants(x) => $ops(x),)+ _ => Val::::Error(format_exerr!("did not expect {:?}", $scalar)), } }; @@ -387,13 +390,9 @@ unary_op!( Some(x) => x, None => return Val::Error(format_exerr!("cannot compute factorial of {:?}", a)), }; - let res = - (1usize..(a_usize_unpacked + 1usize)) - .map(I::from) - .fold(Some(I::one()), |a, b| match (a, b) { - (Some(a_), Some(b_)) => Some(a_ * b_), - _ => None, - }); + let res = (1usize..(a_usize_unpacked + 1usize)) + .map(I::from) + .try_fold(I::one(), |a, b| b.map(|b| a * b)); match res { Some(i) => Val::Int(i), None => Val::Error(format_exerr!("cannot compute factorial of {:?}", a)),