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
..
2020-12-03 10:21:33 +01:00
2020-12-03 10:21:33 +01:00
2020-07-03 00:04:48 +03:00
2020-11-05 14:29:48 +01:00
2020-04-18 18:28:29 +08:00
2020-10-09 12:45:29 +02:00
2020-11-23 13:51:04 +01:00
2020-08-28 18:43:25 +02:00
2020-09-10 17:47:07 +02:00
2020-09-24 14:49:22 +02:00
2020-11-27 10:32:44 +09:00
2020-11-23 13:51:04 +01:00
2020-09-24 14:49:22 +02:00
2020-07-03 00:04:48 +03:00
2020-10-28 23:36:07 +01:00
2020-11-05 14:29:48 +01:00
2020-11-05 14:29:48 +01:00
2020-11-23 13:51:04 +01:00
2020-08-11 17:50:45 +02:00
2020-11-05 14:29:48 +01:00
2020-07-14 14:59:59 +02:00
2020-11-29 15:34:11 -06:00
2020-11-26 20:07:50 +00:00
2020-11-05 14:29:48 +01:00
2020-10-28 23:36:07 +01:00
2020-07-03 00:04:48 +03:00
2020-09-10 17:47:07 +02:00
2020-04-18 18:28:29 +08:00
2020-11-29 15:34:11 -06:00
2020-11-25 20:59:29 +05:30
2020-07-26 21:07:07 +02:00
2020-10-28 23:36:07 +01:00
2020-10-09 12:45:29 +02:00
2020-11-05 14:29:48 +01:00
2020-08-28 18:43:25 +02:00
2020-08-11 17:50:45 +02:00
2020-09-04 18:27:33 +02:00
2020-09-24 14:49:22 +02:00
2020-04-18 18:28:29 +08:00
2020-07-03 00:04:48 +03:00
2020-09-24 14:49:22 +02:00
2020-09-04 18:27:33 +02:00
2020-09-10 17:58:14 -04:00
2020-11-27 17:50:16 -07:00
2020-07-17 08:47:04 +00:00
2020-11-04 22:45:15 +00:00
2020-09-04 18:27:33 +02:00
2020-11-16 22:42:09 +01:00
2020-04-18 18:28:29 +08:00
2020-07-03 00:04:48 +03:00
2020-11-05 14:29:48 +01:00
2020-11-17 12:16:15 -08:00
2020-10-28 23:36:07 +01:00
2020-09-04 18:27:33 +02:00
2020-09-04 18:27:33 +02:00
2020-11-05 14:29:48 +01:00
2020-07-14 14:59:59 +02:00
2020-11-05 14:29:48 +01:00
2020-11-23 23:02:12 +01:00
2020-11-05 14:29:48 +01:00
2020-09-04 18:27:33 +02:00
2020-07-17 08:47:04 +00:00
2020-11-29 15:34:11 -06:00
2020-08-28 18:43:25 +02:00
2020-11-29 15:34:11 -06:00
2020-11-29 15:34:11 -06:00
2020-09-24 14:49:22 +02:00
2020-08-17 13:55:05 +01:00
2020-08-28 18:43:25 +02:00
2020-11-05 14:29:48 +01:00
2020-11-05 14:29:48 +01:00
2020-08-28 18:43:25 +02:00
2020-07-17 08:47:04 +00:00
2020-11-28 17:18:15 +01:00
2020-11-29 15:34:11 -06:00
2020-07-03 00:04:48 +03:00
2020-11-29 15:34:11 -06:00
2020-11-23 13:51:04 +01:00
2020-11-29 15:34:11 -06:00
2020-11-23 13:51:04 +01:00
2020-12-03 10:21:33 +01:00
2020-11-05 14:29:48 +01:00
2020-10-28 23:36:07 +01:00
2020-11-29 15:34:11 -06:00
2020-10-09 12:45:29 +02:00
2020-07-03 00:04:48 +03:00
2020-11-23 13:51:04 +01:00
2020-11-28 21:21:04 -08:00
2020-11-05 14:29:48 +01:00
2020-12-03 10:21:33 +01:00
2020-11-05 14:29:48 +01:00
2020-11-23 13:51:04 +01:00
2020-09-24 14:49:22 +02:00
2020-11-05 14:29:48 +01:00
2020-11-05 14:29:48 +01:00
2020-11-05 14:29:48 +01:00
2020-12-03 10:21:33 +01:00
2020-07-17 08:47:04 +00:00
2020-07-17 08:47:04 +00:00
2020-07-17 08:47:04 +00:00
2020-08-11 17:50:45 +02:00
2020-10-28 23:36:07 +01:00
2020-11-27 08:55:04 +01:00
2020-10-09 12:45:29 +02:00
2020-11-26 21:32:27 +01:00
2020-11-26 21:32:27 +01:00
2020-09-04 18:27:33 +02:00
2020-07-03 00:04:48 +03:00
2020-11-23 13:51:04 +01:00
2020-09-04 18:27:33 +02:00
2020-10-28 23:36:07 +01:00
2020-09-04 18:27:33 +02:00
2020-10-23 22:16:59 +02:00
2020-09-04 18:27:33 +02:00
2020-10-09 12:45:29 +02:00
2020-11-29 15:34:11 -06:00
2020-11-05 14:29:48 +01:00
2020-07-03 00:04:48 +03:00
2020-06-09 14:36:01 +00:00
2020-11-16 22:42:09 +01:00
2020-09-04 18:27:33 +02:00
2020-08-11 17:50:45 +02:00
2020-08-11 17:50:45 +02:00
2020-11-05 14:29:48 +01:00
2020-07-17 08:47:04 +00:00
2020-11-23 13:51:04 +01:00
2020-11-23 13:51:04 +01:00
2020-09-24 14:49:22 +02:00
2020-06-10 17:30:11 -04:00
2020-11-05 14:29:48 +01:00
2020-08-11 17:50:45 +02:00
2020-11-05 14:29:48 +01:00
2020-11-28 14:55:13 -05:00
2020-11-05 14:29:48 +01:00
2020-11-16 22:42:09 +01:00
2020-09-24 14:49:22 +02:00
2020-09-04 18:27:33 +02:00
2020-08-28 18:43:25 +02:00
2020-10-23 22:16:59 +02:00
2020-11-05 14:29:48 +01:00
2020-11-05 14:29:48 +01:00
2020-11-29 15:34:11 -06:00
2020-11-23 13:51:04 +01:00
2020-11-23 13:51:04 +01:00
2020-11-28 17:03:20 +01:00
2020-05-28 15:45:24 +02:00
2020-07-03 00:04:48 +03:00
2020-08-11 17:50:45 +02:00
2020-11-05 14:29:48 +01:00
2020-11-23 13:51:04 +01:00
2020-11-23 13:51:04 +01:00
2020-11-05 14:29:48 +01:00
2020-11-05 14:29:48 +01:00
2020-08-28 18:43:25 +02:00
2020-07-03 00:04:48 +03:00
2020-09-24 14:49:22 +02:00
2020-09-10 17:58:14 -04:00
2020-07-03 00:04:48 +03:00
2020-08-28 18:43:25 +02:00
2020-11-29 15:34:11 -06:00
2020-11-27 17:50:16 -07:00
2020-08-28 18:43:25 +02:00
2020-11-05 14:29:48 +01:00
2020-08-06 22:55:26 +03:00
2020-09-10 17:47:07 +02:00
2020-09-04 18:27:33 +02:00
2020-08-28 18:43:25 +02:00
2020-11-29 15:34:11 -06:00
2020-11-16 22:42:09 +01:00
2020-11-29 15:34:11 -06:00
2020-11-23 13:51:04 +01:00
2020-11-29 15:34:11 -06:00
2020-10-28 23:36:07 +01:00
2020-10-09 12:45:29 +02:00
2020-11-23 13:51:04 +01:00
2020-09-04 18:27:33 +02:00
2020-11-05 14:29:48 +01:00
2020-11-29 02:18:05 +09:00
2020-08-28 18:43:25 +02:00
2020-07-17 08:28:22 +10:00
2020-08-17 13:55:05 +01:00
2020-07-03 00:04:48 +03:00
2020-11-23 13:51:04 +01:00
2020-11-05 14:29:48 +01:00
2020-11-05 14:29:48 +01:00
2020-11-16 22:42:09 +01:00
2020-11-23 13:51:04 +01:00
2020-08-17 20:32:32 +00:00
2020-09-04 18:27:33 +02:00
2020-07-17 08:47:04 +00:00
2020-07-03 00:04:48 +03:00
2020-08-28 18:43:25 +02:00
2020-11-05 14:29:48 +01:00
2020-07-17 08:47:04 +00:00