summary refs log tree commit diff
path: root/src/test/ui/or-patterns/consistent-bindings.rs
blob: 0eb539dca4cba86540957d90630c98df19d92b9a (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
// Check that or-patterns with consistent bindings across arms are allowed.

// edition:2018

#![feature(or_patterns)]
//~^ WARN the feature `or_patterns` is incomplete

fn main() {
    // One level:
    let Ok(a) | Err(a) = Ok(0);
    let Ok(ref a) | Err(ref a) = Ok(0);
    let Ok(ref mut a) | Err(ref mut a) = Ok(0);

    // Two levels:
    enum Tri<S, T, U> { V1(S), V2(T), V3(U) }
    use Tri::*;

    let Ok((V1(a) | V2(a) | V3(a), b)) | Err(Ok((a, b)) | Err((a, b)))
        : Result<_, Result<_, _>>
        = Ok((V1(1), 1));

    let Ok((V1(a) | V2(a) | V3(a), ref b)) | Err(Ok((a, ref b)) | Err((a, ref b)))
        : Result<_, Result<_, _>>
        = Ok((V1(1), 1));

    // Three levels:
    let (
            a,
            Err((ref mut b, ref c, d)) |
            Ok((
                Ok(
                    V1((ref c, d)) |
                    V2((d, ref c)) |
                    V3((ref c, Ok((_, d)) | Err((d, _))))
                ) |
                Err((ref c, d)),
                ref mut b
            ))
        ) =
        (1, Ok((Ok(V3((1, Ok((1, 1))))), 1)));

    // FIXME(or_patterns; Centril | dlrobertson): remove this line below and
    // change this test to check-pass once MIR can handle or-patterns with bindings.
    let () = 0;
    //~^ ERROR mismatched types
}