]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/missing-bindings.rs
Rollup merge of #80269 - pickfire:patch-4, r=joshtriplett
[rust.git] / src / test / ui / or-patterns / missing-bindings.rs
1 // This test ensures that or patterns do not allow missing bindings in any of the arms.
2
3 // edition:2018
4
5 #![allow(non_camel_case_types)]
6
7 fn main() {}
8
9 fn check_handling_of_paths() {
10     mod bar {
11         pub enum foo {
12             alpha,
13             beta,
14             charlie
15         }
16     }
17
18     use bar::foo::{alpha, charlie};
19     let (alpha | beta | charlie) = alpha; //~  ERROR variable `beta` is not bound in all patterns
20     match Some(alpha) {
21         Some(alpha | beta) => {} //~ ERROR variable `beta` is not bound in all patterns
22     }
23 }
24
25 fn check_misc_nesting() {
26     enum E<T> { A(T, T), B(T) }
27     use E::*;
28     enum Vars3<S, T, U> { V1(S), V2(T), V3(U) }
29     use Vars3::*;
30
31     // One level:
32     const X: E<u8> = B(0);
33     let (A(a, _) | _) = X; //~ ERROR variable `a` is not bound in all patterns
34     let (_ | B(a)) = X; //~ ERROR variable `a` is not bound in all patterns
35     let (A(..) | B(a)) = X; //~ ERROR variable `a` is not bound in all patterns
36     let (A(a, _) | B(_)) = X; //~ ERROR variable `a` is not bound in all patterns
37     let (A(_, a) | B(_)) = X; //~ ERROR variable `a` is not bound in all patterns
38     let (A(a, b) | B(a)) = X; //~ ERROR variable `b` is not bound in all patterns
39
40     // Two levels:
41     const Y: E<E<u8>> = B(B(0));
42     let (A(A(..) | B(_), _) | B(a)) = Y; //~ ERROR variable `a` is not bound in all patterns
43     let (A(A(..) | B(a), _) | B(A(a, _) | B(a))) = Y;
44     //~^ ERROR variable `a` is not bound in all patterns
45     let (A(A(a, b) | B(c), d) | B(e)) = Y;
46     //~^ ERROR variable `a` is not bound in all patterns
47     //~| ERROR variable `a` is not bound in all patterns
48     //~| ERROR variable `b` is not bound in all patterns
49     //~| ERROR variable `b` is not bound in all patterns
50     //~| ERROR variable `c` is not bound in all patterns
51     //~| ERROR variable `c` is not bound in all patterns
52     //~| ERROR variable `d` is not bound in all patterns
53     //~| ERROR variable `e` is not bound in all patterns
54
55     // Three levels:
56     let (
57             V1(
58             //~^ ERROR variable `b` is not bound in all patterns
59             //~| ERROR variable `c` is not bound in all patterns
60                 A(
61                     Ok(a) | Err(_), //~ ERROR variable `a` is not bound in all patterns
62                     _
63                 ) |
64                 B(Ok(a) | Err(a))
65             ) |
66             V2(
67                 A(
68                     A(_, a) | //~ ERROR variable `b` is not bound in all patterns
69                     B(b), //~ ERROR variable `a` is not bound in all patterns
70                     _
71                 ) |
72                 B(_)
73                 //~^ ERROR variable `a` is not bound in all patterns
74                 //~| ERROR variable `b` is not bound in all patterns
75             ) |
76             V3(c),
77             //~^ ERROR variable `a` is not bound in all patterns
78         )
79         : (Vars3<E<Result<u8, u8>>, E<E<u8>>, u8>,)
80         = (V3(0),);
81 }