Skip to content

Commit c37bd26

Browse files
committed
Test that _ @ subpat is syntactically rejected.
1 parent e39abcf commit c37bd26

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Here we check that `_ @ sub` is syntactically invalid
2+
// and comes with a nice actionable suggestion.
3+
4+
fn main() {}
5+
6+
#[cfg(FALSE)]
7+
fn wild_before_at_is_bad_syntax() {
8+
let _ @ a = 0;
9+
//~^ ERROR pattern on wrong side of `@`
10+
let _ @ ref a = 0;
11+
//~^ ERROR pattern on wrong side of `@`
12+
let _ @ ref mut a = 0;
13+
//~^ ERROR pattern on wrong side of `@`
14+
let _ @ (a, .., b) = (0, 1, 2, 3);
15+
//~^ ERROR left-hand side of `@` must be a binding
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error: pattern on wrong side of `@`
2+
--> $DIR/wild-before-at-syntactically-rejected.rs:8:9
3+
|
4+
LL | let _ @ a = 0;
5+
| -^^^-
6+
| | |
7+
| | binding on the right, should be on the left
8+
| pattern on the left, should be on the right
9+
| help: switch the order: `a @ _`
10+
11+
error: pattern on wrong side of `@`
12+
--> $DIR/wild-before-at-syntactically-rejected.rs:10:9
13+
|
14+
LL | let _ @ ref a = 0;
15+
| -^^^-----
16+
| | |
17+
| | binding on the right, should be on the left
18+
| pattern on the left, should be on the right
19+
| help: switch the order: `ref a @ _`
20+
21+
error: pattern on wrong side of `@`
22+
--> $DIR/wild-before-at-syntactically-rejected.rs:12:9
23+
|
24+
LL | let _ @ ref mut a = 0;
25+
| -^^^---------
26+
| | |
27+
| | binding on the right, should be on the left
28+
| pattern on the left, should be on the right
29+
| help: switch the order: `ref mut a @ _`
30+
31+
error: left-hand side of `@` must be a binding
32+
--> $DIR/wild-before-at-syntactically-rejected.rs:14:9
33+
|
34+
LL | let _ @ (a, .., b) = (0, 1, 2, 3);
35+
| -^^^----------
36+
| | |
37+
| | also a pattern
38+
| interpreted as a pattern, not a binding
39+
|
40+
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
41+
42+
error: aborting due to 4 previous errors
43+

0 commit comments

Comments
 (0)