Skip to content

Commit 087adfe

Browse files
committed
Ungate improved slice patterns diagnostics
1 parent 34b0774 commit 087adfe

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,19 +1209,10 @@ impl<'tcx> Constructor<'tcx> {
12091209
}
12101210
VarLenSlice(prefix_len, _suffix_len) => match ty.kind {
12111211
ty::Slice(ty) | ty::Array(ty, _) => {
1212-
if cx.tcx.features().slice_patterns {
1213-
let prefix = pats.by_ref().take(prefix_len as usize).collect();
1214-
let suffix = pats.collect();
1215-
let wild = Pat { ty, span: DUMMY_SP, kind: Box::new(PatKind::Wild) };
1216-
PatKind::Slice { prefix, slice: Some(wild), suffix }
1217-
} else {
1218-
// We don't want to output a variable-length slice pattern if the
1219-
// slice_patterns feature is not enabled.
1220-
// The constructor covers infinitely many slice lengths, but for diagnostic
1221-
// purposes it is correct to return only some examples of non-covered
1222-
// patterns. So we just return the smallest length pattern here.
1223-
PatKind::Slice { prefix: pats.collect(), slice: None, suffix: vec![] }
1224-
}
1212+
let prefix = pats.by_ref().take(prefix_len as usize).collect();
1213+
let suffix = pats.collect();
1214+
let wild = Pat { ty, span: DUMMY_SP, kind: Box::new(PatKind::Wild) };
1215+
PatKind::Slice { prefix, slice: Some(wild), suffix }
12251216
}
12261217
_ => bug!("bad slice pattern {:?} {:?}", self, ty),
12271218
},

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: `&[]` 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-
| ^^^ pattern `&[]` 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/uninhabited/uninhabited-matches-feature-gated.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ LL | let _ = match x {};
3030
|
3131
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
3232

33-
error[E0004]: non-exhaustive patterns: `&[_]` not covered
33+
error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered
3434
--> $DIR/uninhabited-matches-feature-gated.rs:21:19
3535
|
3636
LL | let _ = match x {
37-
| ^ pattern `&[_]` not covered
37+
| ^ pattern `&[_, ..]` not covered
3838
|
3939
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
4040

0 commit comments

Comments
 (0)