summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/needless_borrowed_reference.txt
blob: 55faa0cf5719569abb22f17a906fa9436f1428a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
### What it does
Checks for bindings that destructure a reference and borrow the inner
value with `&ref`.

### Why is this bad?
This pattern has no effect in almost all cases.

### Known problems
In some cases, `&ref` is needed to avoid a lifetime mismatch error.
Example:
```
fn foo(a: &Option<String>, b: &Option<String>) {
    match (a, b) {
        (None, &ref c) | (&ref c, None) => (),
        (&Some(ref c), _) => (),
    };
}
```

### Example
```
let mut v = Vec::<String>::new();
v.iter_mut().filter(|&ref a| a.is_empty());
```

Use instead:
```
let mut v = Vec::<String>::new();
v.iter_mut().filter(|a| a.is_empty());
```