]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/unwrap_in_result.txt
Auto merge of #98559 - jackh726:remove-reempty, r=oli-obk
[rust.git] / src / tools / clippy / src / docs / unwrap_in_result.txt
1 ### What it does
2 Checks for functions of type `Result` that contain `expect()` or `unwrap()`
3
4 ### Why is this bad?
5 These functions promote recoverable errors to non-recoverable errors which may be undesirable in code bases which wish to avoid panics.
6
7 ### Known problems
8 This can cause false positives in functions that handle both recoverable and non recoverable errors.
9
10 ### Example
11 Before:
12 ```
13 fn divisible_by_3(i_str: String) -> Result<(), String> {
14     let i = i_str
15         .parse::<i32>()
16         .expect("cannot divide the input by three");
17
18     if i % 3 != 0 {
19         Err("Number is not divisible by 3")?
20     }
21
22     Ok(())
23 }
24 ```
25
26 After:
27 ```
28 fn divisible_by_3(i_str: String) -> Result<(), String> {
29     let i = i_str
30         .parse::<i32>()
31         .map_err(|e| format!("cannot divide the input by three: {}", e))?;
32
33     if i % 3 != 0 {
34         Err("Number is not divisible by 3")?
35     }
36
37     Ok(())
38 }
39 ```