]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / needless_borrowed_ref.fixed
CommitLineData
f20569fa
XL
1// run-rustfix
2
3#[warn(clippy::needless_borrowed_reference)]
4#[allow(unused_variables)]
5fn 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)]
32enum Animal {
33 Cat(u64),
34 Dog(u64),
35}
36
37#[allow(unused_variables)]
38#[allow(dead_code)]
39fn 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}