summaryrefslogtreecommitdiff
path: root/tests/src/loops-borrow-check-negative.rs
blob: 3386d5812addfd24377bd5e0ec480d8e14d61ee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//@ [!borrow-check] skip
//@ [borrow-check] known-failure

// This succeeds
fn loop_a<'a>(a: &'a mut u32, b: &'a mut u32) -> &'a mut u32 {
    let mut x = 0;
    while x > 0 {
        x += 1;
    }
    if x > 0 {
        a
    } else {
        b
    }
}

// This fails
fn loop_a_b<'a, 'b>(a: &'a mut u32, b: &'b mut u32) -> &'a mut u32 {
    let mut x = 0;
    while x > 0 {
        x += 1;
    }
    if x > 0 {
        a
    } else {
        b // Expect lifetime 'a
    }
}