rust/clippy_lints/src/utils
Philipp Krones e2ecc4ad6e
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.
2020-12-03 10:21:33 +01:00
..
ast_utils add suspicious_operation_groupings lint 2020-11-27 17:50:16 -07:00
ast_utils.rs add suspicious_operation_groupings lint 2020-11-27 17:50:16 -07:00
attrs.rs Add note where the first definition of msrv attr is 2020-11-25 12:23:28 +01:00
author.rs Fix inconsistencies in handling of inert attributes on statements 2020-10-24 11:55:48 -04:00
camel_case.rs new lints around #[must_use] fns 2019-10-14 12:09:04 +02:00
comparisons.rs Rustup to rust-lang/rust#67886 2020-01-07 01:46:33 +09:00
conf.rs add support for minimum supported rust version. 2020-11-25 12:22:47 +01:00
constants.rs Remove all copyright license headers 2019-01-08 21:46:39 +01:00
diagnostics.rs add internal-lints feature to enable clippys internal lints (off by default) 2020-11-29 21:07:43 +01:00
eager_or_lazy.rs Merge commit '3e7c6dec24' into clippyup 2020-11-23 13:51:04 +01:00
higher.rs Eat collapsible_match dogfood 2020-11-29 15:34:11 -06:00
hir_utils.rs Improve SpanlessEq for blocks 2020-11-29 15:02:27 -06:00
inspector.rs Remove ForeignMod struct. 2020-11-26 21:32:27 +01:00
internal_lints.rs Merge commit 'b20d4c155d' into clippyup 2020-11-05 14:29:48 +01:00
mod.rs Rollup merge of #6395 - Suyash458:master, r=flip1995 2020-12-03 10:21:32 +01:00
numeric_literal.rs Merge commit '645ef505da' into clippyup 2020-10-28 23:36:07 +01:00
paths.rs add internal-lints feature to enable clippys internal lints (off by default) 2020-11-29 21:07:43 +01:00
ptr.rs Use 'tcx for references to AccessLevels wherever possible. 2020-07-03 00:04:48 +03:00
qualify_min_const_fn.rs Refactor how SwitchInt stores jump targets 2020-10-10 17:46:11 +02:00
sugg.rs Add underscore expressions for destructuring assignments 2020-11-14 13:53:12 +00:00
sym.rs Rustup to https://github.com/rust-lang/rust/pull/67853 2020-01-04 11:30:03 +01:00
usage.rs Auto merge of #78662 - sexxi-goose:add_expr_id_to_delegate, r=nikomatsakis 2020-11-04 22:45:15 +00:00
visitors.rs Add LocalUseVisitor 2020-11-29 15:02:27 -06:00