]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.rs
Rollup merge of #107248 - erikdesjardins:addrspace, r=oli-obk
[rust.git] / tests / ui / closures / 2229_closure_analysis / match / pattern-matching-should-fail.rs
1 // edition:2021
2
3 #![feature(never_type)]
4
5 // Should fake read the discriminant and throw an error
6 fn test1() {
7     let x: !;
8     let c1 = || match x { };
9     //~^ ERROR E0381
10 }
11
12 // Should fake read the discriminant and throw an error
13 fn test2() {
14     let x: !;
15     let c2 = || match x { _ => () };
16     //~^ ERROR E0381
17 }
18
19 // Testing single variant patterns
20 enum SingleVariant {
21     Points(u32)
22 }
23
24 // Should fake read the discriminant and throw an error
25 fn test3() {
26     let variant: !;
27     let c = || {
28     //~^ ERROR E0381
29         match variant {
30             SingleVariant::Points(_) => {}
31         }
32     };
33     c();
34 }
35
36 // Should fake read the discriminant and throw an error
37 fn test4() {
38     let variant: !;
39     let c = || { //~ ERROR E0381
40         match variant {
41             SingleVariant::Points(a) => {
42                 println!("{:?}", a);
43             }
44         }
45     };
46     c();
47 }
48
49 fn test5() {
50     let t: !;
51     let g: !;
52
53     let a = || {
54         match g { }; //~ ERROR E0381
55         let c = ||  {
56             match t { }; //~ ERROR E0381
57         };
58
59         c();
60     };
61
62 }
63
64 // Should fake read the discriminant and throw an error
65 fn test6() {
66     let x: u8;
67     let c1 = || match x { };
68     //~^ ERROR E0381
69     //~| ERROR: non-exhaustive patterns: type `u8` is non-empty
70 }
71
72 fn main() {
73     test1();
74     test2();
75     test3();
76     test4();
77     test5();
78     test6();
79 }