1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![warn(clippy::suspicious_arithmetic_impl)]
11 use std::ops::{Add, AddAssign, Div, Mul, Sub};
13 #[derive(Copy, Clone)]
19 fn add(self, other: Self) -> Self {
24 impl AddAssign for Foo {
25 fn add_assign(&mut self, other: Foo) {
26 *self = *self - other;
33 fn mul(self, other: Foo) -> Foo {
34 Foo(self.0 * other.0 % 42) // OK: BinOpKind::Rem part of BiExpr as parent node
41 fn sub(self, other: Self) -> Self {
42 Foo(self.0 * other.0 - 42) // OK: BinOpKind::Mul part of BiExpr as child node
49 fn div(self, other: Self) -> Self {
50 Foo(do_nothing(self.0 + other.0) / 42) // OK: BinOpKind::Add part of BiExpr as child node
59 fn add(self, other: Self) -> Self {
60 Bar(self.0 & !other.0) // OK: UnNot part of BiExpr as child node
67 fn sub(self, other: Self) -> Self {
68 if self.0 <= other.0 {
69 Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node
78 fn do_nothing(x: u32) -> u32 {