mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
83 lines
2.1 KiB
Text
83 lines
2.1 KiB
Text
error: use Option::map_or instead of an if let/else
|
|
--> $DIR/option_if_let_else.rs:5:5
|
|
|
|
|
LL | / if let Some(x) = string {
|
|
LL | | (true, x)
|
|
LL | | } else {
|
|
LL | | (false, "hello")
|
|
LL | | }
|
|
| |_____^ help: try: `string.map_or((false, "hello"), |x| (true, x))`
|
|
|
|
|
= note: `-D clippy::option-if-let-else` implied by `-D warnings`
|
|
|
|
error: use Option::map_or instead of an if let/else
|
|
--> $DIR/option_if_let_else.rs:15:12
|
|
|
|
|
LL | } else if let Some(x) = string {
|
|
| ____________^
|
|
LL | | Some((true, x))
|
|
LL | | } else {
|
|
LL | | Some((false, ""))
|
|
LL | | }
|
|
| |_____^ help: try: `{ string.map_or(Some((false, "")), |x| Some((true, x))) }`
|
|
|
|
error: use Option::map_or instead of an if let/else
|
|
--> $DIR/option_if_let_else.rs:23:5
|
|
|
|
|
LL | / if let Some(s) = *string {
|
|
LL | | s.len()
|
|
LL | | } else {
|
|
LL | | 0
|
|
LL | | }
|
|
| |_____^ help: try: `(*string).map_or(0, |s| s.len())`
|
|
|
|
error: use Option::map_or instead of an if let/else
|
|
--> $DIR/option_if_let_else.rs:31:5
|
|
|
|
|
LL | / if let Some(x) = arg {
|
|
LL | | let y = x * x;
|
|
LL | | y * y
|
|
LL | | } else {
|
|
LL | | 13
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try
|
|
|
|
|
LL | arg.map_or(13, |x| {
|
|
LL | let y = x * x;
|
|
LL | y * y
|
|
LL | })
|
|
|
|
|
|
|
error: use Option::map_or_else instead of an if let/else
|
|
--> $DIR/option_if_let_else.rs:40:13
|
|
|
|
|
LL | let _ = if let Some(x) = arg {
|
|
| _____________^
|
|
LL | | x * x * x * x
|
|
LL | | } else {
|
|
LL | | let mut y = 1;
|
|
... |
|
|
LL | | y
|
|
LL | | };
|
|
| |_____^
|
|
|
|
|
help: try
|
|
|
|
|
LL | let _ = arg.map_or_else(|| {
|
|
LL | let mut y = 1;
|
|
LL | y = (y + 2 / y) / 2;
|
|
LL | y = (y + 2 / y) / 2;
|
|
LL | y
|
|
LL | }, |x| x * x * x * x);
|
|
|
|
|
|
|
error: use Option::map_or instead of an if let/else
|
|
--> $DIR/option_if_let_else.rs:69:13
|
|
|
|
|
LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
|
|
|
|
error: aborting due to 6 previous errors
|
|
|