add test, bless tests

This commit is contained in:
b-naber 2023-06-21 18:01:31 +00:00
parent 2827aa9752
commit e18e3761ce
7 changed files with 74 additions and 49 deletions

View File

@ -1,4 +1,4 @@
// see issue #70529
// check-pass
struct A;
impl From<A> for [u8; 2] {
@ -13,9 +13,7 @@ impl From<A> for [u8; 3] {
}
}
fn main() {
let a = A;
let [_, _] = a.into();
//~^ ERROR type annotations needed
}

View File

@ -1,14 +0,0 @@
error[E0282]: type annotations needed
--> $DIR/infer_array_len.rs:19:9
|
LL | let [_, _] = a.into();
| ^^^^^^
|
help: consider giving this pattern a type
|
LL | let [_, _]: /* Type */ = a.into();
| ++++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.

View File

@ -2,7 +2,7 @@ fn main() {
match "foo".to_string() {
['f', 'o', ..] => {}
//~^ ERROR expected an array or slice, found `String`
_ => { }
_ => {}
};
// Note that this one works with default binding modes.
@ -15,7 +15,7 @@ fn main() {
};
match [0, 1, 2] {
[0] => {}, //~ ERROR pattern requires
[0] => {} //~ ERROR pattern requires
[0, 1, x @ ..] => {
let a: [_; 1] = x;
@ -23,14 +23,16 @@ fn main() {
[0, 1, 2, 3, x @ ..] => {} //~ ERROR pattern requires
};
match does_not_exist { //~ ERROR cannot find value `does_not_exist` in this scope
[] => {}
match does_not_exist {
//~^ ERROR cannot find value `does_not_exist` in this scope
[] => {} // ERROR cannot find value `does_not_exist` in this scope
};
}
fn another_fn_to_avoid_suppression() {
match Default::default()
match Default
//~^ ERROR expected value, found trait
{
[] => {} //~ ERROR type annotations needed
[] => {}
};
}

View File

@ -4,6 +4,12 @@ error[E0425]: cannot find value `does_not_exist` in this scope
LL | match does_not_exist {
| ^^^^^^^^^^^^^^ not found in this scope
error[E0423]: expected value, found trait `Default`
--> $DIR/slice-pat-type-mismatches.rs:33:11
|
LL | match Default
| ^^^^^^^ not a value
error[E0529]: expected an array or slice, found `String`
--> $DIR/slice-pat-type-mismatches.rs:3:9
|
@ -13,7 +19,7 @@ LL | ['f', 'o', ..] => {}
error[E0527]: pattern requires 1 element but array has 3
--> $DIR/slice-pat-type-mismatches.rs:18:9
|
LL | [0] => {},
LL | [0] => {}
| ^^^ expected 3 elements
error[E0528]: pattern requires at least 4 elements but array has 3
@ -22,13 +28,7 @@ error[E0528]: pattern requires at least 4 elements but array has 3
LL | [0, 1, 2, 3, x @ ..] => {}
| ^^^^^^^^^^^^^^^^^^^^ pattern cannot match array of 3 elements
error[E0282]: type annotations needed
--> $DIR/slice-pat-type-mismatches.rs:34:9
|
LL | [] => {}
| ^^ cannot infer type
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0282, E0425, E0527, E0528, E0529.
For more information about an error, try `rustc --explain E0282`.
Some errors have detailed explanations: E0423, E0425, E0527, E0528, E0529.
For more information about an error, try `rustc --explain E0423`.

View File

@ -1,6 +1,10 @@
fn main() {
let (mut a, mut b);
[a, .., b, ..] = [0, 1]; //~ ERROR `..` can only be used once per slice pattern
[a, a, b] = [1, 2]; //~ ERROR pattern requires 3 elements but array has 2
[_] = [1, 2]; //~ ERROR pattern requires 1 element but array has 2
[a, a, b] = [1, 2];
//~^ ERROR pattern requires 3 elements but array has 2
//~| ERROR mismatched types
[_] = [1, 2];
//~^ ERROR pattern requires 1 element but array has 2
//~| ERROR mismatched types
}

View File

@ -1,23 +1,42 @@
error: `..` can only be used once per slice pattern
--> $DIR/slice_destructure_fail.rs:3:14
--> $DIR/slice_destructure_fail.rs:3:16
|
LL | [a, .., b, ..] = [0, 1];
| -- ^^ can only be used once per slice pattern
| |
| previously used here
error[E0308]: mismatched types
--> $DIR/slice_destructure_fail.rs:4:5
|
LL | [a, a, b] = [1, 2];
| ^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
|
= note: expected array `[{integer}; 2]`
found array `[_; 3]`
error[E0527]: pattern requires 3 elements but array has 2
--> $DIR/slice_destructure_fail.rs:4:3
--> $DIR/slice_destructure_fail.rs:4:5
|
LL | [a, a, b] = [1, 2];
| ^^^^^^^^^ expected 2 elements
error[E0308]: mismatched types
--> $DIR/slice_destructure_fail.rs:7:5
|
LL | [_] = [1, 2];
| ^^^ expected an array with a fixed size of 2 elements, found one with 1 element
|
= note: expected array `[{integer}; 2]`
found array `[_; 1]`
error[E0527]: pattern requires 1 element but array has 2
--> $DIR/slice_destructure_fail.rs:5:3
--> $DIR/slice_destructure_fail.rs:7:5
|
LL | [_] = [1, 2];
| ^^^ expected 2 elements
error: aborting due to 3 previous errors
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0527`.
Some errors have detailed explanations: E0308, E0527.
For more information about an error, try `rustc --explain E0308`.

View File

@ -0,0 +1,16 @@
// check-pass
#![allow(unused_variables)]
struct Zeroes;
impl Into<[usize; 2]> for Zeroes {
fn into(self) -> [usize; 2] { [0; 2] }
}
impl Into<[usize; 3]> for Zeroes {
fn into(self) -> [usize; 3] { [0; 3] }
}
impl Into<[usize; 4]> for Zeroes {
fn into(self) -> [usize; 4] { [0; 4] }
}
fn main() {
let [a, b, c] = Zeroes.into(); // ERROR: type annotations needed
let [d, e, f]: [_; 3] = Zeroes.into(); // Works great
}