]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/if_then_some_else_none.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / if_then_some_else_none.txt
CommitLineData
f2b60f7d
FG
1### What it does
2Checks for if-else that could be written using either `bool::then` or `bool::then_some`.
3
4### Why is this bad?
5Looks a little redundant. Using `bool::then` is more concise and incurs no loss of clarity.
6For simple calculations and known values, use `bool::then_some`, which is eagerly evaluated
7in comparison to `bool::then`.
8
9### Example
10```
11let a = if v.is_empty() {
12 println!("true!");
13 Some(42)
14} else {
15 None
16};
17```
18
19Could be written:
20
21```
22let a = v.is_empty().then(|| {
23 println!("true!");
24 42
25});
26```