]> git.proxmox.com Git - rustc.git/blob - src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / pattern-matching-should-fail.rs
1 #![feature(capture_disjoint_fields)]
2 //~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3 //~| `#[warn(incomplete_features)]` on by default
4 //~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
5 #![feature(never_type)]
6
7 // Should fake read the discriminant and throw an error
8 fn test1() {
9 let x: !;
10 let c1 = || match x { };
11 //~^ ERROR: use of possibly-uninitialized variable: `x`
12 }
13
14 // Should fake read the discriminant and throw an error
15 fn test2() {
16 let x: !;
17 let c2 = || match x { _ => () };
18 //~^ ERROR: borrow of possibly-uninitialized variable: `x`
19 }
20
21 // Testing single variant patterns
22 enum SingleVariant {
23 Points(u32)
24 }
25
26 // Should fake read the discriminant and throw an error
27 fn test3() {
28 let variant: !;
29 let c = || {
30 //~^ ERROR: borrow of possibly-uninitialized variable: `variant`
31 match variant {
32 SingleVariant::Points(_) => {}
33 }
34 };
35 c();
36 }
37
38 // Should fake read the discriminant and throw an error
39 fn test4() {
40 let variant: !;
41 let c = || {
42 //~^ ERROR: borrow of possibly-uninitialized variable: `variant`
43 match variant {
44 SingleVariant::Points(a) => {
45 println!("{:?}", a);
46 }
47 }
48 };
49 c();
50 }
51
52 fn test5() {
53 let t: !;
54 let g: !;
55
56 let a = || {
57 match g { };
58 //~^ ERROR: use of possibly-uninitialized variable: `g`
59 let c = || {
60 match t { };
61 //~^ ERROR: use of possibly-uninitialized variable: `t`
62 };
63
64 c();
65 };
66
67 }
68
69 // Should fake read the discriminant and throw an error
70 fn test6() {
71 let x: u8;
72 let c1 = || match x { };
73 //~^ ERROR: use of possibly-uninitialized variable: `x`
74 //~| ERROR: non-exhaustive patterns: type `u8` is non-empty
75 }
76
77 fn main() {
78 test1();
79 test2();
80 test3();
81 test4();
82 test5();
83 test6();
84 }