Skip to content

Commit

Permalink
clippy redundant closures in macros
Browse files Browse the repository at this point in the history
  • Loading branch information
bertiqwerty committed Sep 3, 2023
1 parent 2add60e commit 75afb61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/expression/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ where
LM: MatchLiteral,
<T as FromStr>::Err: Debug,
{
let factorexes = deepex
let mut factorexes = deepex
.unary_op()
.reprs
.iter()
Expand All @@ -214,10 +214,9 @@ where
}
unary_deri_op(new_deepex)
});
factorexes.fold(
Ok(DeepEx::one()),
|dp1, dp2| -> ExResult<DeepEx<T, OF, LM>> { dp1? * dp2? },
)
factorexes.try_fold(DeepEx::one(), |dp1, dp2| -> ExResult<DeepEx<T, OF, LM>> {
dp2.and_then(|dp2| dp2 * dp1)
})
}

fn partial_derivative_inner<'a, T: NeutralElts + DataType + From<f32>, OF, LM>(
Expand Down
17 changes: 8 additions & 9 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,15 @@ 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<I, F>(a: Val<I, F>, b: Val<I, F>) -> Val<I, F>
where
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!(
Expand Down Expand Up @@ -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::<I, F>::Error(format_exerr!("did not expect {:?}", $scalar)),
}
};
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit 75afb61

Please sign in to comment.