rust/clippy_utils/src
bors 0b63e95dce Auto merge of #10949 - y21:issue8010, r=Alexendoo
[`manual_filter_map`]: lint on `matches` and pattern matching

Fixes #8010

Previously this lint only worked specifically for a very limited set of methods on the filter call (`.filter(|opt| opt.is_some())` and `.filter(|res| res.is_ok())`). This PR extends it to also recognize `matches!` in the `filter` and pattern matching with `if let` or `match` in the `map`.

Example:
```rs
enum Enum {
  A(i32),
  B,
}

let _ = [Enum::A(123), Enum::B].into_iter()
  .filter(|x| matches!(x, Enum::A(_)))
  .map(|x| if let Enum::A(s) = x { s } else { unreachable!() });
```
Now suggests:
```diff
-  .filter(|x| matches!(x, Enum::A(_))).map(if let Enum::A(s) = x { s } else { unreachable!() })
+  .filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })
```

Adding this required a somewhat large change in code because it originally seemed to be specifically written with only method calls in the filter in mind, and `matches!` has different behavior in the map, so this new setup should make it possible to support more "generic" cases that need different handling for the filter and map calls.

changelog: [`manual_filter_map`]: lint on `matches` and pattern matching (and some internal refactoring)
2023-07-19 12:59:51 +00:00
..
ast_utils Merge commit '928e72dd10' into clippyup 2021-02-25 11:25:22 +01:00
mir Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
ty/type_certainty Fix unwrap_or_else_default false positive 2023-07-19 06:45:33 -04:00
ast_utils.rs Make clippy happy 2023-04-27 17:18:12 +00:00
attrs.rs Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
check_proc_macro.rs Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
comparisons.rs Fix typos 2023-07-02 07:11:05 -05:00
consts.rs Merge remote-tracking branch 'upstream/master' into rustup 2023-07-14 13:36:16 +02:00
diagnostics.rs Merge remote-tracking branch 'upstream/master' into rustup 2023-06-02 10:17:55 +02:00
eager_or_lazy.rs Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
higher.rs Auto merge of #10949 - y21:issue8010, r=Alexendoo 2023-07-19 12:59:51 +00:00
hir_utils.rs Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
lib.rs Merge remote-tracking branch 'upstream/master' into rustup 2023-07-14 13:36:16 +02:00
macros.rs Merge remote-tracking branch 'upstream/master' into rustup 2023-07-14 13:36:16 +02:00
msrvs.rs Merge commit '37f4c1725d' into clippyup 2023-07-02 14:59:02 +02:00
numeric_literal.rs Merge commit '37f4c1725d' into clippyup 2023-07-02 14:59:02 +02:00
paths.rs Fix regex lints for regex 1.9.0 2023-07-05 18:29:43 +00:00
ptr.rs Merge commit 'ac0e10aa68' into clippyup 2022-10-06 09:44:38 +02:00
qualify_min_const_fn.rs Merge remote-tracking branch 'upstream/master' into rustup 2023-07-14 13:36:16 +02:00
source.rs Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
str_utils.rs Merge commit '0eff589afc' into clippyup 2021-12-30 15:10:43 +01:00
sugg.rs Merge commit '37f4c1725d' into clippyup 2023-07-02 14:59:02 +02:00
sym_helper.rs Merge commit '928e72dd10' into clippyup 2021-02-25 11:25:22 +01:00
ty.rs Fix unwrap_or_else_default false positive 2023-07-19 06:45:33 -04:00
usage.rs Merge remote-tracking branch 'upstream/master' into rustup 2023-07-14 13:36:16 +02:00
visitors.rs Support hir::ExprKind::Become in clippy 2023-06-26 08:56:32 +00:00