Skip to content

Commit a3df1db

Browse files
committed
update tests, improve variable names
1 parent 40c5eef commit a3df1db

File tree

6 files changed

+40
-12
lines changed

6 files changed

+40
-12
lines changed

src/librustc_error_codes/error_codes/E0730.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Example of erroneous code:
77
88
fn is_123<const N: usize>(x: [u32; N]) -> bool {
99
match x {
10-
[1, 2, 3] => true, // error: cannot pattern-match on an
11-
// array without a fixed length
10+
[1, 2, ..] => true, // error: cannot pattern-match on an
11+
// array without a fixed length
1212
_ => false
1313
}
1414
}

src/librustc_typeck/check/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13551355
) -> Ty<'tcx> {
13561356
let err = self.tcx.types.err;
13571357
let expected = self.structurally_resolved_type(span, expected);
1358-
let (element_ty, slice_ty, expected) = match expected.kind {
1358+
let (element_ty, slice_ty, inferred) = match expected.kind {
13591359
// An array, so we might have something like `let [a, b, c] = [0, 1, 2];`.
13601360
ty::Array(element_ty, len) => {
13611361
let min = before.len() as u64 + after.len() as u64;
@@ -1385,7 +1385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13851385
for elt in after {
13861386
self.check_pat(&elt, element_ty, def_bm, ti);
13871387
}
1388-
expected
1388+
inferred
13891389
}
13901390

13911391
/// Type check the length of an array pattern.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_generics)]
2+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
4+
fn is_123<const N: usize>(x: [u32; N]) -> bool {
5+
match x {
6+
[1, 2] => true, //~ ERROR mismatched types
7+
_ => false
8+
}
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/match_arr_unknown_len.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/match_arr_unknown_len.rs:6:9
11+
|
12+
LL | [1, 2] => true,
13+
| ^^^^^^ expected `2usize`, found `N`
14+
|
15+
= note: expected array `[u32; 2]`
16+
found array `[u32; _]`
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/error-codes/E0730.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
fn is_123<const N: usize>(x: [u32; N]) -> bool {
55
match x {
6-
[1, 2, 3] => true, //~ ERROR mismatched types
6+
[1, 2, ..] => true, //~ ERROR cannot pattern-match on an array without a fixed length
77
_ => false
88
}
99
}

src/test/ui/error-codes/E0730.stderr

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9-
error[E0308]: mismatched types
9+
error[E0730]: cannot pattern-match on an array without a fixed length
1010
--> $DIR/E0730.rs:6:9
1111
|
12-
LL | [1, 2, 3] => true,
13-
| ^^^^^^^^^ expected `3usize`, found `N`
14-
|
15-
= note: expected array `[u32; 3]`
16-
found array `[u32; _]`
12+
LL | [1, 2, ..] => true,
13+
| ^^^^^^^^^^
1714

1815
error: aborting due to previous error
1916

20-
For more information about this error, try `rustc --explain E0308`.
17+
For more information about this error, try `rustc --explain E0730`.

0 commit comments

Comments
 (0)