summaryrefslogtreecommitdiffstats
path: root/tests/ui/pattern/rest-pat-semantic-disallowed.rs
blob: 156285e0f9fc97356f5251ab7ff4254ce6dc4b73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Here we test that rest patterns, i.e. `..`, are not allowed
// outside of slice (+ ident patterns within those), tuple,
// and tuple struct patterns and that duplicates are caught in these contexts.

#![feature(box_patterns)]

fn main() {}

macro_rules! mk_pat {
    () => { .. } //~ ERROR `..` patterns are not allowed here
}

fn rest_patterns() {
    let mk_pat!();

    // Top level:
    fn foo(..: u8) {} //~ ERROR `..` patterns are not allowed here
    let ..;  //~ ERROR `..` patterns are not allowed here

    // Box patterns:
    let box ..;  //~ ERROR `..` patterns are not allowed here

    // In or-patterns:
    match 1 {
        1 | .. => {} //~ ERROR `..` patterns are not allowed here
    }

    // Ref patterns:
    let &..; //~ ERROR `..` patterns are not allowed here
    let &mut ..; //~ ERROR `..` patterns are not allowed here

    // Ident patterns:
    let x @ ..; //~ ERROR `..` patterns are not allowed here
    //~^ ERROR type annotations needed
    let ref x @ ..; //~ ERROR `..` patterns are not allowed here
    let ref mut x @ ..; //~ ERROR `..` patterns are not allowed here

    // Tuple:
    let (..): (u8,); // OK.
    let (..,): (u8,); // OK.
    let (
        ..,
        .., //~ ERROR `..` can only be used once per tuple pattern
        .. //~ ERROR `..` can only be used once per tuple pattern
    ): (u8, u8, u8);
    let (
        ..,
        x,
        .. //~ ERROR `..` can only be used once per tuple pattern
    ): (u8, u8, u8);

    struct A(u8, u8, u8);

    // Tuple struct (same idea as for tuple patterns):
    let A(..); // OK.
    let A(..,); // OK.
    let A(
        ..,
        .., //~ ERROR `..` can only be used once per tuple struct pattern
        .. //~ ERROR `..` can only be used once per tuple struct pattern
    );
    let A(
        ..,
        x,
        .. //~ ERROR `..` can only be used once per tuple struct pattern
    );

    // Array/Slice:
    let [..]: &[u8]; // OK.
    let [..,]: &[u8]; // OK.
    let [
        ..,
        .., //~ ERROR `..` can only be used once per slice pattern
        .. //~ ERROR `..` can only be used once per slice pattern
    ]: &[u8];
    let [
        ..,
        ref x @ .., //~ ERROR `..` can only be used once per slice pattern
        ref mut y @ .., //~ ERROR `..` can only be used once per slice pattern
        (ref z @ ..), //~ ERROR `..` patterns are not allowed here
        .. //~ ERROR `..` can only be used once per slice pattern
    ]: &[u8];
}