about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-19 12:59:51 +0000
committerbors <bors@rust-lang.org>2023-07-19 12:59:51 +0000
commit0b63e95dce4e7f89936fa3547291bfe0b6ef5ffd (patch)
treed93bfa4bfc5c37af0c46e197a26b7acb8b17fd04 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
parent7a34143fa394ccba3cbe7bd1d068420b1bfb84ea (diff)
parent648d1ae8e08ab8617d17c4c815a067dd7d7e550f (diff)
downloadrust-0b63e95dce4e7f89936fa3547291bfe0b6ef5ffd.tar.gz
rust-0b63e95dce4e7f89936fa3547291bfe0b6ef5ffd.zip
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)
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions