2018-07-28 10:34:52 -05:00
|
|
|
#![warn(clippy::suspicious_arithmetic_impl)]
|
2020-04-05 13:40:51 -05:00
|
|
|
use std::ops::{Add, AddAssign, BitOrAssign, Div, DivAssign, Mul, MulAssign, Sub};
|
2018-02-13 08:40:17 -06:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct Foo(u32);
|
|
|
|
|
|
|
|
impl Add for Foo {
|
|
|
|
type Output = Foo;
|
|
|
|
|
|
|
|
fn add(self, other: Self) -> Self {
|
|
|
|
Foo(self.0 - other.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddAssign for Foo {
|
|
|
|
fn add_assign(&mut self, other: Foo) {
|
|
|
|
*self = *self - other;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 13:40:51 -05:00
|
|
|
impl BitOrAssign for Foo {
|
|
|
|
fn bitor_assign(&mut self, other: Foo) {
|
|
|
|
let idx = other.0;
|
|
|
|
self.0 |= 1 << idx; // OK: BinOpKind::Shl part of AssignOp as child node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MulAssign for Foo {
|
|
|
|
fn mul_assign(&mut self, other: Foo) {
|
|
|
|
self.0 /= other.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DivAssign for Foo {
|
|
|
|
fn div_assign(&mut self, other: Foo) {
|
|
|
|
self.0 /= other.0; // OK: BinOpKind::Div == DivAssign
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 08:40:17 -06:00
|
|
|
impl Mul for Foo {
|
|
|
|
type Output = Foo;
|
|
|
|
|
|
|
|
fn mul(self, other: Foo) -> Foo {
|
2018-07-12 02:50:09 -05:00
|
|
|
Foo(self.0 * other.0 % 42) // OK: BinOpKind::Rem part of BiExpr as parent node
|
2018-02-13 08:40:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Sub for Foo {
|
|
|
|
type Output = Foo;
|
|
|
|
|
|
|
|
fn sub(self, other: Self) -> Self {
|
2018-07-12 02:50:09 -05:00
|
|
|
Foo(self.0 * other.0 - 42) // OK: BinOpKind::Mul part of BiExpr as child node
|
2018-02-13 08:40:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Div for Foo {
|
|
|
|
type Output = Foo;
|
|
|
|
|
|
|
|
fn div(self, other: Self) -> Self {
|
2018-07-12 02:50:09 -05:00
|
|
|
Foo(do_nothing(self.0 + other.0) / 42) // OK: BinOpKind::Add part of BiExpr as child node
|
2018-02-13 08:40:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 06:58:03 -06:00
|
|
|
struct Bar(i32);
|
|
|
|
|
|
|
|
impl Add for Bar {
|
|
|
|
type Output = Bar;
|
|
|
|
|
|
|
|
fn add(self, other: Self) -> Self {
|
|
|
|
Bar(self.0 & !other.0) // OK: UnNot part of BiExpr as child node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Sub for Bar {
|
|
|
|
type Output = Bar;
|
|
|
|
|
|
|
|
fn sub(self, other: Self) -> Self {
|
2018-03-17 15:34:13 -05:00
|
|
|
if self.0 <= other.0 {
|
|
|
|
Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node
|
|
|
|
} else {
|
|
|
|
Bar(0)
|
|
|
|
}
|
2018-03-06 06:58:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 08:40:17 -06:00
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
fn do_nothing(x: u32) -> u32 {
|
|
|
|
x
|
|
|
|
}
|