Skip to content

Commit 27e43ae

Browse files
committed
Add tests
1 parent 330b181 commit 27e43ae

18 files changed

+267
-44
lines changed

src/test/ui/bad/bad-expr-lhs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
fn main() {
22
1 = 2; //~ ERROR invalid left-hand side of assignment
33
1 += 2; //~ ERROR invalid left-hand side of assignment
4-
(1, 2) = (3, 4); //~ ERROR invalid left-hand side of assignment
4+
(1, 2) = (3, 4); //~ ERROR destructuring assignments are unstable
5+
//~| ERROR invalid left-hand side of assignment
6+
//~| ERROR invalid left-hand side of assignment
57

68
let (a, b) = (1, 2);
79
(a, b) = (3, 4); //~ ERROR destructuring assignments are unstable

src/test/ui/bad/bad-expr-lhs.stderr

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,53 @@ LL | 1 += 2;
1414
| |
1515
| cannot assign to this expression
1616

17-
error[E0070]: invalid left-hand side of assignment
17+
error[E0658]: destructuring assignments are unstable
1818
--> $DIR/bad-expr-lhs.rs:4:12
1919
|
2020
LL | (1, 2) = (3, 4);
2121
| ------ ^
2222
| |
2323
| cannot assign to this expression
24+
|
25+
= note: see issue #372 <https://github.com/rust-lang/rust/issues/372> for more information
26+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
27+
28+
error[E0070]: invalid left-hand side of assignment
29+
--> $DIR/bad-expr-lhs.rs:4:12
30+
|
31+
LL | (1, 2) = (3, 4);
32+
| - ^
33+
| |
34+
| cannot assign to this expression
35+
36+
error[E0070]: invalid left-hand side of assignment
37+
--> $DIR/bad-expr-lhs.rs:4:12
38+
|
39+
LL | (1, 2) = (3, 4);
40+
| - ^
41+
| |
42+
| cannot assign to this expression
2443

2544
error[E0658]: destructuring assignments are unstable
26-
--> $DIR/bad-expr-lhs.rs:7:12
45+
--> $DIR/bad-expr-lhs.rs:9:12
2746
|
2847
LL | (a, b) = (3, 4);
29-
| ^
48+
| ------ ^
49+
| |
50+
| cannot assign to this expression
3051
|
52+
= note: see issue #372 <https://github.com/rust-lang/rust/issues/372> for more information
3153
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
3254

3355
error[E0070]: invalid left-hand side of assignment
34-
--> $DIR/bad-expr-lhs.rs:9:10
56+
--> $DIR/bad-expr-lhs.rs:11:10
3557
|
3658
LL | None = Some(3);
3759
| ---- ^
3860
| |
3961
| cannot assign to this expression
4062

41-
error: aborting due to 5 previous errors
63+
error: aborting due to 7 previous errors
4264

4365
Some errors have detailed explanations: E0067, E0070, E0658.
4466
For more information about an error, try `rustc --explain E0067`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass
2+
3+
#![feature(destructuring_assignment)]
4+
5+
struct Struct<S, T> {
6+
a: S,
7+
b: T,
8+
}
9+
10+
struct TupleStruct<S, T>(S, T);
11+
12+
fn main() {
13+
let (a, b, c, d);
14+
Struct { a: TupleStruct((a, b), c), b: [d] } =
15+
Struct { a: TupleStruct((0, 1), 2), b: [3] };
16+
assert_eq!((a, b, c, d), (0, 1, 2, 3));
17+
}

src/test/ui/destructuring-assignment/note-unsupported.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ fn main() {
44
let (a, b) = (1, 2);
55

66
(a, b) = (3, 4); //~ ERROR destructuring assignments are unstable
7-
(a, b) += (3, 4); //~ ERROR destructuring assignments are unstable
8-
//~^ ERROR binary assignment operation `+=` cannot be applied
7+
(a, b) += (3, 4); //~ ERROR invalid left-hand side of assignment
8+
//~| ERROR binary assignment operation `+=` cannot be applied
99

1010
[a, b] = [3, 4]; //~ ERROR destructuring assignments are unstable
11-
[a, b] += [3, 4]; //~ ERROR destructuring assignments are unstable
12-
//~^ ERROR binary assignment operation `+=` cannot be applied
11+
[a, b] += [3, 4]; //~ ERROR invalid left-hand side of assignment
12+
//~| ERROR binary assignment operation `+=` cannot be applied
1313

1414
let s = S { x: 3, y: 4 };
1515

1616
S { x: a, y: b } = s; //~ ERROR destructuring assignments are unstable
17-
S { x: a, y: b } += s; //~ ERROR destructuring assignments are unstable
18-
//~^ ERROR binary assignment operation `+=` cannot be applied
17+
S { x: a, y: b } += s; //~ ERROR invalid left-hand side of assignment
18+
//~| ERROR binary assignment operation `+=` cannot be applied
1919

20-
S { x: a, ..s } = S { x: 3, y: 4 }; //~ ERROR destructuring assignments are unstable
20+
S { x: a, ..s } = S { x: 3, y: 4 }; //~ ERROR invalid left-hand side of assignment
2121

2222
let c = 3;
2323

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
error[E0658]: destructuring assignments are unstable
2-
--> $DIR/destructuring-assignment.rs:6:12
2+
--> $DIR/note-unsupported.rs:6:12
33
|
44
LL | (a, b) = (3, 4);
5-
| ^
5+
| ------ ^
6+
| |
7+
| cannot assign to this expression
68
|
9+
= note: see issue #372 <https://github.com/rust-lang/rust/issues/372> for more information
710
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
811

912
error[E0368]: binary assignment operation `+=` cannot be applied to type `({integer}, {integer})`
@@ -14,20 +17,23 @@ LL | (a, b) += (3, 4);
1417
| |
1518
| cannot use `+=` on type `({integer}, {integer})`
1619

17-
error[E0658]: destructuring assignments are unstable
18-
--> $DIR/destructuring-assignment.rs:7:12
20+
error[E0067]: invalid left-hand side of assignment
21+
--> $DIR/note-unsupported.rs:7:12
1922
|
2023
LL | (a, b) += (3, 4);
21-
| ^^
22-
|
23-
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
24+
| ------ ^^
25+
| |
26+
| cannot assign to this expression
2427

2528
error[E0658]: destructuring assignments are unstable
26-
--> $DIR/destructuring-assignment.rs:10:12
29+
--> $DIR/note-unsupported.rs:10:12
2730
|
2831
LL | [a, b] = [3, 4];
29-
| ^
32+
| ------ ^
33+
| |
34+
| cannot assign to this expression
3035
|
36+
= note: see issue #372 <https://github.com/rust-lang/rust/issues/372> for more information
3137
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
3238

3339
error[E0368]: binary assignment operation `+=` cannot be applied to type `[{integer}; 2]`
@@ -38,20 +44,23 @@ LL | [a, b] += [3, 4];
3844
| |
3945
| cannot use `+=` on type `[{integer}; 2]`
4046

41-
error[E0658]: destructuring assignments are unstable
42-
--> $DIR/destructuring-assignment.rs:11:12
47+
error[E0067]: invalid left-hand side of assignment
48+
--> $DIR/note-unsupported.rs:11:12
4349
|
4450
LL | [a, b] += [3, 4];
45-
| ^^
46-
|
47-
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
51+
| ------ ^^
52+
| |
53+
| cannot assign to this expression
4854

4955
error[E0658]: destructuring assignments are unstable
50-
--> $DIR/destructuring-assignment.rs:16:22
56+
--> $DIR/note-unsupported.rs:16:22
5157
|
5258
LL | S { x: a, y: b } = s;
53-
| ^
59+
| ---------------- ^
60+
| |
61+
| cannot assign to this expression
5462
|
63+
= note: see issue #372 <https://github.com/rust-lang/rust/issues/372> for more information
5564
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
5665

5766
error[E0368]: binary assignment operation `+=` cannot be applied to type `S`
@@ -64,31 +73,34 @@ LL | S { x: a, y: b } += s;
6473
|
6574
= note: an implementation of `std::ops::AddAssign` might be missing for `S`
6675

67-
error[E0658]: destructuring assignments are unstable
68-
--> $DIR/destructuring-assignment.rs:17:22
76+
error[E0067]: invalid left-hand side of assignment
77+
--> $DIR/note-unsupported.rs:17:22
6978
|
7079
LL | S { x: a, y: b } += s;
71-
| ^^
72-
|
73-
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
80+
| ---------------- ^^
81+
| |
82+
| cannot assign to this expression
7483

75-
error[E0658]: destructuring assignments are unstable
76-
--> $DIR/destructuring-assignment.rs:20:21
84+
error[E0070]: invalid left-hand side of assignment
85+
--> $DIR/note-unsupported.rs:20:21
7786
|
7887
LL | S { x: a, ..s } = S { x: 3, y: 4 };
79-
| ^
80-
|
81-
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
88+
| --------------- ^
89+
| |
90+
| cannot assign to this expression
8291

8392
error[E0658]: destructuring assignments are unstable
84-
--> $DIR/destructuring-assignment.rs:24:17
93+
--> $DIR/note-unsupported.rs:24:17
8594
|
8695
LL | ((a, b), c) = ((3, 4), 5);
87-
| ^
96+
| ----------- ^
97+
| |
98+
| cannot assign to this expression
8899
|
100+
= note: see issue #372 <https://github.com/rust-lang/rust/issues/372> for more information
89101
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
90102

91103
error: aborting due to 11 previous errors
92104

93-
Some errors have detailed explanations: E0368, E0658.
94-
For more information about an error, try `rustc --explain E0368`.
105+
Some errors have detailed explanations: E0067, E0070, E0368, E0658.
106+
For more information about an error, try `rustc --explain E0067`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-pass
2+
3+
#![feature(destructuring_assignment)]
4+
5+
fn main() {
6+
let (mut a, mut b);
7+
[a, b] = [0, 1];
8+
assert_eq!((a,b), (0,1));
9+
[a, .., b] = [1,2];
10+
assert_eq!((a,b), (1,2));
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(destructuring_assignment)]
2+
3+
fn main() {
4+
let (mut a, mut b);
5+
[a, .., b, ..] = [0, 1]; //~ ERROR `..` can only be used once per slice pattern
6+
[a, a, b] = [1,2]; //~ ERROR pattern requires 3 elements but array has 2
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: `..` can only be used once per slice pattern
2+
--> $DIR/slice_destructure_fail.rs:5:14
3+
|
4+
LL | [a, .., b, ..] = [0, 1];
5+
| -- ^^ can only be used once per slice pattern
6+
| |
7+
| previously used here
8+
9+
error[E0527]: pattern requires 3 elements but array has 2
10+
--> $DIR/slice_destructure_fail.rs:6:3
11+
|
12+
LL | [a, a, b] = [1,2];
13+
| ^^^^^^^^^ expected 2 elements
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0527`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
3+
#![feature(destructuring_assignment)]
4+
struct Struct<S, T> {
5+
a: S,
6+
b: T,
7+
}
8+
9+
fn main() {
10+
let (a, b);
11+
Struct { a, b } = Struct { a: 0, b: 1 };
12+
assert_eq!((a, b), (0, 1));
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(destructuring_assignment)]
2+
struct Struct<S, T> {
3+
a: S,
4+
b: T,
5+
}
6+
7+
fn main() {
8+
let (mut a, b);
9+
let mut c;
10+
Struct { a, b, c } = Struct { a: 0, b: 1 }; //~ ERROR does not have a field named `c`
11+
}

0 commit comments

Comments
 (0)