]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/suspicious_arithmetic_impl.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / suspicious_arithmetic_impl.rs
index 097627e1d7c28fc3548dd50af869a5431c275e14..ed845b7647a568b54005e1c6b1330bc3c2f4996f 100644 (file)
@@ -1,8 +1,14 @@
+// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
 
-
-
-#![warn(suspicious_arithmetic_impl)]
-use std::ops::{Add, AddAssign, Mul, Sub, Div};
+#![warn(clippy::suspicious_arithmetic_impl)]
+use std::ops::{Add, AddAssign, Div, Mul, Sub};
 
 #[derive(Copy, Clone)]
 struct Foo(u32);
@@ -25,7 +31,7 @@ impl Mul for Foo {
     type Output = Foo;
 
     fn mul(self, other: Foo) -> Foo {
-        Foo(self.0 * other.0 % 42) // OK: BiRem part of BiExpr as parent node
+        Foo(self.0 * other.0 % 42) // OK: BinOpKind::Rem part of BiExpr as parent node
     }
 }
 
@@ -33,7 +39,7 @@ impl Sub for Foo {
     type Output = Foo;
 
     fn sub(self, other: Self) -> Self {
-        Foo(self.0 * other.0 - 42) // OK: BiMul part of BiExpr as child node
+        Foo(self.0 * other.0 - 42) // OK: BinOpKind::Mul part of BiExpr as child node
     }
 }
 
@@ -41,7 +47,29 @@ impl Div for Foo {
     type Output = Foo;
 
     fn div(self, other: Self) -> Self {
-        Foo(do_nothing(self.0 + other.0) / 42) // OK: BiAdd part of BiExpr as child node
+        Foo(do_nothing(self.0 + other.0) / 42) // OK: BinOpKind::Add part of BiExpr as child node
+    }
+}
+
+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 {
+        if self.0 <= other.0 {
+            Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node
+        } else {
+            Bar(0)
+        }
     }
 }