From da6a83fd02d3d1c7251858a64bfc4b1342a7e9b8 Mon Sep 17 00:00:00 2001 From: Jacek Pospychala Date: Sun, 5 Apr 2020 20:40:51 +0200 Subject: [PATCH] Incorrect suspicious_op_assign_impl --- clippy_lints/src/suspicious_trait_impl.rs | 3 ++- tests/ui/suspicious_arithmetic_impl.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 89b57ed1a8de..8189fc239b5d 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -72,7 +72,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { match e.kind { hir::ExprKind::Binary(..) | hir::ExprKind::Unary(hir::UnOp::UnNot, _) - | hir::ExprKind::Unary(hir::UnOp::UnNeg, _) => return, + | hir::ExprKind::Unary(hir::UnOp::UnNeg, _) + | hir::ExprKind::AssignOp(..) => return, _ => {}, } } diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index 6ee924d3b2ed..be6e42d57450 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -1,5 +1,5 @@ #![warn(clippy::suspicious_arithmetic_impl)] -use std::ops::{Add, AddAssign, Div, Mul, Sub}; +use std::ops::{Add, AddAssign, Div, Mul, Sub, BitOrAssign}; #[derive(Copy, Clone)] struct Foo(u32); @@ -18,6 +18,13 @@ impl AddAssign for Foo { } } +impl BitOrAssign for Foo { + fn bitor_assign(&mut self, other: Foo) { + let idx = other.0; + self.0 |= 1 << idx; + } +} + impl Mul for Foo { type Output = Foo;