1 #![allow(unused_variables, clippy::disallowed_names)]
2 #![warn(clippy::op_ref)]
3 use std::collections::HashSet;
4 use std::ops::{BitAnd, Mul};
5
main()6 fn main() {
7 let tracked_fds: HashSet<i32> = HashSet::new();
8 let new_fds = HashSet::new();
9 let unwanted = &tracked_fds - &new_fds;
10
11 let foo = &5 - &6;
12
13 let bar = String::new();
14 let bar = "foo" == &bar;
15
16 let a = "a".to_string();
17 let b = "a";
18
19 if b < &a {
20 println!("OK");
21 }
22
23 struct X(i32);
24 impl BitAnd for X {
25 type Output = X;
26 fn bitand(self, rhs: X) -> X {
27 X(self.0 & rhs.0)
28 }
29 }
30 impl<'a> BitAnd<&'a X> for X {
31 type Output = X;
32 fn bitand(self, rhs: &'a X) -> X {
33 X(self.0 & rhs.0)
34 }
35 }
36 let x = X(1);
37 let y = X(2);
38 let z = x & &y;
39
40 #[derive(Copy, Clone)]
41 struct Y(i32);
42 impl BitAnd for Y {
43 type Output = Y;
44 fn bitand(self, rhs: Y) -> Y {
45 Y(self.0 & rhs.0)
46 }
47 }
48 impl<'a> BitAnd<&'a Y> for Y {
49 type Output = Y;
50 fn bitand(self, rhs: &'a Y) -> Y {
51 Y(self.0 & rhs.0)
52 }
53 }
54 let x = Y(1);
55 let y = Y(2);
56 let z = x & &y;
57 }
58
59 #[derive(Clone, Copy)]
60 struct A(i32);
61 #[derive(Clone, Copy)]
62 struct B(i32);
63
64 impl Mul<&A> for B {
65 type Output = i32;
mul(self, rhs: &A) -> Self::Output66 fn mul(self, rhs: &A) -> Self::Output {
67 self.0 * rhs.0
68 }
69 }
70 impl Mul<A> for B {
71 type Output = i32;
mul(self, rhs: A) -> Self::Output72 fn mul(self, rhs: A) -> Self::Output {
73 // Should not lint because removing the reference would lead to unconditional recursion
74 self * &rhs
75 }
76 }
77 impl Mul<&A> for A {
78 type Output = i32;
mul(self, rhs: &A) -> Self::Output79 fn mul(self, rhs: &A) -> Self::Output {
80 self.0 * rhs.0
81 }
82 }
83 impl Mul<A> for A {
84 type Output = i32;
mul(self, rhs: A) -> Self::Output85 fn mul(self, rhs: A) -> Self::Output {
86 let one = B(1);
87 let two = 2;
88 let three = 3;
89 let _ = one * &self;
90 let _ = two + &three;
91 // Removing the reference would lead to unconditional recursion
92 self * &rhs
93 }
94 }
95