]> git.lizzy.rs Git - rust.git/blob - src/docs/unwrap_used.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / unwrap_used.txt
1 ### What it does
2 Checks for `.unwrap()` or `.unwrap_err()` calls on `Result`s and `.unwrap()` call on `Option`s.
3
4 ### Why is this bad?
5 It is better to handle the `None` or `Err` case,
6 or at least call `.expect(_)` with a more helpful message. Still, for a lot of
7 quick-and-dirty code, `unwrap` is a good choice, which is why this lint is
8 `Allow` by default.
9
10 `result.unwrap()` will let the thread panic on `Err` values.
11 Normally, you want to implement more sophisticated error handling,
12 and propagate errors upwards with `?` operator.
13
14 Even if you want to panic on errors, not all `Error`s implement good
15 messages on display. Therefore, it may be beneficial to look at the places
16 where they may get displayed. Activate this lint to do just that.
17
18 ### Examples
19 ```
20 option.unwrap();
21 result.unwrap();
22 ```
23
24 Use instead:
25 ```
26 option.expect("more helpful message");
27 result.expect("more helpful message");
28 ```
29
30 If [expect_used](#expect_used) is enabled, instead:
31 ```
32 option?;
33
34 // or
35
36 result?;
37 ```