-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Initial implementation of or-pattern usefulness checking #66612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6e85f46
0030a77
b5ec4d1
cdc844e
0881750
0f4c5fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![feature(or_patterns)] | ||
#![feature(slice_patterns)] | ||
#![allow(incomplete_features)] | ||
#![deny(unreachable_patterns)] | ||
|
||
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now. | ||
fn main() { | ||
// Get the fatal error out of the way | ||
match (0u8,) { | ||
(0 | _,) => {} | ||
//~^ ERROR or-patterns are not fully implemented yet | ||
} | ||
|
||
match (0u8, 0u8) { | ||
//~^ ERROR non-exhaustive patterns: `(2u8..=std::u8::MAX, _)` | ||
(0 | 1, 2 | 3) => {} | ||
} | ||
match ((0u8,),) { | ||
//~^ ERROR non-exhaustive patterns: `((4u8..=std::u8::MAX))` | ||
((0 | 1,) | (2 | 3,),) => {}, | ||
} | ||
match (Some(0u8),) { | ||
//~^ ERROR non-exhaustive patterns: `(Some(2u8..=std::u8::MAX))` | ||
(None | Some(0 | 1),) => {} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error[E0004]: non-exhaustive patterns: `(2u8..=std::u8::MAX, _)` not covered | ||
--> $DIR/exhaustiveness-non-exhaustive.rs:14:11 | ||
| | ||
LL | match (0u8, 0u8) { | ||
| ^^^^^^^^^^ pattern `(2u8..=std::u8::MAX, _)` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `((4u8..=std::u8::MAX))` not covered | ||
--> $DIR/exhaustiveness-non-exhaustive.rs:18:11 | ||
| | ||
LL | match ((0u8,),) { | ||
| ^^^^^^^^^ pattern `((4u8..=std::u8::MAX))` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `(Some(2u8..=std::u8::MAX))` not covered | ||
--> $DIR/exhaustiveness-non-exhaustive.rs:22:11 | ||
| | ||
LL | match (Some(0u8),) { | ||
| ^^^^^^^^^^^^ pattern `(Some(2u8..=std::u8::MAX))` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error: or-patterns are not fully implemented yet | ||
--> $DIR/exhaustiveness-non-exhaustive.rs:10:10 | ||
| | ||
LL | (0 | _,) => {} | ||
| ^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0004`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![feature(or_patterns)] | ||
#![feature(slice_patterns)] | ||
#![allow(incomplete_features)] | ||
#![deny(unreachable_patterns)] | ||
|
||
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now. | ||
fn main() { | ||
// Get the fatal error out of the way | ||
match (0u8,) { | ||
(0 | _,) => {} | ||
//~^ ERROR or-patterns are not fully implemented yet | ||
} | ||
|
||
match (0u8,) { | ||
(1 | 2,) => {} | ||
_ => {} | ||
} | ||
|
||
match (0u8,) { | ||
(1 | 1,) => {} // redundancy not detected for now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume you have plans for this somehow... =P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do ^^. This is actually necessary if we want to remove the hack for top-level or-patterns and keep the same diagnostics. I'll have a follow-up PR up soon
Nadrieril marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ => {} | ||
} | ||
match (0u8, 0u8) { | ||
(1 | 2, 3 | 4) => {} | ||
(1, 2) => {} | ||
(2, 1) => {} | ||
_ => {} | ||
} | ||
match (Some(0u8),) { | ||
(None | Some(0 | 1),) => {} | ||
(Some(2..=255),) => {} | ||
} | ||
match ((0u8,),) { | ||
((0 | 1,) | (2 | 3,),) => {}, | ||
((_,),) => {}, | ||
} | ||
match (&[0u8][..],) { | ||
([] | [0 | 1..=255] | [_, ..],) => {}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: or-patterns are not fully implemented yet | ||
--> $DIR/exhaustiveness-pass.rs:10:10 | ||
| | ||
LL | (0 | _,) => {} | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#![feature(or_patterns)] | ||
#![feature(slice_patterns)] | ||
#![allow(incomplete_features)] | ||
#![deny(unreachable_patterns)] | ||
|
||
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now. | ||
fn main() { | ||
// Get the fatal error out of the way | ||
match (0u8,) { | ||
(0 | _,) => {} | ||
//~^ ERROR or-patterns are not fully implemented yet | ||
} | ||
|
||
match (0u8,) { | ||
(1 | 2,) => {} | ||
(1,) => {} //~ ERROR unreachable pattern | ||
_ => {} | ||
} | ||
match (0u8,) { | ||
(1 | 2,) => {} | ||
(2,) => {} //~ ERROR unreachable pattern | ||
_ => {} | ||
} | ||
match (0u8,) { | ||
(1,) => {} | ||
(2,) => {} | ||
(1 | 2,) => {} //~ ERROR unreachable pattern | ||
_ => {} | ||
} | ||
match (0u8, 0u8) { | ||
(1 | 2, 3 | 4) => {} | ||
(1, 3) => {} //~ ERROR unreachable pattern | ||
(1, 4) => {} //~ ERROR unreachable pattern | ||
(2, 4) => {} //~ ERROR unreachable pattern | ||
(2 | 1, 4) => {} //~ ERROR unreachable pattern | ||
(1, 5 | 6) => {} | ||
(1, 4 | 5) => {} //~ ERROR unreachable pattern | ||
_ => {} | ||
} | ||
match (Some(0u8),) { | ||
(None | Some(1 | 2),) => {} | ||
(Some(1),) => {} //~ ERROR unreachable pattern | ||
(None,) => {} //~ ERROR unreachable pattern | ||
_ => {} | ||
} | ||
match ((0u8,),) { | ||
((1 | 2,) | (3 | 4,),) => {}, | ||
((1..=4,),) => {}, //~ ERROR unreachable pattern | ||
_ => {}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:16:9 | ||
| | ||
LL | (1,) => {} | ||
| ^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:4:9 | ||
| | ||
LL | #![deny(unreachable_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:21:9 | ||
| | ||
LL | (2,) => {} | ||
| ^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:27:9 | ||
| | ||
LL | (1 | 2,) => {} | ||
| ^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:32:9 | ||
| | ||
LL | (1, 3) => {} | ||
| ^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:33:9 | ||
| | ||
LL | (1, 4) => {} | ||
| ^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:34:9 | ||
| | ||
LL | (2, 4) => {} | ||
| ^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:35:9 | ||
| | ||
LL | (2 | 1, 4) => {} | ||
| ^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:37:9 | ||
| | ||
LL | (1, 4 | 5) => {} | ||
| ^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:42:9 | ||
| | ||
LL | (Some(1),) => {} | ||
| ^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:43:9 | ||
| | ||
LL | (None,) => {} | ||
| ^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:48:9 | ||
| | ||
LL | ((1..=4,),) => {}, | ||
| ^^^^^^^^^^^ | ||
|
||
error: or-patterns are not fully implemented yet | ||
--> $DIR/exhaustiveness-unreachable-pattern.rs:10:10 | ||
| | ||
LL | (0 | _,) => {} | ||
| ^^^^^ | ||
|
||
error: aborting due to 12 previous errors | ||
|
Uh oh!
There was an error while loading. Please reload this page.