Skip to content

Commit e8198f6

Browse files
committed
Auto merge of #66129 - Nadrieril:refactor-slice-pat-usefulness, r=<try>
Refactor slice pattern usefulness checking This PR changes how variable-length slice patterns are handled in usefulness checking. The objectives are: cleaning up that code to make it easier to understand, and paving the way to handling fixed-length slices more cleverly too, for #53820. Before this, variable-length slice patterns were eagerly expanded into a union of fixed-length slices. Now they have their own special constructor, which allows expanding them a bit more lazily. As a nice side-effect, this improves diagnostics. This PR shows a slight performance improvement, mostly due to 149792b. This will probably have to be reverted in some way when we implement or-patterns.
2 parents 3a1b3b3 + 9531787 commit e8198f6

16 files changed

+536
-190
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 281 additions & 178 deletions
Large diffs are not rendered by default.

src/test/ui/consts/const_let_refutable.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0005]: refutable pattern in function argument: `&[]`, `&[_]` and `&[_, _, _]` not covered
1+
error[E0005]: refutable pattern in function argument: `&[]`, `&[_]` and `&[_, _, _, ..]` not covered
22
--> $DIR/const_let_refutable.rs:3:16
33
|
44
LL | const fn slice([a, b]: &[i32]) -> i32 {
5-
| ^^^^^^ patterns `&[]`, `&[_]` and `&[_, _, _]` not covered
5+
| ^^^^^^ patterns `&[]`, `&[_]` and `&[_, _, _, ..]` not covered
66

77
error[E0723]: can only call other `const fn` within a `const fn`, but `const <&i32 as std::ops::Add>::add` is not stable as `const fn`
88
--> $DIR/const_let_refutable.rs:4:5

src/test/ui/pattern/usefulness/match-byte-array-patterns-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | match buf {
66
|
77
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
88

9-
error[E0004]: non-exhaustive patterns: `&[]`, `&[_]`, `&[_, _]` and 3 more not covered
9+
error[E0004]: non-exhaustive patterns: `&[..]` not covered
1010
--> $DIR/match-byte-array-patterns-2.rs:10:11
1111
|
1212
LL | match buf {
13-
| ^^^ patterns `&[]`, `&[_]`, `&[_, _]` and 3 more not covered
13+
| ^^^ pattern `&[..]` not covered
1414
|
1515
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
1616

src/test/ui/pattern/usefulness/match-slice-patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
fn check(list: &[Option<()>]) {
44
match list {
5-
//~^ ERROR `&[_, Some(_), None, _]` not covered
5+
//~^ ERROR `&[_, Some(_), .., None, _]` not covered
66
&[] => {},
77
&[_] => {},
88
&[_, _] => {},

src/test/ui/pattern/usefulness/match-slice-patterns.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0004]: non-exhaustive patterns: `&[_, Some(_), None, _]` not covered
1+
error[E0004]: non-exhaustive patterns: `&[_, Some(_), .., None, _]` not covered
22
--> $DIR/match-slice-patterns.rs:4:11
33
|
44
LL | match list {
5-
| ^^^^ pattern `&[_, Some(_), None, _]` not covered
5+
| ^^^^ pattern `&[_, Some(_), .., None, _]` not covered
66
|
77
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
88

src/test/ui/pattern/usefulness/non-exhaustive-match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444
}
4545
let vec = vec![0.5f32];
4646
let vec: &[f32] = &vec;
47-
match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered
47+
match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _, ..]` not covered
4848
[0.1, 0.2, 0.3] => (),
4949
[0.1, 0.2] => (),
5050
[0.1] => (),

src/test/ui/pattern/usefulness/non-exhaustive-match.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ LL | match *vec {
6666
|
6767
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
6868

69-
error[E0004]: non-exhaustive patterns: `[_, _, _, _]` not covered
69+
error[E0004]: non-exhaustive patterns: `[_, _, _, _, ..]` not covered
7070
--> $DIR/non-exhaustive-match.rs:47:11
7171
|
7272
LL | match *vec {
73-
| ^^^^ pattern `[_, _, _, _]` not covered
73+
| ^^^^ pattern `[_, _, _, _, ..]` not covered
7474
|
7575
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
7676

0 commit comments

Comments
 (0)