diff options
Diffstat (limited to 'src/tools/clippy/src/docs/option_if_let_else.txt')
-rw-r--r-- | src/tools/clippy/src/docs/option_if_let_else.txt | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/src/tools/clippy/src/docs/option_if_let_else.txt b/src/tools/clippy/src/docs/option_if_let_else.txt deleted file mode 100644 index 43652db51..000000000 --- a/src/tools/clippy/src/docs/option_if_let_else.txt +++ /dev/null @@ -1,46 +0,0 @@ -### What it does -Lints usage of `if let Some(v) = ... { y } else { x }` and -`match .. { Some(v) => y, None/_ => x }` which are more -idiomatically done with `Option::map_or` (if the else bit is a pure -expression) or `Option::map_or_else` (if the else bit is an impure -expression). - -### Why is this bad? -Using the dedicated functions of the `Option` type is clearer and -more concise than an `if let` expression. - -### Known problems -This lint uses a deliberately conservative metric for checking -if the inside of either body contains breaks or continues which will -cause it to not suggest a fix if either block contains a loop with -continues or breaks contained within the loop. - -### Example -``` -let _ = if let Some(foo) = optional { - foo -} else { - 5 -}; -let _ = match optional { - Some(val) => val + 1, - None => 5 -}; -let _ = if let Some(foo) = optional { - foo -} else { - let y = do_complicated_function(); - y*y -}; -``` - -should be - -``` -let _ = optional.map_or(5, |foo| foo); -let _ = optional.map_or(5, |val| val + 1); -let _ = optional.map_or_else(||{ - let y = do_complicated_function(); - y*y -}, |foo| foo); -```
\ No newline at end of file |