3 #![warn(clippy::needless_borrowed_reference)]
4 #![allow(unused, clippy::needless_borrow)]
8 fn should_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
9 let mut v = Vec::<String>::new();
10 let _ = v.iter_mut().filter(|a| a.is_empty());
13 let thingy = Some(&var);
14 if let Some(v) = thingy {}
16 if let &[a, ref b] = slice_of_refs {}
19 let [a, b, ..] = &array;
21 if let [a, b] = slice {}
22 if let [a, b] = &vec[..] {}
24 if let [a, b, ..] = slice {}
25 if let [a, .., b] = slice {}
26 if let [.., a, b] = slice {}
29 fn should_not_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
30 if let [ref a] = slice {}
31 if let &[ref a, b] = slice {}
32 if let &[ref a, .., b] = slice {}
34 // must not be removed as variables must be bound consistently across | patterns
35 if let (&[ref a], _) | ([], ref a) = (slice_of_refs, &1u8) {}
38 let thingy2 = Some(&mut var2);
39 if let Some(&mut ref mut v) = thingy2 {
40 // ^ should **not** be linted
41 // v is borrowed as mutable.
44 if let Some(&mut ref v) = thingy2 {
45 // ^ should **not** be linted
46 // here, v is borrowed as immutable.
57 fn foo(a: &Animal, b: &Animal) {
59 // lifetime mismatch error if there is no '&ref' before `feature(nll)` stabilization in 1.63
60 (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (),
61 // ^ and ^ should **not** be linted
62 (&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should **not** be linted