]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/manual_assert.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / manual_assert.txt
1 ### What it does
2 Detects `if`-then-`panic!` that can be replaced with `assert!`.
3
4 ### Why is this bad?
5 `assert!` is simpler than `if`-then-`panic!`.
6
7 ### Example
8 ```
9 let sad_people: Vec<&str> = vec![];
10 if !sad_people.is_empty() {
11     panic!("there are sad people: {:?}", sad_people);
12 }
13 ```
14 Use instead:
15 ```
16 let sad_people: Vec<&str> = vec![];
17 assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people);
18 ```