summaryrefslogtreecommitdiffstats
path: root/src/test/ui/pattern/pat-tuple-underfield.rs
blob: dac60e3fab2c0038e2d617007f80bf23b65c4c86 (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
struct S(i32, f32);
enum E {
    S(i32, f32),
}
struct Point4(i32, i32, i32, i32);

fn main() {
    match S(0, 1.0) {
        S(x) => {}
        //~^ ERROR this pattern has 1 field, but the corresponding tuple struct has 2 fields
        //~| HELP use `_` to explicitly ignore each field
    }
    match S(0, 1.0) {
        S(_) => {}
        //~^ ERROR this pattern has 1 field, but the corresponding tuple struct has 2 fields
        //~| HELP use `_` to explicitly ignore each field
        //~| HELP use `..` to ignore all fields
    }
    match S(0, 1.0) {
        S() => {}
        //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields
        //~| HELP use `_` to explicitly ignore each field
        //~| HELP use `..` to ignore all fields

        // Test non-standard formatting
        S () => {}
        //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields
        //~| HELP use `_` to explicitly ignore each field
        //~| HELP use `..` to ignore all fields
    }

    match E::S(0, 1.0) {
        E::S(x) => {}
        //~^ ERROR this pattern has 1 field, but the corresponding tuple variant has 2 fields
        //~| HELP use `_` to explicitly ignore each field
    }
    match E::S(0, 1.0) {
        E::S(_) => {}
        //~^ ERROR this pattern has 1 field, but the corresponding tuple variant has 2 fields
        //~| HELP use `_` to explicitly ignore each field
        //~| HELP use `..` to ignore all fields
    }
    match E::S(0, 1.0) {
        E::S() => {}
        //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields
        //~| HELP use `_` to explicitly ignore each field
        //~| HELP use `..` to ignore all fields

        // Test non-standard formatting
        E::S () => {}
        //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields
        //~| HELP use `_` to explicitly ignore each field
        //~| HELP use `..` to ignore all fields
    }
    match E::S(0, 1.0) {
        E::S => {}
        //~^ ERROR expected unit struct, unit variant or constant, found tuple variant `E::S`
        //~| HELP use the tuple variant pattern syntax instead
    }

    match Point4(0, 1, 2, 3) {
        Point4(   a   ,     _    ) => {}
        //~^ ERROR this pattern has 2 fields, but the corresponding tuple struct has 4 fields
        //~| HELP use `_` to explicitly ignore each field
        //~| HELP use `..` to ignore the rest of the fields
    }
}