From 74f01d2538123616b05e9eb58934c35cdd50b4dc Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 25 Oct 2020 18:23:24 +0100 Subject: [PATCH 1/2] clippy: fix suspicious_arithmetic_impl errors (false positives) --- src/geometry/isometry_ops.rs | 26 ++++--- src/geometry/quaternion_ops.rs | 124 ++++++++++++++----------------- src/geometry/rotation_ops.rs | 16 ++-- src/geometry/similarity_ops.rs | 43 +++++------ src/geometry/transform_ops.rs | 57 +++++++------- src/geometry/translation_ops.rs | 110 +++++++-------------------- src/geometry/unit_complex_ops.rs | 8 +- 7 files changed, 162 insertions(+), 222 deletions(-) diff --git a/src/geometry/isometry_ops.rs b/src/geometry/isometry_ops.rs index 8b00fcda..e676d492 100644 --- a/src/geometry/isometry_ops.rs +++ b/src/geometry/isometry_ops.rs @@ -149,6 +149,7 @@ isometry_binop_impl_all!( [ref ref] => { let shift = self.rotation.transform_vector(&rhs.translation.vector); + #[allow(clippy::suspicious_arithmetic_impl)] Isometry::from_parts(Translation::from(&self.translation.vector + shift), self.rotation.clone() * rhs.rotation.clone()) // FIXME: too bad we have to clone. }; @@ -157,10 +158,10 @@ isometry_binop_impl_all!( isometry_binop_impl_all!( Div, div; self: Isometry, rhs: Isometry, Output = Isometry; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.inverse(); - [ref ref] => self * rhs.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; ); // Isometry ×= Translation @@ -289,6 +290,7 @@ isometry_binop_impl_all!( [ref val] => self * &right; [val ref] => &self * right; [ref ref] => { + #[allow(clippy::suspicious_arithmetic_impl)] let new_tr = &self.translation.vector + self.rotation.transform_vector(&right.vector); Isometry::from_parts(Translation::from(new_tr), self.rotation.clone()) }; @@ -427,10 +429,10 @@ isometry_from_composition_impl_all!( self: Rotation, right: Isometry>, Output = Isometry>; // FIXME: don't call inverse explicitly? - [val val] => self * right.inverse(); - [ref val] => self * right.inverse(); - [val ref] => self * right.inverse(); - [ref ref] => self * right.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; ); // Isometry × UnitQuaternion @@ -479,10 +481,10 @@ isometry_from_composition_impl_all!( self: UnitQuaternion, right: Isometry>, Output = Isometry>; // FIXME: don't call inverse explicitly? - [val val] => self * right.inverse(); - [ref val] => self * right.inverse(); - [val ref] => self * right.inverse(); - [ref ref] => self * right.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; ); // Translation × Rotation diff --git a/src/geometry/quaternion_ops.rs b/src/geometry/quaternion_ops.rs index e18c1b16..d91d7fd8 100644 --- a/src/geometry/quaternion_ops.rs +++ b/src/geometry/quaternion_ops.rs @@ -121,11 +121,10 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Add, add; -(U4, U1), (U4, U1); -self: Quaternion, rhs: Quaternion, Output = Quaternion; -Quaternion::from(self.coords + rhs.coords); -); + Add, add; + (U4, U1), (U4, U1); + self: Quaternion, rhs: Quaternion, Output = Quaternion; + Quaternion::from(self.coords + rhs.coords); ); // Quaternion - Quaternion quaternion_op_impl!( @@ -150,11 +149,10 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Sub, sub; -(U4, U1), (U4, U1); -self: Quaternion, rhs: Quaternion, Output = Quaternion; -Quaternion::from(self.coords - rhs.coords); -); + Sub, sub; + (U4, U1), (U4, U1); + self: Quaternion, rhs: Quaternion, Output = Quaternion; + Quaternion::from(self.coords - rhs.coords); ); // Quaternion × Quaternion quaternion_op_impl!( @@ -183,11 +181,10 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Mul, mul; -(U4, U1), (U4, U1); -self: Quaternion, rhs: Quaternion, Output = Quaternion; -&self * &rhs; -); + Mul, mul; + (U4, U1), (U4, U1); + self: Quaternion, rhs: Quaternion, Output = Quaternion; + &self * &rhs; ); // UnitQuaternion × UnitQuaternion quaternion_op_impl!( @@ -212,18 +209,17 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Mul, mul; -(U4, U1), (U4, U1); -self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; -&self * &rhs; -); + Mul, mul; + (U4, U1), (U4, U1); + self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; + &self * &rhs; ); // UnitQuaternion ÷ UnitQuaternion quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); self: &'a UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; - self * rhs.inverse(); + #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; 'a, 'b); quaternion_op_impl!( @@ -241,11 +237,10 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Div, div; -(U4, U1), (U4, U1); -self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; -&self / &rhs; -); + Div, div; + (U4, U1), (U4, U1); + self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; + &self / &rhs; ); // UnitQuaternion × Rotation quaternion_op_impl!( @@ -274,12 +269,11 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Mul, mul; -(U4, U1), (U3, U3); -self: UnitQuaternion, rhs: Rotation, -Output = UnitQuaternion => U3, U3; -self * UnitQuaternion::::from_rotation_matrix(&rhs); -); + Mul, mul; + (U4, U1), (U3, U3); + self: UnitQuaternion, rhs: Rotation, + Output = UnitQuaternion => U3, U3; + self * UnitQuaternion::::from_rotation_matrix(&rhs); ); // UnitQuaternion ÷ Rotation quaternion_op_impl!( @@ -308,12 +302,11 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Div, div; -(U4, U1), (U3, U3); -self: UnitQuaternion, rhs: Rotation, -Output = UnitQuaternion => U3, U3; -self / UnitQuaternion::::from_rotation_matrix(&rhs); -); + Div, div; + (U4, U1), (U3, U3); + self: UnitQuaternion, rhs: Rotation, + Output = UnitQuaternion => U3, U3; + self / UnitQuaternion::::from_rotation_matrix(&rhs); ); // Rotation × UnitQuaternion quaternion_op_impl!( @@ -342,12 +335,11 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Mul, mul; -(U3, U3), (U4, U1); -self: Rotation, rhs: UnitQuaternion, -Output = UnitQuaternion => U3, U3; -UnitQuaternion::::from_rotation_matrix(&self) * rhs; -); + Mul, mul; + (U3, U3), (U4, U1); + self: Rotation, rhs: UnitQuaternion, + Output = UnitQuaternion => U3, U3; + UnitQuaternion::::from_rotation_matrix(&self) * rhs; ); // Rotation ÷ UnitQuaternion quaternion_op_impl!( @@ -376,12 +368,11 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Div, div; -(U3, U3), (U4, U1); -self: Rotation, rhs: UnitQuaternion, -Output = UnitQuaternion => U3, U3; -UnitQuaternion::::from_rotation_matrix(&self) / rhs; -); + Div, div; + (U3, U3), (U4, U1); + self: Rotation, rhs: UnitQuaternion, + Output = UnitQuaternion => U3, U3; + UnitQuaternion::::from_rotation_matrix(&self) / rhs; ); // UnitQuaternion × Vector quaternion_op_impl!( @@ -415,12 +406,11 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Mul, mul; -(U4, U1), (U3, U1) for SB: Storage ; -self: UnitQuaternion, rhs: Vector, -Output = Vector3 => U3, U4; -&self * &rhs; -); + Mul, mul; + (U4, U1), (U3, U1) for SB: Storage ; + self: UnitQuaternion, rhs: Vector, + Output = Vector3 => U3, U4; + &self * &rhs; ); // UnitQuaternion × Point quaternion_op_impl!( @@ -448,12 +438,11 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Mul, mul; -(U4, U1), (U3, U1); -self: UnitQuaternion, rhs: Point3, -Output = Point3 => U3, U4; -Point3::from(self * rhs.coords); -); + Mul, mul; + (U4, U1), (U3, U1); + self: UnitQuaternion, rhs: Point3, + Output = Point3 => U3, U4; + Point3::from(self * rhs.coords); ); // UnitQuaternion × Unit quaternion_op_impl!( @@ -481,12 +470,11 @@ quaternion_op_impl!( 'b); quaternion_op_impl!( -Mul, mul; -(U4, U1), (U3, U1) for SB: Storage ; -self: UnitQuaternion, rhs: Unit>, -Output = Unit> => U3, U4; -Unit::new_unchecked(self * rhs.into_inner()); -); + Mul, mul; + (U4, U1), (U3, U1) for SB: Storage ; + self: UnitQuaternion, rhs: Unit>, + Output = Unit> => U3, U4; + Unit::new_unchecked(self * rhs.into_inner()); ); macro_rules! scalar_op_impl( ($($Op: ident, $op: ident, $OpAssign: ident, $op_assign: ident);* $(;)*) => {$( diff --git a/src/geometry/rotation_ops.rs b/src/geometry/rotation_ops.rs index b3330877..9b90c856 100644 --- a/src/geometry/rotation_ops.rs +++ b/src/geometry/rotation_ops.rs @@ -59,10 +59,10 @@ md_impl_all!( Div, div; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation, Output = Rotation; - [val val] => self * right.inverse(); - [ref val] => self * right.inverse(); - [val ref] => self * right.inverse(); - [ref ref] => self * right.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; ); // Rotation × Matrix @@ -98,10 +98,10 @@ md_impl_all!( where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Matrix, right: Rotation, Output = MatrixMN; - [val val] => self * right.inverse(); - [ref val] => self * right.inverse(); - [val ref] => self * right.inverse(); - [ref ref] => self * right.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; ); // Rotation × Point diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index 9043a667..d011871d 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -158,15 +158,14 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; self: Similarity, rhs: Similarity, Output = Similarity; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.inverse(); - [ref ref] => self * rhs.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; ); // Similarity ×= Translation similarity_binop_assign_impl_all!( - MulAssign, mul_assign; self: Similarity, rhs: Translation; [val] => *self *= &rhs; @@ -281,6 +280,7 @@ similarity_binop_impl_all!( [ref ref] => { let shift = self.isometry.rotation.transform_vector(&rhs.translation.vector) * self.scaling(); Similarity::from_parts( + #[allow(clippy::suspicious_arithmetic_impl)] Translation::from(&self.isometry.translation.vector + shift), self.isometry.rotation.clone() * rhs.rotation.clone(), self.scaling()) @@ -290,10 +290,10 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; self: Similarity, rhs: Isometry, Output = Similarity; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.inverse(); - [ref ref] => self * rhs.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; ); // Isometry × Similarity @@ -322,10 +322,10 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; self: Isometry, rhs: Similarity, Output = Similarity; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.inverse(); - [ref ref] => self * rhs.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; ); // Similarity × Point @@ -364,6 +364,7 @@ similarity_binop_impl_all!( [ref ref] => { let shift = self.isometry.rotation.transform_vector(&right.vector) * self.scaling(); Similarity::from_parts( + #[allow(clippy::suspicious_arithmetic_impl)] Translation::from(&self.isometry.translation.vector + shift), self.isometry.rotation.clone(), self.scaling()) @@ -495,10 +496,10 @@ similarity_from_composition_impl_all!( self: Rotation, right: Similarity>, Output = Similarity>; // FIXME: don't call inverse explicitly? - [val val] => self * right.inverse(); - [ref val] => self * right.inverse(); - [val ref] => self * right.inverse(); - [ref ref] => self * right.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; ); // Similarity × UnitQuaternion @@ -556,10 +557,10 @@ similarity_from_composition_impl_all!( self: UnitQuaternion, right: Similarity>, Output = Similarity>; // FIXME: don't call inverse explicitly? - [val val] => self * right.inverse(); - [ref val] => self * right.inverse(); - [val ref] => self * right.inverse(); - [ref ref] => self * right.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; ); // Similarity × UnitComplex diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index 5773782c..6986a90a 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -143,6 +143,7 @@ md_impl_all!( if C::has_normalizer() { let normalizer = self.matrix().fixed_slice::(D::dim(), 0); + #[allow(clippy::suspicious_arithmetic_impl)] let n = normalizer.tr_dot(&rhs.coords) + unsafe { *self.matrix().get_unchecked((D::dim(), D::dim())) }; if !n.is_zero() { @@ -293,10 +294,10 @@ md_impl_all!( Div, div where N: RealField; (DimNameSum, DimNameSum), (DimNameSum, DimNameSum) for D: DimNameAdd, CA: TCategoryMul, CB: SubTCategoryOf; self: Transform, rhs: Transform, Output = Transform; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.clone().inverse(); - [ref ref] => self * rhs.clone().inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.clone().inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.clone().inverse() }; ); // Transform ÷ Rotation @@ -304,10 +305,10 @@ md_impl_all!( Div, div where N: RealField; (DimNameSum, DimNameSum), (D, D) for D: DimNameAdd, C: TCategoryMul; self: Transform, rhs: Rotation, Output = Transform; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.inverse(); - [ref ref] => self * rhs.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; ); // Rotation ÷ Transform @@ -315,10 +316,10 @@ md_impl_all!( Div, div where N: RealField; (D, D), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul; self: Rotation, rhs: Transform, Output = Transform; - [val val] => self.inverse() * rhs; - [ref val] => self.inverse() * rhs; - [val ref] => self.inverse() * rhs; - [ref ref] => self.inverse() * rhs; + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; ); // Transform ÷ UnitQuaternion @@ -326,10 +327,10 @@ md_impl_all!( Div, div where N: RealField; (U4, U4), (U4, U1) for C: TCategoryMul; self: Transform, rhs: UnitQuaternion, Output = Transform; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.inverse(); - [ref ref] => self * rhs.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; ); // UnitQuaternion ÷ Transform @@ -337,10 +338,10 @@ md_impl_all!( Div, div where N: RealField; (U4, U1), (U4, U4) for C: TCategoryMul; self: UnitQuaternion, rhs: Transform, Output = Transform; - [val val] => self.inverse() * rhs; - [ref val] => self.inverse() * rhs; - [val ref] => self.inverse() * rhs; - [ref ref] => self.inverse() * rhs; + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; ); // // Transform ÷ Isometry @@ -402,10 +403,10 @@ md_impl_all!( Div, div where N: RealField; (DimNameSum, DimNameSum), (D, U1) for D: DimNameAdd, C: TCategoryMul; self: Transform, rhs: Translation, Output = Transform; - [val val] => self * rhs.inverse(); - [ref val] => self * rhs.inverse(); - [val ref] => self * rhs.inverse(); - [ref ref] => self * rhs.inverse(); + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; ); // Translation ÷ Transform @@ -414,10 +415,10 @@ md_impl_all!( (D, U1), (DimNameSum, DimNameSum) for D: DimNameAdd, C: TCategoryMul; self: Translation, rhs: Transform, Output = Transform; - [val val] => self.inverse() * rhs; - [ref val] => self.inverse() * rhs; - [val ref] => self.inverse() * rhs; - [ref ref] => self.inverse() * rhs; + [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; ); // Transform ×= Transform diff --git a/src/geometry/translation_ops.rs b/src/geometry/translation_ops.rs index c00b25bc..8d543c20 100644 --- a/src/geometry/translation_ops.rs +++ b/src/geometry/translation_ops.rs @@ -13,44 +13,50 @@ use crate::geometry::{Point, Translation}; add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: &'a Translation, right: &'b Translation, Output = Translation; - Translation::from(&self.vector + &right.vector); 'a, 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + &right.vector) }; + 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: &'a Translation, right: Translation, Output = Translation; - Translation::from(&self.vector + right.vector); 'a); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + right.vector) }; + 'a); add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: Translation, right: &'b Translation, Output = Translation; - Translation::from(self.vector + &right.vector); 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + &right.vector) }; + 'b); add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: Translation, right: Translation, Output = Translation; - Translation::from(self.vector + right.vector); ); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + right.vector) }; ); // Translation ÷ Translation // FIXME: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method? add_sub_impl!(Div, div, ClosedSub; (D, U1), (D, U1) -> (D) for D: DimName; self: &'a Translation, right: &'b Translation, Output = Translation; - Translation::from(&self.vector - &right.vector); 'a, 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - &right.vector) }; + 'a, 'b); add_sub_impl!(Div, div, ClosedSub; (D, U1), (D, U1) -> (D) for D: DimName; self: &'a Translation, right: Translation, Output = Translation; - Translation::from(&self.vector - right.vector); 'a); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - right.vector) }; + 'a); add_sub_impl!(Div, div, ClosedSub; (D, U1), (D, U1) -> (D) for D: DimName; self: Translation, right: &'b Translation, Output = Translation; - Translation::from(self.vector - &right.vector); 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - &right.vector) }; + 'b); add_sub_impl!(Div, div, ClosedSub; (D, U1), (D, U1) -> (D) for D: DimName; self: Translation, right: Translation, Output = Translation; - Translation::from(self.vector - right.vector); ); + #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - right.vector) }; ); // Translation × Point // FIXME: we don't handle properly non-zero origins here. Do we want this to be the intended @@ -58,107 +64,45 @@ add_sub_impl!(Div, div, ClosedSub; add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: &'a Translation, right: &'b Point, Output = Point; - right + &self.vector; 'a, 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; + 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: &'a Translation, right: Point, Output = Point; - right + &self.vector; 'a); + #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; + 'a); add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: Translation, right: &'b Point, Output = Point; - right + self.vector; 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; + 'b); add_sub_impl!(Mul, mul, ClosedAdd; (D, U1), (D, U1) -> (D) for D: DimName; self: Translation, right: Point, Output = Point; - right + self.vector; ); + #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; ); // Translation *= Translation add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd; (D, U1), (D, U1) for D: DimName; self: Translation, right: &'b Translation; - self.vector += &right.vector; 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { self.vector += &right.vector }; + 'b); add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd; (D, U1), (D, U1) for D: DimName; self: Translation, right: Translation; - self.vector += right.vector; ); + #[allow(clippy::suspicious_arithmetic_impl)] { self.vector += right.vector }; ); add_sub_assign_impl!(DivAssign, div_assign, ClosedSub; (D, U1), (D, U1) for D: DimName; self: Translation, right: &'b Translation; - self.vector -= &right.vector; 'b); + #[allow(clippy::suspicious_arithmetic_impl)] { self.vector -= &right.vector }; + 'b); add_sub_assign_impl!(DivAssign, div_assign, ClosedSub; (D, U1), (D, U1) for D: DimName; self: Translation, right: Translation; - self.vector -= right.vector; ); - -/* -// Translation × Matrix -add_sub_impl!(Mul, mul; - (D1, D1), (R2, C2) for D1, R2, C2; - self: &'a Translation, right: &'b Matrix, Output = MatrixMN; - self.vector() * right; 'a, 'b); - -add_sub_impl!(Mul, mul; - (D1, D1), (R2, C2) for D1, R2, C2; - self: &'a Translation, right: Matrix, Output = MatrixMN; - self.vector() * right; 'a); - -add_sub_impl!(Mul, mul; - (D1, D1), (R2, C2) for D1, R2, C2; - self: Translation, right: &'b Matrix, Output = MatrixMN; - self.unwrap() * right; 'b); - -add_sub_impl!(Mul, mul; - (D1, D1), (R2, C2) for D1, R2, C2; - self: Translation, right: Matrix, Output = MatrixMN; - self.unwrap() * right; ); - -// Matrix × Translation -add_sub_impl!(Mul, mul; - (R1, C1), (D2, D2) for R1, C1, D2; - self: &'a Matrix, right: &'b Translation, Output = MatrixMN; - self * right.vector(); 'a, 'b); - -add_sub_impl!(Mul, mul; - (R1, C1), (D2, D2) for R1, C1, D2; - self: &'a Matrix, right: Translation, Output = MatrixMN; - self * right.unwrap(); 'a); - -add_sub_impl!(Mul, mul; - (R1, C1), (D2, D2) for R1, C1, D2; - self: Matrix, right: &'b Translation, Output = MatrixMN; - self * right.vector(); 'b); - - -add_sub_impl!(Mul, mul; - (R1, C1), (D2, D2) for R1, C1, D2; - self: Matrix, right: Translation, Output = MatrixMN; - self * right.unwrap(); ); - -// Matrix *= Translation -md_assign_impl!(MulAssign, mul_assign; - (R1, C1), (C1, C1) for R1, C1; - self: Matrix, right: &'b Translation; - self.mul_assign(right.vector()); 'b); - -md_assign_impl!(MulAssign, mul_assign; - (R1, C1), (C1, C1) for R1, C1; - self: Matrix, right: Translation; - self.mul_assign(right.unwrap()); ); - - -md_assign_impl!(DivAssign, div_assign; - (R1, C1), (C1, C1) for R1, C1; - self: Matrix, right: &'b Translation; - self.mul_assign(right.inverse().vector()); 'b); - -md_assign_impl!(DivAssign, div_assign; - (R1, C1), (C1, C1) for R1, C1; - self: Matrix, right: Translation; - self.mul_assign(right.inverse().unwrap()); ); -*/ + #[allow(clippy::suspicious_arithmetic_impl)] { self.vector -= right.vector }; ); diff --git a/src/geometry/unit_complex_ops.rs b/src/geometry/unit_complex_ops.rs index f7af7088..af1a32f1 100644 --- a/src/geometry/unit_complex_ops.rs +++ b/src/geometry/unit_complex_ops.rs @@ -96,6 +96,7 @@ where #[inline] fn div(self, rhs: Self) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] Unit::new_unchecked(self.into_inner() * rhs.conjugate().into_inner()) } } @@ -108,6 +109,7 @@ where #[inline] fn div(self, rhs: UnitComplex) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner()) } } @@ -120,6 +122,7 @@ where #[inline] fn div(self, rhs: &'b UnitComplex) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] Unit::new_unchecked(self.into_inner() * rhs.conjugate().into_inner()) } } @@ -132,6 +135,7 @@ where #[inline] fn div(self, rhs: &'b UnitComplex) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner()) } } @@ -206,7 +210,7 @@ complex_op_impl_all!( [val val] => &self / &rhs; [ref val] => self / &rhs; [val ref] => &self / rhs; - [ref ref] => self * UnitComplex::from_rotation_matrix(rhs).inverse(); + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * UnitComplex::from_rotation_matrix(rhs).inverse() }; ); // Rotation × UnitComplex @@ -228,7 +232,7 @@ complex_op_impl_all!( [val val] => &self / &rhs; [ref val] => self / &rhs; [val ref] => &self / rhs; - [ref ref] => UnitComplex::from_rotation_matrix(self) * rhs.inverse(); + [ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { UnitComplex::from_rotation_matrix(self) * rhs.inverse() }; ); // UnitComplex × Point From d990aff44e68869719251d564ffe9a4beac9c1f8 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 25 Oct 2020 18:38:50 +0100 Subject: [PATCH 2/2] clippy: fix clippy::eq_op error (false positive) --- src/geometry/quaternion.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 22ee5309..69d54967 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -389,6 +389,7 @@ where /// ``` #[inline] pub fn outer(&self, other: &Self) -> Self { + #[allow(clippy::eq_op)] (self * other - other * self).half() }