]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/match-cfg-fake-edges.rs
Rollup merge of #106175 - compiler-errors:bad-import-sugg, r=oli-obk
[rust.git] / src / test / ui / nll / match-cfg-fake-edges.rs
1 // Test that we have enough false edges to avoid exposing the exact matching
2 // algorithm in borrow checking.
3
4 #![feature(if_let_guard)]
5
6 fn guard_always_precedes_arm(y: i32) {
7     let mut x;
8     // x should always be initialized, as the only way to reach the arm is
9     // through the guard.
10     match y {
11         0 | 2 if { x = 2; true } => x,
12         _ => 2,
13     };
14
15     let mut x;
16     match y {
17         0 | 2 if let Some(()) = { x = 2; Some(()) } => x,
18         _ => 2,
19     };
20 }
21
22 fn guard_may_be_skipped(y: i32) {
23     let x;
24     // Even though x *is* always initialized, we don't want to have borrowck
25     // results be based on whether patterns are exhaustive.
26     match y {
27         _ if { x = 2; true } => 1,
28         _ if {
29             x; //~ ERROR E0381
30             false
31         } => 2,
32         _ => 3,
33     };
34
35     let x;
36     match y {
37         _ if let Some(()) = { x = 2; Some(()) } => 1,
38         _ if let Some(()) = {
39             x; //~ ERROR E0381
40             None
41         } => 2,
42         _ => 3,
43     };
44 }
45
46 fn guard_may_be_taken(y: bool) {
47     let x = String::new();
48     // Even though x *is* never moved before the use, we don't want to have
49     // borrowck results be based on whether patterns are disjoint.
50     match y {
51         false if { drop(x); true } => 1,
52         true => {
53             x; //~ ERROR use of moved value: `x`
54             2
55         }
56         false => 3,
57     };
58
59     let x = String::new();
60     match y {
61         false if let Some(()) = { drop(x); Some(()) } => 1,
62         true => {
63             x; //~ ERROR use of moved value: `x`
64             2
65         }
66         false => 3,
67     };
68 }
69
70 fn main() {}