3 #![warn(clippy::needless_borrowed_reference)]
6 irrefutable_let_patterns,
7 non_shorthand_field_patterns,
8 clippy::needless_borrow
19 struct TupleStruct(u8, u8, u8);
24 slice_of_refs: &[&u8],
27 tuple_struct: TupleStruct,
30 let mut v = Vec::<String>::new();
31 let _ = v.iter_mut().filter(|&ref a| a.is_empty());
34 let thingy = Some(&var);
35 if let Some(&ref v) = thingy {}
37 if let &[&ref a, ref b] = slice_of_refs {}
39 let &[ref a, ..] = &array;
40 let &[ref a, ref b, ..] = &array;
42 if let &[ref a, ref b] = slice {}
43 if let &[ref a, ref b] = &vec[..] {}
45 if let &[ref a, ref b, ..] = slice {}
46 if let &[ref a, .., ref b] = slice {}
47 if let &[.., ref a, ref b] = slice {}
49 if let &[ref a, _] = slice {}
51 if let &(ref a, ref b, ref c) = &tuple {}
52 if let &(ref a, _, ref c) = &tuple {}
53 if let &(ref a, ..) = &tuple {}
55 if let &TupleStruct(ref a, ..) = &tuple_struct {}
64 if let &Struct { ref a, b: _, .. } = &s {}
70 slice_of_refs: &[&u8],
73 tuple_struct: TupleStruct,
76 if let [ref a] = slice {}
77 if let &[ref a, b] = slice {}
78 if let &[ref a, .., b] = slice {}
80 if let &(ref a, b, ..) = &tuple {}
81 if let &TupleStruct(ref a, b, ..) = &tuple_struct {}
82 if let &Struct { ref a, b, .. } = &s {}
84 // must not be removed as variables must be bound consistently across | patterns
85 if let (&[ref a], _) | ([], ref a) = (slice_of_refs, &1u8) {}
87 // the `&`s here technically could be removed, but it'd be noisy and without a `ref` doesn't match
90 if let &[_] = slice {}
91 if let &[..] = slice {}
92 if let &(..) = &tuple {}
93 if let &TupleStruct(..) = &tuple_struct {}
94 if let &Struct { .. } = &s {}
97 let thingy2 = Some(&mut var2);
98 if let Some(&mut ref mut v) = thingy2 {
99 // ^ should **not** be linted
100 // v is borrowed as mutable.
103 if let Some(&mut ref v) = thingy2 {
104 // ^ should **not** be linted
105 // here, v is borrowed as immutable.
116 fn foo(a: &Animal, b: &Animal) {
118 // lifetime mismatch error if there is no '&ref' before `feature(nll)` stabilization in 1.63
119 (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (),
120 // ^ and ^ should **not** be linted
121 (Animal::Dog(a), &Animal::Dog(_)) => (),