Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e18e376

Browse files
committed
add test, bless tests
1 parent 2827aa9 commit e18e376

File tree

7 files changed

+74
-49
lines changed

7 files changed

+74
-49
lines changed

tests/ui/array-slice-vec/infer_array_len.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// see issue #70529
1+
// check-pass
22
struct A;
33

44
impl From<A> for [u8; 2] {
@@ -13,9 +13,7 @@ impl From<A> for [u8; 3] {
1313
}
1414
}
1515

16-
1716
fn main() {
1817
let a = A;
1918
let [_, _] = a.into();
20-
//~^ ERROR type annotations needed
2119
}

tests/ui/array-slice-vec/infer_array_len.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/array-slice-vec/slice-pat-type-mismatches.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main() {
22
match "foo".to_string() {
33
['f', 'o', ..] => {}
44
//~^ ERROR expected an array or slice, found `String`
5-
_ => { }
5+
_ => {}
66
};
77

88
// Note that this one works with default binding modes.
@@ -15,22 +15,24 @@ fn main() {
1515
};
1616

1717
match [0, 1, 2] {
18-
[0] => {}, //~ ERROR pattern requires
18+
[0] => {} //~ ERROR pattern requires
1919

2020
[0, 1, x @ ..] => {
2121
let a: [_; 1] = x;
2222
}
2323
[0, 1, 2, 3, x @ ..] => {} //~ ERROR pattern requires
2424
};
2525

26-
match does_not_exist { //~ ERROR cannot find value `does_not_exist` in this scope
27-
[] => {}
26+
match does_not_exist {
27+
//~^ ERROR cannot find value `does_not_exist` in this scope
28+
[] => {} // ERROR cannot find value `does_not_exist` in this scope
2829
};
2930
}
3031

3132
fn another_fn_to_avoid_suppression() {
32-
match Default::default()
33+
match Default
34+
//~^ ERROR expected value, found trait
3335
{
34-
[] => {} //~ ERROR type annotations needed
36+
[] => {}
3537
};
3638
}

tests/ui/array-slice-vec/slice-pat-type-mismatches.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ error[E0425]: cannot find value `does_not_exist` in this scope
44
LL | match does_not_exist {
55
| ^^^^^^^^^^^^^^ not found in this scope
66

7+
error[E0423]: expected value, found trait `Default`
8+
--> $DIR/slice-pat-type-mismatches.rs:33:11
9+
|
10+
LL | match Default
11+
| ^^^^^^^ not a value
12+
713
error[E0529]: expected an array or slice, found `String`
814
--> $DIR/slice-pat-type-mismatches.rs:3:9
915
|
@@ -13,7 +19,7 @@ LL | ['f', 'o', ..] => {}
1319
error[E0527]: pattern requires 1 element but array has 3
1420
--> $DIR/slice-pat-type-mismatches.rs:18:9
1521
|
16-
LL | [0] => {},
22+
LL | [0] => {}
1723
| ^^^ expected 3 elements
1824

1925
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
2228
LL | [0, 1, 2, 3, x @ ..] => {}
2329
| ^^^^^^^^^^^^^^^^^^^^ pattern cannot match array of 3 elements
2430

25-
error[E0282]: type annotations needed
26-
--> $DIR/slice-pat-type-mismatches.rs:34:9
27-
|
28-
LL | [] => {}
29-
| ^^ cannot infer type
30-
3131
error: aborting due to 5 previous errors
3232

33-
Some errors have detailed explanations: E0282, E0425, E0527, E0528, E0529.
34-
For more information about an error, try `rustc --explain E0282`.
33+
Some errors have detailed explanations: E0423, E0425, E0527, E0528, E0529.
34+
For more information about an error, try `rustc --explain E0423`.
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
fn main() {
2-
let (mut a, mut b);
3-
[a, .., b, ..] = [0, 1]; //~ ERROR `..` can only be used once per slice pattern
4-
[a, a, b] = [1, 2]; //~ ERROR pattern requires 3 elements but array has 2
5-
[_] = [1, 2]; //~ ERROR pattern requires 1 element but array has 2
2+
let (mut a, mut b);
3+
[a, .., b, ..] = [0, 1]; //~ ERROR `..` can only be used once per slice pattern
4+
[a, a, b] = [1, 2];
5+
//~^ ERROR pattern requires 3 elements but array has 2
6+
//~| ERROR mismatched types
7+
[_] = [1, 2];
8+
//~^ ERROR pattern requires 1 element but array has 2
9+
//~| ERROR mismatched types
610
}
Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
error: `..` can only be used once per slice pattern
2-
--> $DIR/slice_destructure_fail.rs:3:14
2+
--> $DIR/slice_destructure_fail.rs:3:16
33
|
4-
LL | [a, .., b, ..] = [0, 1];
5-
| -- ^^ can only be used once per slice pattern
6-
| |
7-
| previously used here
4+
LL | [a, .., b, ..] = [0, 1];
5+
| -- ^^ can only be used once per slice pattern
6+
| |
7+
| previously used here
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/slice_destructure_fail.rs:4:5
11+
|
12+
LL | [a, a, b] = [1, 2];
13+
| ^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
14+
|
15+
= note: expected array `[{integer}; 2]`
16+
found array `[_; 3]`
817

918
error[E0527]: pattern requires 3 elements but array has 2
10-
--> $DIR/slice_destructure_fail.rs:4:3
19+
--> $DIR/slice_destructure_fail.rs:4:5
20+
|
21+
LL | [a, a, b] = [1, 2];
22+
| ^^^^^^^^^ expected 2 elements
23+
24+
error[E0308]: mismatched types
25+
--> $DIR/slice_destructure_fail.rs:7:5
26+
|
27+
LL | [_] = [1, 2];
28+
| ^^^ expected an array with a fixed size of 2 elements, found one with 1 element
1129
|
12-
LL | [a, a, b] = [1, 2];
13-
| ^^^^^^^^^ expected 2 elements
30+
= note: expected array `[{integer}; 2]`
31+
found array `[_; 1]`
1432

1533
error[E0527]: pattern requires 1 element but array has 2
16-
--> $DIR/slice_destructure_fail.rs:5:3
34+
--> $DIR/slice_destructure_fail.rs:7:5
1735
|
18-
LL | [_] = [1, 2];
19-
| ^^^ expected 2 elements
36+
LL | [_] = [1, 2];
37+
| ^^^ expected 2 elements
2038

21-
error: aborting due to 3 previous errors
39+
error: aborting due to 5 previous errors
2240

23-
For more information about this error, try `rustc --explain E0527`.
41+
Some errors have detailed explanations: E0308, E0527.
42+
For more information about an error, try `rustc --explain E0308`.

tests/ui/pattern/issue-76342.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
#![allow(unused_variables)]
3+
struct Zeroes;
4+
impl Into<[usize; 2]> for Zeroes {
5+
fn into(self) -> [usize; 2] { [0; 2] }
6+
}
7+
impl Into<[usize; 3]> for Zeroes {
8+
fn into(self) -> [usize; 3] { [0; 3] }
9+
}
10+
impl Into<[usize; 4]> for Zeroes {
11+
fn into(self) -> [usize; 4] { [0; 4] }
12+
}
13+
fn main() {
14+
let [a, b, c] = Zeroes.into(); // ERROR: type annotations needed
15+
let [d, e, f]: [_; 3] = Zeroes.into(); // Works great
16+
}

0 commit comments

Comments
 (0)