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