summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/infallible_destructuring_match.txt
blob: 4b5d3c4ba6c40c1b0657fa0195b977bacdb09453 (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
### What it does
Checks for matches being used to destructure a single-variant enum
or tuple struct where a `let` will suffice.

### Why is this bad?
Just readability – `let` doesn't nest, whereas a `match` does.

### Example
```
enum Wrapper {
    Data(i32),
}

let wrapper = Wrapper::Data(42);

let data = match wrapper {
    Wrapper::Data(i) => i,
};
```

The correct use would be:
```
enum Wrapper {
    Data(i32),
}

let wrapper = Wrapper::Data(42);
let Wrapper::Data(data) = wrapper;
```