]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/panic_in_result_fn.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / panic_in_result_fn.txt
1 ### What it does
2 Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result.
3
4 ### Why is this bad?
5 For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided.
6
7 ### Known problems
8 Functions called from a function returning a `Result` may invoke a panicking macro. This is not checked.
9
10 ### Example
11 ```
12 fn result_with_panic() -> Result<bool, String>
13 {
14     panic!("error");
15 }
16 ```
17 Use instead:
18 ```
19 fn result_without_panic() -> Result<bool, String> {
20     Err(String::from("error"))
21 }
22 ```