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

Negative coverage: borrow_check_statement / if / premise borrow_check_block(env, assumptions, state, &else_block.block, places_live_on_exit) => else_state

Premise at line 223. Observed failure causes: failed_judgment.

if
LineCoverageSource
212✗(borrow_check_expr_has_ty(
env,
assumptions,
state,
condition,
Ty::bool(),
Either(then_block, &else_block.block).live_before(env, &state, places_live_on_exit),
) => state)
2222(borrow_check_block(env, assumptions, state, then_block, places_live_on_exit) => then_state)
2234(borrow_check_block(env, assumptions, state, &else_block.block, places_live_on_exit) => else_state)
226N/A(let state: FlowState = Union((then_state, else_state)).upcast())
──────── ("if")
22829(borrow_check_statement(env, assumptions, state, Stmt::If { condition, then_block, else_block }, places_live_on_exit) => (env, state))

4 tests failed proving this premise:


Source location: src/test_util.rs:516 (all coverage from this test)

#[test]
fn rustc_expectation_is_independent_of_borrowck_modes() {
    let before = rustc_runs();
    FormalityTest::new(NLL_ONLY_ERROR)
        .rustc_err(expect_test::expect![[r#"
            error[E0499]: cannot borrow `*m` as mutable more than once at a time
             --> lib.rs
              |
            3 | pub fn foo<'a00>(mut m: &'a00 mut Map) -> &'a00 mut Map {
              |            ---- lifetime `'a00` defined here
            4 |     {
            5 |         let mut n: &'_ mut Map = &mut *m;
              |                                  ------- first mutable borrow occurs here
            6 |         if false {
            7 |             return n;
              |                    - returning this value requires that `*m` is borrowed for `'a00`
            8 |         } else {
            9 |             let mut o: &'_ mut Map = &mut *m;
              |                                      ^^^^^^^ second mutable borrow occurs here

            For more information about this error, try `rustc --explain E0499`.
            error: could not compile `Foo` (lib) due to 1 previous error
        "#]])
        .borrowck_err(BorrowCheckFailure::Nll, expect_test::expect![[r#"
            the rule "borrow of disjoint places" at (nll.rs) failed because
              condition evaluated to false: `place_disjoint_from_place(&loan.place, &access.place)`
                &loan.place = *(m : &!lt_1 mut Map) : <&!lt_1 mut Map as Derefable>::Target
                &access.place = *(m : &!lt_1 mut Map) : <&!lt_1 mut Map as Derefable>::Target

            the rule "loan_cannot_outlive" at (nll.rs) failed because
              condition evaluated to false: `!outlived_by_loan.contains(&lifetime.upcast())`
                outlived_by_loan = {!lt_1, ?lt_2, ?lt_3}
                &lifetime.upcast() = !lt_1

            the rule "loan_not_required_by_universal_regions" at (nll.rs) failed because
              condition evaluated to false: `outlived_by_loan.iter().all(|p| match p
              {
                  Parameter::Ty(_) => false, Parameter::Lt(lt) => match lt.as_ref()
                  {
                      Lt::Static => false, Lt::Variable(Variable::UniversalVar(_)) => false,
                      Lt::Variable(Variable::ExistentialVar(_)) => true,
                      Lt::Variable(Variable::BoundVar(_)) =>
                      panic!("cannot outlive a bound var"), Lt::Erased => true,
                  }, Parameter::Const(_) => panic!("cannot outlive a constant"),
              })`

            the rule "write-indirect" at (nll.rs) failed because
              pattern `TypedPlaceExpressionData::Deref(place_loaned_ref)` did not match value `m`

            the rule "write-indirect" at (nll.rs) failed because
              condition evaluated to false: `place_accessed.is_prefix_of(place_loaned_ref)`
                place_accessed = *(m : &!lt_1 mut Map) : <&!lt_1 mut Map as Derefable>::Target
                place_loaned_ref = m : &!lt_1 mut Map"#]]);
    assert_eq!(rustc_runs() - before, 1);
}
Failed proof tree

Source location: tests/borrowck.rs:2470 (all coverage from this test)

fn min_problem_case_3<'a>(m: &'a mut Map) -> &'a mut Map {
    exists<'r0, 'r1> {
        let n: &'r0 mut Map = &'r0 mut *m;
        if true {
            return n;
        } else {
            let o: &'r1 mut Map = &'r1 mut *m;
            return o;
        }
    }
}
Failed proof tree

Source location: tests/borrowck.rs:3288 (all coverage from this test)

fn foo<'a>(m: &'a mut Map) -> &'a mut Map {
    exists<'r0, 'r1> {
        let n: &'r0 mut Map = &'r0 mut *m;
        if false {
            return n;
        } else {
            let o: &'r1 mut Map = &'r1 mut *m;
            return o;
        }
    }
}
Failed proof tree

Source location: tests/mir_typeck.rs:168 (all coverage from this test)

fn foo (b: bool) -> u32 {
    if b {
        return 1_u32;
    } else {
        return false;
    }
}
Failed proof tree

How to read this page