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