]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/op_ref.rs
Fix `unnecessary_cast` suggestion when taking a reference
[rust.git] / tests / ui / op_ref.rs
index 6605c967c8e7e6323d659f0a7c645e0cd59832c2..07226b0a1a83b272a250e20429b555b30f04bacd 100644 (file)
@@ -1,8 +1,7 @@
-#![allow(unused_variables, clippy::blacklisted_name)]
+#![allow(unused_variables, clippy::disallowed_names)]
 #![warn(clippy::op_ref)]
-#![allow(clippy::many_single_char_names)]
 use std::collections::HashSet;
-use std::ops::BitAnd;
+use std::ops::{BitAnd, Mul};
 
 fn main() {
     let tracked_fds: HashSet<i32> = HashSet::new();
@@ -56,3 +55,40 @@ fn bitand(self, rhs: &'a Y) -> Y {
     let y = Y(2);
     let z = x & &y;
 }
+
+#[derive(Clone, Copy)]
+struct A(i32);
+#[derive(Clone, Copy)]
+struct B(i32);
+
+impl Mul<&A> for B {
+    type Output = i32;
+    fn mul(self, rhs: &A) -> Self::Output {
+        self.0 * rhs.0
+    }
+}
+impl Mul<A> for B {
+    type Output = i32;
+    fn mul(self, rhs: A) -> Self::Output {
+        // Should not lint because removing the reference would lead to unconditional recursion
+        self * &rhs
+    }
+}
+impl Mul<&A> for A {
+    type Output = i32;
+    fn mul(self, rhs: &A) -> Self::Output {
+        self.0 * rhs.0
+    }
+}
+impl Mul<A> for A {
+    type Output = i32;
+    fn mul(self, rhs: A) -> Self::Output {
+        let one = B(1);
+        let two = 2;
+        let three = 3;
+        let _ = one * &self;
+        let _ = two + &three;
+        // Removing the reference would lead to unconditional recursion
+        self * &rhs
+    }
+}