File: recover-pat-exprs.rs

package info (click to toggle)
rustc 1.87.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 925,564 kB
  • sloc: xml: 158,127; python: 36,039; javascript: 19,761; sh: 19,737; cpp: 18,981; ansic: 13,133; asm: 4,376; makefile: 710; perl: 29; lisp: 28; ruby: 19; sql: 11
file content (106 lines) | stat: -rw-r--r-- 4,296 bytes parent folder | download | duplicates (7)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// FieldExpression, TupleIndexingExpression
fn field_access() {
    match 0 {
        x => (),
        x.y => (), //~ error: expected a pattern, found an expression
        x.0 => (), //~ error: expected a pattern, found an expression
        x._0 => (), //~ error: expected a pattern, found an expression
        x.0.1 => (), //~ error: expected a pattern, found an expression
        x.4.y.17.__z => (), //~ error: expected a pattern, found an expression
    }

    { let x.0e0; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
    { let x.-0.0; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
    { let x.-0; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`

    { let x.0u32; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
    { let x.0.0_f64; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
}

// IndexExpression, ArrayExpression
fn array_indexing() {
    match 0 {
        x[0] => (), //~ error: expected a pattern, found an expression
        x[..] => (), //~ error: expected a pattern, found an expression
    }

    { let x[0, 1, 2]; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
    { let x[0; 20]; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
    { let x[]; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
    { let (x[]); } //~ error: expected one of `)`, `,`, `@`, `if`, or `|`, found `[`
    //~^ missing `,`
}

// MethodCallExpression, CallExpression, ErrorPropagationExpression
fn method_call() {
    match 0 {
        x.f() => (), //~ error: expected a pattern, found an expression
        x._f() => (), //~ error: expected a pattern, found an expression
        x? => (), //~ error: expected a pattern, found an expression
        ().f() => (), //~ error: expected a pattern, found an expression
        (0, x)?.f() => (), //~ error: expected a pattern, found an expression
        x.f().g() => (), //~ error: expected a pattern, found an expression
        0.f()?.g()?? => (), //~ error: expected a pattern, found an expression
    }
}

// TypeCastExpression
fn type_cast() {
    match 0 {
        x as usize => (), //~ error: expected a pattern, found an expression
        0 as usize => (), //~ error: expected a pattern, found an expression
        x.f().0.4 as f32 => (), //~ error: expected a pattern, found an expression
    }
}

// ArithmeticOrLogicalExpression, also check if parentheses are added as needed
fn operator() {
    match 0 {
        1 + 1 => (), //~ error: expected a pattern, found an expression
        (1 + 2) * 3 => (),
        //~^ error: expected a pattern, found an expression
        //~| error: expected a pattern, found an expression
        x.0 > 2 => (), //~ error: expected a pattern, found an expression
        x.0 == 2 => (), //~ error: expected a pattern, found an expression
    }

    // preexisting match arm guard
    match (0, 0) {
        (x, y.0 > 2) if x != 0 => (), //~ error: expected a pattern, found an expression
        (x, y.0 > 2) if x != 0 || x != 1 => (), //~ error: expected a pattern, found an expression
    }
}

const _: u32 = match 12 {
    1 + 2 * PI.cos() => 2, //~ error: expected a pattern, found an expression
    _ => 0,
};

fn main() {
    match u8::MAX {
        u8::MAX.abs() => (),
        //~^ error: expected a pattern, found an expression
        x.sqrt() @ .. => (),
        //~^ error: expected a pattern, found an expression
        //~| error: left-hand side of `@` must be a binding
        z @ w @ v.u() => (),
        //~^ error: expected a pattern, found an expression
        y.ilog(3) => (),
        //~^ error: expected a pattern, found an expression
        n + 1 => (),
        //~^ error: expected a pattern, found an expression
        ("".f() + 14 * 8) => (),
        //~^ error: expected a pattern, found an expression
        0 | ((1) | 2) | 3 => (),
        f?() => (),
        //~^ error: expected a pattern, found an expression
        (_ + 1) => (),
        //~^ error: expected one of `)`, `,`, `if`, or `|`, found `+`
    }

    let 1 + 1 = 2;
    //~^ error: expected a pattern, found an expression

    let b = matches!(x, (x * x | x.f()) | x[0]);
    //~^ error: expected one of `)`, `,`, `@`, `if`, or `|`, found `*`
}