]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // Here we test that rest patterns, i.e. `..`, are not allowed |
2 | // outside of slice (+ ident patterns witin those), tuple, | |
3 | // and tuple struct patterns and that duplicates are caught in these contexts. | |
4 | ||
74b04a01 | 5 | #![feature(box_patterns)] |
416331ca XL |
6 | |
7 | fn main() {} | |
8 | ||
9 | macro_rules! mk_pat { | |
10 | () => { .. } //~ ERROR `..` patterns are not allowed here | |
11 | } | |
12 | ||
13 | fn rest_patterns() { | |
14 | let mk_pat!(); | |
15 | ||
16 | // Top level: | |
17 | fn foo(..: u8) {} //~ ERROR `..` patterns are not allowed here | |
18 | let ..; //~ ERROR `..` patterns are not allowed here | |
19 | ||
20 | // Box patterns: | |
21 | let box ..; //~ ERROR `..` patterns are not allowed here | |
22 | ||
23 | // In or-patterns: | |
24 | match 1 { | |
25 | 1 | .. => {} //~ ERROR `..` patterns are not allowed here | |
26 | } | |
27 | ||
28 | // Ref patterns: | |
29 | let &..; //~ ERROR `..` patterns are not allowed here | |
30 | let &mut ..; //~ ERROR `..` patterns are not allowed here | |
31 | ||
32 | // Ident patterns: | |
33 | let x @ ..; //~ ERROR `..` patterns are not allowed here | |
e74abb32 | 34 | //~^ ERROR type annotations needed |
416331ca XL |
35 | let ref x @ ..; //~ ERROR `..` patterns are not allowed here |
36 | let ref mut x @ ..; //~ ERROR `..` patterns are not allowed here | |
37 | ||
38 | // Tuple: | |
39 | let (..): (u8,); // OK. | |
40 | let (..,): (u8,); // OK. | |
41 | let ( | |
42 | .., | |
43 | .., //~ ERROR `..` can only be used once per tuple pattern | |
44 | .. //~ ERROR `..` can only be used once per tuple pattern | |
45 | ): (u8, u8, u8); | |
46 | let ( | |
47 | .., | |
48 | x, | |
49 | .. //~ ERROR `..` can only be used once per tuple pattern | |
50 | ): (u8, u8, u8); | |
51 | ||
52 | struct A(u8, u8, u8); | |
53 | ||
54 | // Tuple struct (same idea as for tuple patterns): | |
55 | let A(..); // OK. | |
56 | let A(..,); // OK. | |
57 | let A( | |
58 | .., | |
59 | .., //~ ERROR `..` can only be used once per tuple struct pattern | |
60 | .. //~ ERROR `..` can only be used once per tuple struct pattern | |
61 | ); | |
62 | let A( | |
63 | .., | |
64 | x, | |
65 | .. //~ ERROR `..` can only be used once per tuple struct pattern | |
66 | ); | |
67 | ||
68 | // Array/Slice: | |
69 | let [..]: &[u8]; // OK. | |
70 | let [..,]: &[u8]; // OK. | |
71 | let [ | |
72 | .., | |
73 | .., //~ ERROR `..` can only be used once per slice pattern | |
74 | .. //~ ERROR `..` can only be used once per slice pattern | |
75 | ]: &[u8]; | |
76 | let [ | |
77 | .., | |
78 | ref x @ .., //~ ERROR `..` can only be used once per slice pattern | |
79 | ref mut y @ .., //~ ERROR `..` can only be used once per slice pattern | |
80 | (ref z @ ..), //~ ERROR `..` patterns are not allowed here | |
81 | .. //~ ERROR `..` can only be used once per slice pattern | |
82 | ]: &[u8]; | |
83 | } |