Skip to content

Commit 15bc63e

Browse files
committed
Add syntactic test for rest patterns.
1 parent 8b94e9e commit 15bc63e

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Here we test that `..` is allowed in all pattern locations *syntactically*.
2+
// The semantic test is in `rest-pat-semantic-disallowed.rs`.
3+
4+
// check-pass
5+
6+
fn main() {}
7+
8+
macro_rules! accept_pat {
9+
($p:pat) => {}
10+
}
11+
12+
accept_pat!(..);
13+
14+
#[cfg(FALSE)]
15+
fn rest_patterns() {
16+
// Top level:
17+
fn foo(..: u8) {}
18+
let ..;
19+
20+
// Box patterns:
21+
let box ..;
22+
23+
// In or-patterns:
24+
match x {
25+
.. | .. => {}
26+
}
27+
28+
// Ref patterns:
29+
let &..;
30+
let &mut ..;
31+
32+
// Ident patterns:
33+
let x @ ..;
34+
let ref x @ ..;
35+
let ref mut x @ ..;
36+
37+
// Tuple:
38+
let (..); // This is interpreted as a tuple pattern, not a parenthesis one.
39+
let (..,); // Allowing trailing comma.
40+
let (.., .., ..); // Duplicates also.
41+
let (.., P, ..); // Including with things in between.
42+
43+
// Tuple struct (same idea as for tuple patterns):
44+
let A(..);
45+
let A(..,);
46+
let A(.., .., ..);
47+
let A(.., P, ..);
48+
49+
// Array/Slice (like with tuple patterns):
50+
let [..];
51+
let [..,];
52+
let [.., .., ..];
53+
let [.., P, ..];
54+
55+
// Random walk to guard against special casing:
56+
match x {
57+
.. |
58+
[
59+
(
60+
box ..,
61+
&(..),
62+
&mut ..,
63+
x @ ..
64+
),
65+
ref x @ ..,
66+
] |
67+
ref mut x @ ..
68+
=> {}
69+
}
70+
}

0 commit comments

Comments
 (0)