Skip to content

Commit 1d09365

Browse files
committed
decimal: Allow suspicious arithmetic impl for + in Mul
It's understandable that Clippy would think that the addition was incorrct here, but it's correct since we're already doing a multiplication in the digits operator. The addition is in the index operator.
1 parent c208bac commit 1d09365

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

exercises/decimal/example.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ impl Decimal {
101101
}
102102

103103
macro_rules! auto_impl_decimal_ops {
104-
($trait:ident, $func_name:ident, $digits_operation:expr, $index_operation:expr) => {
104+
($(#[$attr:meta])* $trait:ident, $func_name:ident, $digits_operation:expr, $index_operation:expr) => {
105105
impl $trait for Decimal {
106106
type Output = Self;
107+
$(#[$attr])*
107108
fn $func_name(mut self, mut rhs: Self) -> Self {
108109
Decimal::equalize_precision(&mut self, &mut rhs);
109110
Decimal::new(
@@ -117,7 +118,7 @@ macro_rules! auto_impl_decimal_ops {
117118

118119
auto_impl_decimal_ops!(Add, add, |s, o| s + o, |s, _| s);
119120
auto_impl_decimal_ops!(Sub, sub, |s, o| s - o, |s, _| s);
120-
auto_impl_decimal_ops!(Mul, mul, |s, o| s * o, |s, o| s + o);
121+
auto_impl_decimal_ops!(#[allow(clippy::suspicious_arithmetic_impl)] Mul, mul, |s, o| s * o, |s, o| s + o);
121122

122123
macro_rules! auto_impl_decimal_cow {
123124
($trait:ident, $func_name:ident, $digits_operation:expr, $return_type:ty) => {

0 commit comments

Comments
 (0)