-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Refactor slice pattern usefulness checking #66129
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
Merged
bors
merged 18 commits into
rust-lang:master
from
Nadrieril:refactor-slice-pat-usefulness
Nov 12, 2019
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4dc5697
Add some slice-pattern exhaustiveness tests
Nadrieril 235b379
Rename Constructor::Slice to FixedLenSlice
Nadrieril d2b7711
Match on self first in subtract_constructor
Nadrieril e092a17
Add special variable-length slice constructor
Nadrieril 909ec37
Simpler code path for subtracting from FixedLenSlice
Nadrieril b669730
Don't use max_slice_length when subtracting from VarLenSlice
Nadrieril 65bc67e
Make exhaustiveness error message more consistent for slice patterns
Nadrieril 58de9d9
Add some test cases
Nadrieril d7044f2
Store both prefix and suffix length in VarLenSlice
Nadrieril 149792b
pat_constructors returns at most one constructor
Nadrieril d582ed5
Inline max_slice_length
Nadrieril f774eb6
Use VarLenSlice consistently when splitting constructors
Nadrieril 9531787
Move a few more tests to the usefulness/ folder
Nadrieril 816aee2
Apply suggestions from code review
Nadrieril 7514c48
Factor out constructing a new wildcard pattern
Nadrieril 098974d
Split slice-patterns test as suggested by Centril
Nadrieril 369a351
Inline constructor_sub_pattern_tys
Nadrieril fd9921b
tidy
Nadrieril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,110 @@ | ||
#![feature(slice_patterns)] | ||
#![deny(unreachable_patterns)] | ||
|
||
fn main() { | ||
let s: &[bool] = &[true; 0]; | ||
let s0: &[bool; 0] = &[]; | ||
let s1: &[bool; 1] = &[false; 1]; | ||
let s2: &[bool; 2] = &[false; 2]; | ||
let s3: &[bool; 3] = &[false; 3]; | ||
|
||
let [] = s0; | ||
let [_] = s1; | ||
let [_, _] = s2; | ||
|
||
let [..] = s; | ||
let [..] = s0; | ||
let [..] = s1; | ||
let [..] = s2; | ||
let [..] = s3; | ||
|
||
let [_, _, ..] = s2; | ||
let [_, .., _] = s2; | ||
let [.., _, _] = s2; | ||
|
||
match s1 { | ||
[true, ..] => {} | ||
[.., false] => {} | ||
} | ||
match s2 { | ||
//~^ ERROR `&[false, true]` not covered | ||
[true, ..] => {} | ||
[.., false] => {} | ||
} | ||
match s3 { | ||
//~^ ERROR `&[false, _, true]` not covered | ||
[true, ..] => {} | ||
[.., false] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[false, .., true]` not covered | ||
[] => {} | ||
[true, ..] => {} | ||
[.., false] => {} | ||
} | ||
|
||
match s3 { | ||
//~^ ERROR `&[false, _, _]` not covered | ||
[true, .., true] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[_, ..]` not covered | ||
[] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[_, _, ..]` not covered | ||
[] => {} | ||
[_] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[false, ..]` not covered | ||
[] => {} | ||
[true, ..] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[false, _, ..]` not covered | ||
[] => {} | ||
[_] => {} | ||
[true, ..] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[_, .., false]` not covered | ||
[] => {} | ||
[_] => {} | ||
[.., true] => {} | ||
} | ||
|
||
match s { | ||
[true, ..] => {} | ||
[true, ..] => {} //~ ERROR unreachable pattern | ||
[true] => {} //~ ERROR unreachable pattern | ||
[..] => {} | ||
} | ||
match s { | ||
[.., true] => {} | ||
[.., true] => {} //~ ERROR unreachable pattern | ||
[true] => {} //~ ERROR unreachable pattern | ||
[..] => {} | ||
} | ||
match s { | ||
[false, .., true] => {} | ||
[false, .., true] => {} //~ ERROR unreachable pattern | ||
[false, true] => {} //~ ERROR unreachable pattern | ||
[false] => {} | ||
[..] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[_, _, .., true]` not covered | ||
[] => {} | ||
[_] => {} | ||
[_, _] => {} | ||
[.., false] => {} | ||
} | ||
match s { | ||
//~^ ERROR `&[true, _, .., _]` not covered | ||
[] => {} | ||
[_] => {} | ||
[_, _] => {} | ||
[false, .., false] => {} | ||
} | ||
} |
This file contains hidden or 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,133 @@ | ||
error[E0004]: non-exhaustive patterns: `&[false, true]` not covered | ||
--> $DIR/slice-patterns.rs:29:11 | ||
| | ||
LL | match s2 { | ||
| ^^ pattern `&[false, true]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[false, _, true]` not covered | ||
--> $DIR/slice-patterns.rs:34:11 | ||
| | ||
LL | match s3 { | ||
| ^^ pattern `&[false, _, true]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[false, .., true]` not covered | ||
--> $DIR/slice-patterns.rs:39:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[false, .., true]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[false, _, _]` not covered | ||
--> $DIR/slice-patterns.rs:46:11 | ||
| | ||
LL | match s3 { | ||
| ^^ pattern `&[false, _, _]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered | ||
--> $DIR/slice-patterns.rs:50:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[_, ..]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[_, _, ..]` not covered | ||
--> $DIR/slice-patterns.rs:54:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[_, _, ..]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[false, ..]` not covered | ||
--> $DIR/slice-patterns.rs:59:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[false, ..]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[false, _, ..]` not covered | ||
--> $DIR/slice-patterns.rs:64:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[false, _, ..]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[_, .., false]` not covered | ||
--> $DIR/slice-patterns.rs:70:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[_, .., false]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error: unreachable pattern | ||
--> $DIR/slice-patterns.rs:79:9 | ||
| | ||
LL | [true, ..] => {} | ||
| ^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/slice-patterns.rs:2:9 | ||
| | ||
LL | #![deny(unreachable_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/slice-patterns.rs:80:9 | ||
| | ||
LL | [true] => {} | ||
| ^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/slice-patterns.rs:85:9 | ||
| | ||
LL | [.., true] => {} | ||
| ^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/slice-patterns.rs:86:9 | ||
| | ||
LL | [true] => {} | ||
| ^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/slice-patterns.rs:91:9 | ||
| | ||
LL | [false, .., true] => {} | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/slice-patterns.rs:92:9 | ||
| | ||
LL | [false, true] => {} | ||
| ^^^^^^^^^^^^^ | ||
|
||
error[E0004]: non-exhaustive patterns: `&[_, _, .., true]` not covered | ||
--> $DIR/slice-patterns.rs:96:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[_, _, .., true]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error[E0004]: non-exhaustive patterns: `&[true, _, .., _]` not covered | ||
--> $DIR/slice-patterns.rs:103:11 | ||
| | ||
LL | match s { | ||
| ^ pattern `&[true, _, .., _]` not covered | ||
| | ||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms | ||
|
||
error: aborting due to 17 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0004`. |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.