summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/unwrap_used.txt
blob: 9b4713df515d65e2bdf91498d9d2577ff12a6635 (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
31
32
33
34
35
36
37
### What it does
Checks for `.unwrap()` or `.unwrap_err()` calls on `Result`s and `.unwrap()` call on `Option`s.

### Why is this bad?
It is better to handle the `None` or `Err` case,
or at least call `.expect(_)` with a more helpful message. Still, for a lot of
quick-and-dirty code, `unwrap` is a good choice, which is why this lint is
`Allow` by default.

`result.unwrap()` will let the thread panic on `Err` values.
Normally, you want to implement more sophisticated error handling,
and propagate errors upwards with `?` operator.

Even if you want to panic on errors, not all `Error`s implement good
messages on display. Therefore, it may be beneficial to look at the places
where they may get displayed. Activate this lint to do just that.

### Examples
```
option.unwrap();
result.unwrap();
```

Use instead:
```
option.expect("more helpful message");
result.expect("more helpful message");
```

If [expect_used](#expect_used) is enabled, instead:
```
option?;

// or

result?;
```