Skip to content

Commit 762f5d3

Browse files
committed
Incorrect suspicious_op_assign_impl
1 parent 7907abe commit 762f5d3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

clippy_lints/src/suspicious_trait_impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
7272
match e.kind {
7373
hir::ExprKind::Binary(..)
7474
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
75-
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _) => return,
75+
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _)
76+
| hir::ExprKind::AssignOp(..) => return,
7677
_ => {},
7778
}
7879
}

tests/ui/suspicious_arithmetic_impl.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::suspicious_arithmetic_impl)]
2-
use std::ops::{Add, AddAssign, Div, Mul, Sub};
2+
use std::ops::{Add, AddAssign, BitOrAssign, Div, Mul, Sub};
33

44
#[derive(Copy, Clone)]
55
struct Foo(u32);
@@ -18,6 +18,13 @@ impl AddAssign for Foo {
1818
}
1919
}
2020

21+
impl BitOrAssign for Foo {
22+
fn bitor_assign(&mut self, other: Foo) {
23+
let idx = other.0;
24+
self.0 |= 1 << idx;
25+
}
26+
}
27+
2128
impl Mul for Foo {
2229
type Output = Foo;
2330

0 commit comments

Comments
 (0)