Commit 786c94a
committed
Auto merge of #116734 - Nadrieril:lint-per-column, r=cjgillot
Lint `non_exhaustive_omitted_patterns` by columns
This is a rework of the `non_exhaustive_omitted_patterns` lint to make it more consistent. The intent of the lint is to help consumers of `non_exhaustive` enums ensure they stay up-to-date with all upstream variants. This rewrite fixes two cases we didn't handle well before:
First, because of details of exhaustiveness checking, the following wouldn't lint `Enum::C` as missing:
```rust
match Some(x) {
Some(Enum::A) => {}
Some(Enum::B) => {}
_ => {}
}
```
Second, because of the fundamental workings of exhaustiveness checking, the following would treat the `true` and `false` cases separately and thus lint about missing variants:
```rust
match (true, x) {
(true, Enum::A) => {}
(true, Enum::B) => {}
(false, Enum::C) => {}
_ => {}
}
```
Moreover, it would correctly not lint in the case where the pair is flipped, because of asymmetry in how exhaustiveness checking proceeds.
A drawback is that it no longer makes sense to set the lint level per-arm. This will silently break the lint for current users of it (but it's behind a feature gate so that's ok).
The new approach is now independent of the exhaustiveness algorithm; it's a separate pass that looks at patterns column by column. This is another of the motivations for this: I'm glad to move it out of the algorithm, it was akward there.
This PR is almost identical to #111651. cc `@eholk` who reviewed it at the time. Compared to then, I'm more confident this is the right approach.File tree
11 files changed
+579
-366
lines changed- compiler
- rustc_lint_defs/src
- rustc_mir_build/src
- thir/pattern
- tests/ui
- feature-gates
- rfcs/rfc-2008-non-exhaustive
11 files changed
+579
-366
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3953 | 3953 | | |
3954 | 3954 | | |
3955 | 3955 | | |
3956 | | - | |
3957 | | - | |
| 3956 | + | |
| 3957 | + | |
| 3958 | + | |
| 3959 | + | |
| 3960 | + | |
| 3961 | + | |
| 3962 | + | |
3958 | 3963 | | |
3959 | 3964 | | |
3960 | 3965 | | |
| |||
3968 | 3973 | | |
3969 | 3974 | | |
3970 | 3975 | | |
| 3976 | + | |
3971 | 3977 | | |
3972 | 3978 | | |
3973 | | - | |
3974 | 3979 | | |
3975 | 3980 | | |
3976 | 3981 | | |
3977 | 3982 | | |
3978 | 3983 | | |
3979 | 3984 | | |
3980 | 3985 | | |
3981 | | - | |
| 3986 | + | |
3982 | 3987 | | |
3983 | 3988 | | |
3984 | | - | |
3985 | | - | |
| 3989 | + | |
| 3990 | + | |
3986 | 3991 | | |
3987 | 3992 | | |
3988 | 3993 | | |
3989 | 3994 | | |
3990 | 3995 | | |
3991 | 3996 | | |
3992 | | - | |
| 3997 | + | |
3993 | 3998 | | |
3994 | 3999 | | |
3995 | 4000 | | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
3996 | 4005 | | |
3997 | 4006 | | |
3998 | | - | |
3999 | | - | |
4000 | | - | |
4001 | | - | |
4002 | | - | |
4003 | | - | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
4004 | 4012 | | |
4005 | 4013 | | |
4006 | 4014 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
813 | | - | |
| 813 | + | |
814 | 814 | | |
815 | 815 | | |
816 | 816 | | |
| |||
Lines changed: 13 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
| 476 | + | |
| 477 | + | |
477 | 478 | | |
478 | 479 | | |
479 | 480 | | |
| |||
662 | 663 | | |
663 | 664 | | |
664 | 665 | | |
665 | | - | |
| 666 | + | |
666 | 667 | | |
667 | 668 | | |
668 | 669 | | |
| |||
701 | 702 | | |
702 | 703 | | |
703 | 704 | | |
704 | | - | |
705 | | - | |
| 705 | + | |
| 706 | + | |
706 | 707 | | |
707 | 708 | | |
708 | 709 | | |
| |||
718 | 719 | | |
719 | 720 | | |
720 | 721 | | |
721 | | - | |
| 722 | + | |
722 | 723 | | |
723 | 724 | | |
724 | 725 | | |
| |||
896 | 897 | | |
897 | 898 | | |
898 | 899 | | |
899 | | - | |
| 900 | + | |
900 | 901 | | |
901 | 902 | | |
902 | | - | |
| 903 | + | |
903 | 904 | | |
904 | 905 | | |
905 | 906 | | |
| |||
916 | 917 | | |
917 | 918 | | |
918 | 919 | | |
919 | | - | |
| 920 | + | |
920 | 921 | | |
921 | 922 | | |
922 | 923 | | |
| |||
927 | 928 | | |
928 | 929 | | |
929 | 930 | | |
930 | | - | |
| 931 | + | |
931 | 932 | | |
932 | 933 | | |
933 | 934 | | |
| |||
958 | 959 | | |
959 | 960 | | |
960 | 961 | | |
961 | | - | |
| 962 | + | |
962 | 963 | | |
963 | 964 | | |
964 | 965 | | |
| |||
0 commit comments