]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/match-cfg-fake-edges.rs
fix merge conflicts
[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(nll, bind_by_move_pattern_guards)]
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
16 fn guard_may_be_skipped(y: i32) {
17     let x;
18     // Even though x *is* always initialized, we don't want to have borrowck
19     // results be based on whether patterns are exhaustive.
20     match y {
21         _ if { x = 2; true } => 1,
22         _ if {
23             x; //~ ERROR use of possibly uninitialized variable: `x`
24             false
25         } => 2,
26         _ => 3,
27     };
28 }
29
30 fn guard_may_be_taken(y: bool) {
31     let x = String::new();
32     // Even though x *is* never moved before the use, we don't want to have
33     // borrowck results be based on whether patterns are disjoint.
34     match y {
35         false if { drop(x); true } => 1,
36         true => {
37             x; //~ ERROR use of moved value: `x`
38             2
39         }
40         false => 3,
41     };
42 }
43
44 fn all_previous_tests_may_be_done(y: &mut (bool, bool)) {
45     let r = &mut y.1;
46     // We don't actually test y.1 to select the second arm, but we don't want
47     // borrowck results to be based on the order we match patterns.
48     match y {
49         (false, true) => 1, //~ ERROR cannot use `y.1` because it was mutably borrowed
50         (true, _) => {
51             r;
52             2
53         }
54         (false, _) => 3,
55     };
56 }
57
58 fn main() {}