diff --git a/core/src/ast.rs b/core/src/ast.rs index 9d590af5..1a9c22a7 100644 --- a/core/src/ast.rs +++ b/core/src/ast.rs @@ -509,7 +509,7 @@ pub(crate) fn evaluate( } Expr::Equality(is_equals, a, b) => { let lhs = evaluate(*a, scope.clone(), attrs, context, int)?; - let rhs = evaluate(*b, scope.clone(), attrs, context, int)?; + let rhs = evaluate(*b, scope, attrs, context, int)?; Value::Bool(match lhs.compare(&rhs, int)? { Some(cmp::Ordering::Equal) => is_equals, Some(cmp::Ordering::Greater | cmp::Ordering::Less) | None => !is_equals, diff --git a/core/src/date.rs b/core/src/date.rs index 72676345..0aafc052 100644 --- a/core/src/date.rs +++ b/core/src/date.rs @@ -21,7 +21,7 @@ pub(crate) struct Date { } impl Date { - pub(crate) fn today(context: &mut crate::Context) -> FResult { + pub(crate) fn today(context: &crate::Context) -> FResult { let Some(current_time_info) = &context.current_time else { return Err(FendError::UnableToGetCurrentDate); }; diff --git a/core/src/eval.rs b/core/src/eval.rs index 80366835..7a97a5d1 100644 --- a/core/src/eval.rs +++ b/core/src/eval.rs @@ -16,7 +16,7 @@ pub(crate) fn evaluate_to_value( let mut missing_open_parens: i32 = 0; for token in lex { let token = token?; - if let lexer::Token::Symbol(lexer::Symbol::CloseParens) = token { + if matches!(token, lexer::Token::Symbol(lexer::Symbol::CloseParens)) { missing_open_parens += 1; } tokens.push(token); diff --git a/core/src/lexer.rs b/core/src/lexer.rs index 884c1e99..b365b1d3 100644 --- a/core/src/lexer.rs +++ b/core/src/lexer.rs @@ -845,7 +845,7 @@ impl<'a, I: Interrupt> Iterator for Lexer<'a, '_, I> { res, Some(Ok(Token::Num(_) | Token::Symbol(Symbol::UnitConversion))) ); - if let Some(Ok(Token::Symbol(Symbol::Backslash))) = res { + if matches!(res, Some(Ok(Token::Symbol(Symbol::Backslash)))) { self.after_backslash_state = 1; } else if self.after_backslash_state == 1 { if let Some(Ok(Token::Ident(_))) = res { diff --git a/core/src/num/complex.rs b/core/src/num/complex.rs index 8f666e4e..68462596 100644 --- a/core/src/num/complex.rs +++ b/core/src/num/complex.rs @@ -144,7 +144,7 @@ impl Complex { let rem = rhs.clone().real.modulo(4.into(), int); // Reduced case: (ix)^y = x^y * i^y if self.real.is_zero() && rhs.imag.is_zero() { - if let Ok(n) = rhs.real.clone().try_as_usize(int) { + if let Ok(n) = rhs.real.try_as_usize(int) { return self.pow_n(n, int); } @@ -380,8 +380,7 @@ impl Complex { let sqrt = Exact::new(Self::from(1), true) .add(exact.clone().mul(&exact, int)?.neg(), int)? .try_and_then(|x| x.frac_pow(half.value, int))?; - i.clone() - .mul(&exact, int)? + i.mul(&exact, int)? .add(sqrt, int)? .try_and_then(|x| x.ln(int)) } diff --git a/core/src/num/continued_fraction.rs b/core/src/num/continued_fraction.rs index 59d8586b..755a78ea 100644 --- a/core/src/num/continued_fraction.rs +++ b/core/src/num/continued_fraction.rs @@ -61,7 +61,7 @@ impl ContinuedFraction { let mut denominator = 1.0; for term in self.into_iter().take(MAX_ITERATIONS) { denominator = 1.0 / (denominator + term.as_f64()); - result = result * denominator + term.as_f64(); + result = result.mul_add(denominator, term.as_f64()); } result } @@ -404,17 +404,11 @@ impl Iterator for BihomographicIterator { } BihomographicState::Shift { right_first } => { if right_first { - if let Ok(()) = self.shift_right() { - self.state = BihomographicState::Initial; - continue; - } else if let Ok(()) = self.shift_down() { + if self.shift_right() == Ok(()) || self.shift_down() == Ok(()) { self.state = BihomographicState::Initial; continue; } - } else if let Ok(()) = self.shift_down() { - self.state = BihomographicState::Initial; - continue; - } else if let Ok(()) = self.shift_right() { + } else if self.shift_down() == Ok(()) || self.shift_right() == Ok(()) { self.state = BihomographicState::Initial; continue; } @@ -807,8 +801,7 @@ mod tests { .take(1000) .map(|b| b.try_as_usize(&Never).unwrap()) .collect::>(), - Some(1) - .into_iter() + iter::once(1) .chain([2, 1, 1, 2, 36].into_iter().cycle()) .take(1000) .collect::>(), diff --git a/core/src/units.rs b/core/src/units.rs index c693d95a..784fc83c 100644 --- a/core/src/units.rs +++ b/core/src/units.rs @@ -237,7 +237,7 @@ fn query_unit_internal( short_prefixes: bool, case_sensitive: bool, whole_unit: bool, - context: &mut crate::Context, + context: &crate::Context, ) -> FResult<(Cow<'static, str>, Cow<'static, str>, Cow<'static, str>)> { if !short_prefixes { for (s, p, d) in &context.custom_units { diff --git a/core/src/value.rs b/core/src/value.rs index b7117005..ffb0ec29 100644 --- a/core/src/value.rs +++ b/core/src/value.rs @@ -278,11 +278,11 @@ impl Value { Ok(match self { Self::Num(n) => { let other = crate::ast::evaluate(other, scope.clone(), attrs, context, int)?; - if let Self::Dp = other { + if matches!(other, Self::Dp) { let num = Self::Num(n).expect_num()?.try_as_usize(int)?; return Ok(Self::Format(FormattingStyle::DecimalPlaces(num))); } - if let Self::Sf = other { + if matches!(other, Self::Sf) { let num = Self::Num(n).expect_num()?.try_as_usize(int)?; if num == 0 { return Err(FendError::CannotFormatWithZeroSf);