]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/rest-pat-semantic-disallowed.rs
Auto merge of #63124 - Centril:rollup-onohtqt, r=Centril
[rust.git] / src / test / ui / pattern / rest-pat-semantic-disallowed.rs
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
5 #![feature(slice_patterns, box_patterns)]
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
34     let ref x @ ..; //~ ERROR `..` patterns are not allowed here
35     let ref mut x @ ..; //~ ERROR `..` patterns are not allowed here
36
37     // Tuple:
38     let (..): (u8,); // OK.
39     let (..,): (u8,); // OK.
40     let (
41         ..,
42         .., //~ ERROR `..` can only be used once per tuple pattern
43         .. //~ ERROR `..` can only be used once per tuple pattern
44     ): (u8, u8, u8);
45     let (
46         ..,
47         x,
48         .. //~ ERROR `..` can only be used once per tuple pattern
49     ): (u8, u8, u8);
50
51     struct A(u8, u8, u8);
52
53     // Tuple struct (same idea as for tuple patterns):
54     let A(..); // OK.
55     let A(..,); // OK.
56     let A(
57         ..,
58         .., //~ ERROR `..` can only be used once per tuple struct pattern
59         .. //~ ERROR `..` can only be used once per tuple struct pattern
60     );
61     let A(
62         ..,
63         x,
64         .. //~ ERROR `..` can only be used once per tuple struct pattern
65     );
66
67     // Array/Slice:
68     let [..]: &[u8]; // OK.
69     let [..,]: &[u8]; // OK.
70     let [
71         ..,
72         .., //~ ERROR `..` can only be used once per slice pattern
73         .. //~ ERROR `..` can only be used once per slice pattern
74     ]: &[u8];
75     let [
76         ..,
77         ref x @ .., //~ ERROR `..` can only be used once per slice pattern
78         ref mut y @ .., //~ ERROR `..` can only be used once per slice pattern
79         (ref z @ ..), //~ ERROR `..` patterns are not allowed here
80         .. //~ ERROR `..` can only be used once per slice pattern
81     ]: &[u8];
82 }