diff options
| author | bors <bors@rust-lang.org> | 2022-10-08 15:58:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-08 15:58:51 +0000 |
| commit | 292e313259f422c8f4c31ecaedcc14058e8f4f8b (patch) | |
| tree | 57a9020d932e78c457c5e1a96d299da076a4dae7 /src/docs | |
| parent | 2c8e473ffea22fdf9ffbecb53c1c7288d38fe923 (diff) | |
| parent | 830fdf2b56d2a2f0f8e8135e05ec30b08e54ad3a (diff) | |
Auto merge of #9451 - kraktus:manual_filter2, r=dswij
Add `manual_filter` lint for `Option` Share much of its implementation with `manual_map` and should greatly benefit from its previous feedback. I'm sure it's possible to even more refactor both and would gladly take input on that as well as any clippy idiomatic usage, since this is my first lint addition. I've added the lint to the complexity section for now, I don't know if every new lint needs to go in nursery first. The matching could be expanded to more than `Some(<value>)` to lint on arbitrary struct matching inside the `Some` but I've left it like it was for `manual_map` for now. `needless_match::pat_same_as_expr` provides a more generic match example. close https://github.com/rust-lang/rust-clippy/issues/8822 changelog: Add lint [`manual_filter`] for `Option`
Diffstat (limited to 'src/docs')
| -rw-r--r-- | src/docs/manual_filter.txt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/docs/manual_filter.txt b/src/docs/manual_filter.txt new file mode 100644 index 00000000000..19a4d9319d9 --- /dev/null +++ b/src/docs/manual_filter.txt @@ -0,0 +1,21 @@ +### What it does +Checks for usages of `match` which could be implemented using `filter` + +### Why is this bad? +Using the `filter` method is clearer and more concise. + +### Example +``` +match Some(0) { + Some(x) => if x % 2 == 0 { + Some(x) + } else { + None + }, + None => None, +}; +``` +Use instead: +``` +Some(0).filter(|&x| x % 2 == 0); +``` \ No newline at end of file |
