update tests, improve variable names
This commit is contained in:
parent
40c5eefdcd
commit
a3df1db8ee
6 changed files with 40 additions and 12 deletions
|
@ -7,8 +7,8 @@ Example of erroneous code:
|
||||||
|
|
||||||
fn is_123<const N: usize>(x: [u32; N]) -> bool {
|
fn is_123<const N: usize>(x: [u32; N]) -> bool {
|
||||||
match x {
|
match x {
|
||||||
[1, 2, 3] => true, // error: cannot pattern-match on an
|
[1, 2, ..] => true, // error: cannot pattern-match on an
|
||||||
// array without a fixed length
|
// array without a fixed length
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1355,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let err = self.tcx.types.err;
|
let err = self.tcx.types.err;
|
||||||
let expected = self.structurally_resolved_type(span, expected);
|
let expected = self.structurally_resolved_type(span, expected);
|
||||||
let (element_ty, slice_ty, expected) = match expected.kind {
|
let (element_ty, slice_ty, inferred) = match expected.kind {
|
||||||
// An array, so we might have something like `let [a, b, c] = [0, 1, 2];`.
|
// An array, so we might have something like `let [a, b, c] = [0, 1, 2];`.
|
||||||
ty::Array(element_ty, len) => {
|
ty::Array(element_ty, len) => {
|
||||||
let min = before.len() as u64 + after.len() as u64;
|
let min = before.len() as u64 + after.len() as u64;
|
||||||
|
@ -1385,7 +1385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
for elt in after {
|
for elt in after {
|
||||||
self.check_pat(&elt, element_ty, def_bm, ti);
|
self.check_pat(&elt, element_ty, def_bm, ti);
|
||||||
}
|
}
|
||||||
expected
|
inferred
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type check the length of an array pattern.
|
/// Type check the length of an array pattern.
|
||||||
|
|
11
src/test/ui/array-slice-vec/match_arr_unknown_len.rs
Normal file
11
src/test/ui/array-slice-vec/match_arr_unknown_len.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#![feature(const_generics)]
|
||||||
|
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||||
|
|
||||||
|
fn is_123<const N: usize>(x: [u32; N]) -> bool {
|
||||||
|
match x {
|
||||||
|
[1, 2] => true, //~ ERROR mismatched types
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
20
src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
Normal file
20
src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||||
|
--> $DIR/match_arr_unknown_len.rs:1:12
|
||||||
|
|
|
||||||
|
LL | #![feature(const_generics)]
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/match_arr_unknown_len.rs:6:9
|
||||||
|
|
|
||||||
|
LL | [1, 2] => true,
|
||||||
|
| ^^^^^^ expected `2usize`, found `N`
|
||||||
|
|
|
||||||
|
= note: expected array `[u32; 2]`
|
||||||
|
found array `[u32; _]`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
fn is_123<const N: usize>(x: [u32; N]) -> bool {
|
fn is_123<const N: usize>(x: [u32; N]) -> bool {
|
||||||
match x {
|
match x {
|
||||||
[1, 2, 3] => true, //~ ERROR mismatched types
|
[1, 2, ..] => true, //~ ERROR cannot pattern-match on an array without a fixed length
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,12 @@ LL | #![feature(const_generics)]
|
||||||
|
|
|
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0730]: cannot pattern-match on an array without a fixed length
|
||||||
--> $DIR/E0730.rs:6:9
|
--> $DIR/E0730.rs:6:9
|
||||||
|
|
|
|
||||||
LL | [1, 2, 3] => true,
|
LL | [1, 2, ..] => true,
|
||||||
| ^^^^^^^^^ expected `3usize`, found `N`
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
= note: expected array `[u32; 3]`
|
|
||||||
found array `[u32; _]`
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0730`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue