]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_borrowed_ref.rs
Auto merge of #4314 - chansuke:add-negation-to-is_empty, r=flip1995
[rust.git] / tests / ui / needless_borrowed_ref.rs
1 #[warn(clippy::needless_borrowed_reference)]
2 #[allow(unused_variables)]
3 fn main() {
4     let mut v = Vec::<String>::new();
5     let _ = v.iter_mut().filter(|&ref a| a.is_empty());
6     //                            ^ should be linted
7
8     let var = 3;
9     let thingy = Some(&var);
10     if let Some(&ref v) = thingy {
11         //          ^ should be linted
12     }
13
14     let mut var2 = 5;
15     let thingy2 = Some(&mut var2);
16     if let Some(&mut ref mut v) = thingy2 {
17         //          ^ should **not** be linted
18         // v is borrowed as mutable.
19         *v = 10;
20     }
21     if let Some(&mut ref v) = thingy2 {
22         //          ^ should **not** be linted
23         // here, v is borrowed as immutable.
24         // can't do that:
25         //*v = 15;
26     }
27 }
28
29 #[allow(dead_code)]
30 enum Animal {
31     Cat(u64),
32     Dog(u64),
33 }
34
35 #[allow(unused_variables)]
36 #[allow(dead_code)]
37 fn foo(a: &Animal, b: &Animal) {
38     match (a, b) {
39         (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
40         //                  ^    and   ^ should **not** be linted
41         (&Animal::Dog(ref a), &Animal::Dog(_)) => (), //              ^ should **not** be linted
42     }
43 }