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