forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#120775 - Nadrieril:more-min_exh_pats, r=compiler-errors Make `min_exhaustive_patterns` match `exhaustive_patterns` better Split off from rust-lang#120742. There remained two edge cases where `min_exhaustive_patterns` wasn't behaving like `exhaustive_patterns`. This fixes them, and tests the feature in a bunch more cases. I essentially went through all uses of `exhaustive_patterns` to see which ones would be interesting to compare between the two features. r? `@compiler-errors`
- Loading branch information
Showing
18 changed files
with
192 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/ui/closures/2229_closure_analysis/run_pass/multivariant.min_exhaustive_patterns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: the feature `min_exhaustive_patterns` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/multivariant.rs:7:46 | ||
| | ||
LL | #![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #119612 <https://github.com/rust-lang/rust/issues/119612> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
5 changes: 4 additions & 1 deletion
5
tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/ui/pattern/usefulness/always-inhabited-union-ref.min_exhaustive_patterns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
warning: the feature `min_exhaustive_patterns` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/always-inhabited-union-ref.rs:7:46 | ||
| | ||
LL | #![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #119612 <https://github.com/rust-lang/rust/issues/119612> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0004]: non-exhaustive patterns: type `&!` is non-empty | ||
--> $DIR/always-inhabited-union-ref.rs:26:11 | ||
| | ||
LL | match uninhab_ref() { | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: the matched value is of type `&!` | ||
= note: references are always considered inhabited | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ match uninhab_ref() { | ||
LL + _ => todo!(), | ||
LL + } | ||
| | ||
|
||
error[E0004]: non-exhaustive patterns: type `Foo` is non-empty | ||
--> $DIR/always-inhabited-union-ref.rs:30:11 | ||
| | ||
LL | match uninhab_union() { | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
note: `Foo` defined here | ||
--> $DIR/always-inhabited-union-ref.rs:13:11 | ||
| | ||
LL | pub union Foo { | ||
| ^^^ | ||
= note: the matched value is of type `Foo` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ match uninhab_union() { | ||
LL + _ => todo!(), | ||
LL + } | ||
| | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0004`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/ui/pattern/usefulness/match-privately-empty.min_exhaustive_patterns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
warning: the feature `min_exhaustive_patterns` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/match-privately-empty.rs:3:46 | ||
| | ||
LL | #![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #119612 <https://github.com/rust-lang/rust/issues/119612> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0004]: non-exhaustive patterns: `Some(Private { misc: true, .. })` not covered | ||
--> $DIR/match-privately-empty.rs:16:11 | ||
| | ||
LL | match private::DATA { | ||
| ^^^^^^^^^^^^^ pattern `Some(Private { misc: true, .. })` not covered | ||
| | ||
note: `Option<Private>` defined here | ||
--> $SRC_DIR/core/src/option.rs:LL:COL | ||
::: $SRC_DIR/core/src/option.rs:LL:COL | ||
| | ||
= note: not covered | ||
= note: the matched value is of type `Option<Private>` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | ||
| | ||
LL ~ Some(private::Private { misc: false, .. }) => {}, | ||
LL + Some(Private { misc: true, .. }) => todo!() | ||
| | ||
|
||
error: aborting due to 1 previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0004`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../pattern/usefulness/slice_of_empty.stderr → ...slice_of_empty.exhaustive_patterns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/ui/pattern/usefulness/slice_of_empty.min_exhaustive_patterns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
warning: the feature `min_exhaustive_patterns` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/slice_of_empty.rs:3:46 | ||
| | ||
LL | #![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #119612 <https://github.com/rust-lang/rust/issues/119612> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered | ||
--> $DIR/slice_of_empty.rs:11:11 | ||
| | ||
LL | match nevers { | ||
| ^^^^^^ pattern `&[_, ..]` not covered | ||
| | ||
= note: the matched value is of type `&[!]` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | ||
| | ||
LL ~ &[] => (), | ||
LL ~ &[_, ..] => todo!(), | ||
| | ||
|
||
error[E0004]: non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered | ||
--> $DIR/slice_of_empty.rs:22:11 | ||
| | ||
LL | match nevers { | ||
| ^^^^^^ patterns `&[]` and `&[_, _, ..]` not covered | ||
| | ||
= note: the matched value is of type `&[!]` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms | ||
| | ||
LL ~ &[_] => (), | ||
LL ~ &[] | &[_, _, ..] => todo!(), | ||
| | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0004`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ninhabited/uninhabited-irrefutable.stderr → ...ed-irrefutable.exhaustive_patterns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/ui/uninhabited/uninhabited-irrefutable.min_exhaustive_patterns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error[E0005]: refutable pattern in local binding | ||
--> $DIR/uninhabited-irrefutable.rs:32:9 | ||
| | ||
LL | let Foo::D(_y, _z) = x; | ||
| ^^^^^^^^^^^^^^ pattern `Foo::A(_)` not covered | ||
| | ||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
note: `Foo` defined here | ||
--> $DIR/uninhabited-irrefutable.rs:21:6 | ||
| | ||
LL | enum Foo { | ||
| ^^^ | ||
LL | | ||
LL | A(foo::SecretlyEmpty), | ||
| - not covered | ||
= note: pattern `Foo::A(_)` is currently uninhabited, but this variant contains private fields which may become inhabited in the future | ||
= note: the matched value is of type `Foo` | ||
help: you might want to use `let else` to handle the variant that isn't matched | ||
| | ||
LL | let Foo::D(_y, _z) = x else { todo!() }; | ||
| ++++++++++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0005`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters