diff options
| author | Philipp Krones <hello@philkrones.com> | 2020-12-03 10:21:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-03 10:21:33 +0100 |
| commit | e2ecc4ad6e179c344434333585bf4e4d297e8ef2 (patch) | |
| tree | 8f0d5d4794a375b5255a569be58a67eddaa756b8 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp | |
| parent | b3d6d6e2e77f030c63770512ae4c8e40531fa728 (diff) | |
| parent | 0e207888391fb8b55fa75d19259812b6cb97a75c (diff) | |
| download | rust-e2ecc4ad6e179c344434333585bf4e4d297e8ef2.tar.gz rust-e2ecc4ad6e179c344434333585bf4e4d297e8ef2.zip | |
Rollup merge of #6402 - camsteffen:collapsible-match, r=llogiq
Add Collapsible match lint
changelog: Add collapsible_match lint
Closes #1252
Closes #2521
This lint finds nested `match` or `if let` patterns that can be squashed together. It is designed to be very conservative to only find cases where merging the patterns would most likely reduce cognitive complexity.
Example:
```rust
match result {
Ok(opt) => match opt {
Some(x) => x,
_ => return,
}
_ => return,
}
```
to
```rust
match result {
Ok(Some(x)) => x,
_ => return,
}
```
These criteria must be met for the lint to fire:
* The inner match has exactly 2 branches.
* Both the outer and inner match have a "wild" branch like `_ => ..`. There is a special case for `None => ..` to also be considered "wild-like".
* The contents of the wild branches are identical.
* The binding which "links" the matches is never used elsewhere.
Thanks to the hir, `if let`'s are easily included with this lint since they are desugared into equivalent `match`'es.
I think this would fit into the style category, but I would also understand changing it to pedantic.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
