summaryrefslogtreecommitdiffstats
path: root/tests/ui/or-patterns/missing-bindings.rs
blob: 7c26012c0e93df075abbd604635f92bc0b680803 (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
// This test ensures that or patterns do not allow missing bindings in any of the arms.

// edition:2018

#![allow(non_camel_case_types)]

fn main() {}

fn check_handling_of_paths() {
    mod bar {
        pub enum foo {
            alpha,
            beta,
            charlie
        }
    }

    use bar::foo::{alpha, charlie};
    let (alpha | beta | charlie) = alpha; //~  ERROR variable `beta` is not bound in all patterns
    match Some(alpha) {
        Some(alpha | beta) => {} //~ ERROR variable `beta` is not bound in all patterns
    }
}

fn check_misc_nesting() {
    enum E<T> { A(T, T), B(T) }
    use E::*;
    enum Vars3<S, T, U> { V1(S), V2(T), V3(U) }
    use Vars3::*;

    // One level:
    const X: E<u8> = B(0);
    let (A(a, _) | _) = X; //~ ERROR variable `a` is not bound in all patterns
    let (_ | B(a)) = X; //~ ERROR variable `a` is not bound in all patterns
    let (A(..) | B(a)) = X; //~ ERROR variable `a` is not bound in all patterns
    let (A(a, _) | B(_)) = X; //~ ERROR variable `a` is not bound in all patterns
    let (A(_, a) | B(_)) = X; //~ ERROR variable `a` is not bound in all patterns
    let (A(a, b) | B(a)) = X; //~ ERROR variable `b` is not bound in all patterns

    // Two levels:
    const Y: E<E<u8>> = B(B(0));
    let (A(A(..) | B(_), _) | B(a)) = Y; //~ ERROR variable `a` is not bound in all patterns
    let (A(A(..) | B(a), _) | B(A(a, _) | B(a))) = Y;
    //~^ ERROR variable `a` is not bound in all patterns
    let (A(A(a, b) | B(c), d) | B(e)) = Y;
    //~^ ERROR variable `a` is not bound in all patterns
    //~| ERROR variable `a` is not bound in all patterns
    //~| ERROR variable `b` is not bound in all patterns
    //~| ERROR variable `b` is not bound in all patterns
    //~| ERROR variable `c` is not bound in all patterns
    //~| ERROR variable `c` is not bound in all patterns
    //~| ERROR variable `d` is not bound in all patterns
    //~| ERROR variable `e` is not bound in all patterns

    // Three levels:
    let (
            V1(
            //~^ ERROR variable `b` is not bound in all patterns
            //~| ERROR variable `c` is not bound in all patterns
                A(
                    Ok(a) | Err(_), //~ ERROR variable `a` is not bound in all patterns
                    _
                ) |
                B(Ok(a) | Err(a))
            ) |
            V2(
                A(
                    A(_, a) | //~ ERROR variable `b` is not bound in all patterns
                    B(b), //~ ERROR variable `a` is not bound in all patterns
                    _
                ) |
                B(_)
                //~^ ERROR variable `a` is not bound in all patterns
                //~| ERROR variable `b` is not bound in all patterns
            ) |
            V3(c),
            //~^ ERROR variable `a` is not bound in all patterns
        )
        : (Vars3<E<Result<u8, u8>>, E<E<u8>>, u8>,)
        = (V3(0),);
}