]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/match-cfg-fake-edges.rs
Rollup merge of #103146 - joboet:cleanup_pthread_condvar, r=Mark-Simulacrum
[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 fn guard_always_precedes_arm(y: i32) {
5     let mut x;
6     // x should always be initialized, as the only way to reach the arm is
7     // through the guard.
8     match y {
9         0 | 2 if { x = 2; true } => x,
10         _ => 2,
11     };
12 }
13
14 fn guard_may_be_skipped(y: i32) {
15     let x;
16     // Even though x *is* always initialized, we don't want to have borrowck
17     // results be based on whether patterns are exhaustive.
18     match y {
19         _ if { x = 2; true } => 1,
20         _ if {
21             x; //~ ERROR E0381
22             false
23         } => 2,
24         _ => 3,
25     };
26 }
27
28 fn guard_may_be_taken(y: bool) {
29     let x = String::new();
30     // Even though x *is* never moved before the use, we don't want to have
31     // borrowck results be based on whether patterns are disjoint.
32     match y {
33         false if { drop(x); true } => 1,
34         true => {
35             x; //~ ERROR use of moved value: `x`
36             2
37         }
38         false => 3,
39     };
40 }
41
42 fn main() {}