mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
c3d58cd5fa
Fixes #13407
62 lines
2 KiB
Text
62 lines
2 KiB
Text
error: this could be simplified with `bool::then`
|
|
--> tests/ui/if_then_some_else_none.rs:6:13
|
|
|
|
|
LL | let _ = if foo() {
|
|
| _____________^
|
|
LL | |
|
|
LL | | println!("true!");
|
|
LL | | Some("foo")
|
|
LL | | } else {
|
|
LL | | None
|
|
LL | | };
|
|
| |_____^ help: try: `foo().then(|| { println!("true!"); "foo" })`
|
|
|
|
|
= note: `-D clippy::if-then-some-else-none` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::if_then_some_else_none)]`
|
|
|
|
error: this could be simplified with `bool::then`
|
|
--> tests/ui/if_then_some_else_none.rs:15:13
|
|
|
|
|
LL | let _ = if matches!(true, true) {
|
|
| _____________^
|
|
LL | |
|
|
LL | | println!("true!");
|
|
LL | | Some(matches!(true, false))
|
|
LL | | } else {
|
|
LL | | None
|
|
LL | | };
|
|
| |_____^ help: try: `matches!(true, true).then(|| { println!("true!"); matches!(true, false) })`
|
|
|
|
error: this could be simplified with `bool::then_some`
|
|
--> tests/ui/if_then_some_else_none.rs:25:28
|
|
|
|
|
LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None });
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(o < 32).then_some(o)`
|
|
|
|
error: this could be simplified with `bool::then_some`
|
|
--> tests/ui/if_then_some_else_none.rs:30:13
|
|
|
|
|
LL | let _ = if !x { Some(0) } else { None };
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(!x).then_some(0)`
|
|
|
|
error: this could be simplified with `bool::then`
|
|
--> tests/ui/if_then_some_else_none.rs:86:13
|
|
|
|
|
LL | let _ = if foo() {
|
|
| _____________^
|
|
LL | |
|
|
LL | | println!("true!");
|
|
LL | | Some(150)
|
|
LL | | } else {
|
|
LL | | None
|
|
LL | | };
|
|
| |_____^ help: try: `foo().then(|| { println!("true!"); 150 })`
|
|
|
|
error: this could be simplified with `bool::then`
|
|
--> tests/ui/if_then_some_else_none.rs:135:5
|
|
|
|
|
LL | if s == "1" { Some(true) } else { None }
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(s == "1").then(|| true)`
|
|
|
|
error: aborting due to 6 previous errors
|
|
|