Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Positive coverage: borrow_check_statement / if

if
LineCoverageSource
209(borrow_check_expr_has_ty(
env,
assumptions,
state,
condition,
Ty::bool(),
Either(then_block, else_block).live_before(env, &state, places_live_on_exit),
) => state)
2191(borrow_check_block(env, assumptions, state, then_block, places_live_on_exit) => then_state)
2201(borrow_check_block(env, assumptions, state, else_block, places_live_on_exit) => else_state)
223N/A(let state: FlowState = Union((then_state, else_state)).upcast())
──────── ("if")
22514(borrow_check_statement(env, assumptions, state, Stmt::If { condition, then_block, else_block }, places_live_on_exit) => (env, state))

14 tests exercised this rule:


Source location: tests/borrowck.rs:186

fn foo() -> u32 {
    let x: u32;
    if true {
        x = 1 _ u32;
    } else {
        x = 2 _ u32;
    }
    return x;
}
Proof tree
… (200 of 1048 nodes shown)

Source location: tests/borrowck.rs:1968

fn min_problem_case_3<'a>(m: &mut 'a Map) -> &mut 'a Map {
    exists<'r0, 'r1> {
        let n: &mut 'r0 Map = &mut 'r0 *m;
        if true {
            return n;
        } else {
            let o: &mut 'r1 Map = &mut 'r1 *m;
            return o;
        }
    }
}
Proof tree
… (200 of 1324 nodes shown)

Source location: tests/borrowck.rs:2156

fn min_problem_case_3<'a>(m: &mut 'a Map) -> &mut 'a Map {
    exists<'r0, 'r1> {
        let n: &mut 'r0 Map = &mut 'r0 *m;
        if true {
        } else {
        }
        let o: &mut 'r1 Map = &mut 'r1 *m;
        return o;
    }
}
Proof tree
… (200 of 1295 nodes shown)

Source location: tests/borrowck.rs:2410

fn foo () -> u32 {
    exists<'l_p, 'l_q, 'loan_0, 'loan_1, 'loan_2, 'loan_3> {
        let a: u32 = 0 _ u32;
        let b: u32 = 0 _ u32;
        // In Rustc, the 1-tuple is needed for some reason
        // Niko does not 100% understand, else rustc is able to
        // see that this program is safe.
        let q: &mut 'l_q u32 = &mut 'loan_0 a;
        let p: &mut 'l_p u32 = &mut 'loan_1 a;
        if true {
            p = &mut 'loan_1 a;
            q = &mut 'loan_2 b;
        } else {
            p = &mut 'loan_3 b;
        }
        *q = 1 _ u32;
        return *p;
    }
}
Proof tree
… (200 of 1495 nodes shown)

Source location: tests/borrowck.rs:2733

fn foo<'a>(m: &mut 'a Map) -> &mut 'a Map {
    exists<'r0, 'r1> {
        let n: &mut 'r0 Map = &mut 'r0 *m;
        if false {
            return n;
        } else {
            let o: &mut 'r1 Map = &mut 'r1 *m;
            return o;
        }
    }
}
Proof tree
… (200 of 1324 nodes shown)

Source location: tests/borrowck.rs:3095

fn reborrow<'a>(a: &mut 'a u8) -> &mut 'a u8 {
    exists<'r0, 'r1, 'r2, 'r3> {
        if true {
            let b: &mut 'r1 u8 = &mut 'r0 *a;
            return b;
        } else { }

        let c: &mut 'r3 u8 = &mut 'r2 *a;
        return c;
    }
}
Proof tree
… (200 of 1308 nodes shown)

Source location: tests/borrowck.rs:3120

fn reborrow<'a>(a: &mut 'a u8) -> &mut 'a u8 {
    exists<'r0, 'r1, 'r2, 'r3> {
        // This creates an outlives constraint
        let b: &mut 'r1 u8 = &mut 'r0 *a;
        if true {
            return b;
        } else {
            // this means the loan remains live
        }

        // If the outlives constraint propagated here,
        // we would get an error.
        let c: &mut 'r3 u8 = &mut 'r2 *a;
        return c;
    }
}
Proof tree
… (200 of 1314 nodes shown)

Source location: tests/borrowck.rs:3157

fn reborrow<'a>(a: &mut 'a u8) -> &mut 'a u8 {
    exists<'r0, 'r1, 'r2, 'r3> {
        if true {
            let b: &mut 'r1 u8 = &mut 'r0 *a;
            return b;
        } else {
            let c: &mut 'r3 u8 = &mut 'r2 *a;
            return c;
        }
    }
}
Proof tree
… (200 of 1309 nodes shown)

Source location: tests/codegen.rs:95

fn main() -> () {
    let x: i32 = 1 _ i32;
    if true {
        println!(x);
    } else {
        println!(0 _ i32);
    }
}
Proof tree
… (200 of 1031 nodes shown)

Source location: tests/codegen.rs:318

fn main() -> () {
    let x: i32 = 0 _ i32;
    'a: loop {
        if true {
            println!(x);
            break 'a;
        } else {
            continue 'a;
        }
    }
}
Proof tree
… (200 of 1073 nodes shown)

Source location: tests/codegen.rs:356

fn main() -> () {
    'a: loop {
        if true {
            println!(1 _ i32);
            break 'a;
        } else {
            println!(2 _ i32);
            break 'a;
        }
    }
    println!(3 _ i32);
}

Proof trees omitted for the remaining 4 tests.


Source location: tests/codegen.rs:377

fn main() -> () {
    let x: i32 = 0 _ i32;
    'a: loop {
        if false {
            x = 1 _ i32;
            break 'a;
        } else {
            x = 2 _ i32;
            break 'a;
        }
    }
    println!(x);
}

Source location: tests/mir_typeck.rs:133

fn foo (b: bool) -> u32 {
    if b {
        return 1 _ u32;
    } else {
        return 2 _ u32;
    }
}

Source location: tests/return_validation.rs:48

fn foo(b: bool) -> u32 {
    if b {
        return 1 _ u32;
    } else {
        return 2 _ u32;
    }
}