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

Judgment borrow_check_expr

judgment_fn! {
    /// Prove that any loans issued in this value expression are respected, and return its type.
    pub fn borrow_check_expr(
        env: TypeckEnv,
        assumptions: Predicates,
        state: FlowState,
        expr: Expr,
        places_live_on_exit: LivePlaces,
    ) => (Ty, FlowState) {
        /* rules omitted */
    }
}

Source: crates/formality-rust/src/check/borrow_check/nll.rs:375

The number on each rule’s conclusion is positive coverage; the number on each premise is negative coverage. Click a number to browse the tests.

division
LineCoverageSource
387N/A(let expr = Expr::bin_op(lhs, BinOpKind::Div, rhs))
3882(borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state))
──────── ("division")
39019(borrow_check_expr(env, assumptions, state, Expr::Div { lhs, rhs }, places_live_on_exit) => (ty, state))
parenthesized
LineCoverageSource
394✗(borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state))
──────── ("parenthesized")
39614(borrow_check_expr(env, assumptions, state, Expr::Parens(expr), places_live_on_exit) => (ty, state))
multiplication
LineCoverageSource
400N/A(let expr = Expr::bin_op(lhs, BinOpKind::Mul, rhs))
4012(borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state))
──────── ("multiplication")
40315(borrow_check_expr(env, assumptions, state, Expr::Mul { lhs, rhs }, places_live_on_exit) => (ty, state))
remainder
LineCoverageSource
407N/A(let expr = Expr::bin_op(lhs, BinOpKind::Rem, rhs))
4082(borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state))
──────── ("remainder")
41011(borrow_check_expr(env, assumptions, state, Expr::Rem { lhs, rhs }, places_live_on_exit) => (ty, state))
bitwise or
LineCoverageSource
414N/A(let expr = Expr::bin_op(lhs, BinOpKind::BitOr, rhs))
4153(borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state))
──────── ("bitwise or")
41713(borrow_check_expr(env, assumptions, state, Expr::BitOr { lhs, rhs }, places_live_on_exit) => (ty, state))
bitwise xor
LineCoverageSource
421N/A(let expr = Expr::bin_op(lhs, BinOpKind::BitXor, rhs))
4222(borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state))
──────── ("bitwise xor")
42415(borrow_check_expr(env, assumptions, state, Expr::BitXor { lhs, rhs }, places_live_on_exit) => (ty, state))
bitwise and
LineCoverageSource
428N/A(let expr = Expr::bin_op(lhs, BinOpKind::BitAnd, rhs))
4293(borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state))
──────── ("bitwise and")
43114(borrow_check_expr(env, assumptions, state, Expr::BitAnd { lhs, rhs }, places_live_on_exit) => (ty, state))
assign
LineCoverageSource
4361(borrow_check_expr(
env,
assumptions,
state,
expr,
Assignment(place).live_before(env, &state, places_live_on_exit),
) => (value_ty, state))
4452(borrow_check_place_expr(
env,
assumptions,
state,
place,
) => (place, state))
4531(prove_assignable(env, assumptions, state, value_ty, &place.ty) => state)
45516(access_permitted(
env,
assumptions,
state,
Access::new(AccessKind::Write, place),
places_live_on_exit,
) => state)
463N/A(let state = kill_loans(place, state))
464N/A(let state = state.with_initialized(&place.to_place_expression()))
──────── ("assign")
46643(borrow_check_expr(env, assumptions, state, Expr::Assign { place, expr }, places_live_on_exit) => (Ty::unit(), state))
assign-op
LineCoverageSource
4711(borrow_check_expr(
env,
assumptions,
state,
rhs,
Seq(place, Assignment(place)).live_before(env, &state, places_live_on_exit),
) => (rhs_ty, state))
478N/A(let places_live_before_write = Assignment(place).live_before(env, &state, places_live_on_exit))
480✗(borrow_check_place_expr(env, assumptions, state, place) => (place, state))
481✗(prove_ty_is_rigid(env, assumptions, state, &place.ty) => (RigidTy { name: RigidName::ScalarId(scalar), parameters: _ }, state))
4821(if scalar.is_int())
4834(prove_assignable(env, assumptions, state, rhs_ty, &place.ty) => state)
4852(access_permitted(env, assumptions, state, Access::new(AccessKind::Read, place), places_live_before_write) => state)
4861(access_permitted(env, assumptions, state, Access::new(AccessKind::Write, place), places_live_on_exit) => state)
487N/A(let state = kill_loans(place, state))
──────── ("assign-op")
48919(borrow_check_expr(env, assumptions, state, Expr::AssignOp { place, op: _, rhs }, places_live_on_exit) => (Ty::unit(), state))
call
LineCoverageSource
49412(borrow_check_expr(
env,
assumptions,
state,
callee,
args.live_before(env, &state, places_live),
) => (callee_ty, state))
503✗(prove_ty_is_rigid(env, assumptions, state, callee_ty) => (RigidTy { name: RigidName::FnDef(fn_id), parameters }, state))
506✗(let Fn { id: _, safety, binder } = env.crates().fn_named(fn_id)?)
508✗(ProvenSet::singleton((safety, ProofTree::leaf("safety"))) => Safety::Safe)
509✗(let FnBoundData { input_args, output_ty, where_clauses, body: _ } =
binder.instantiate_with(parameters)?)
5131(if input_args.len() == args.len())
515✗(for_all(i in 0..args.len()) with(state)
(borrow_check_expr_has_ty(env, assumptions, state, &args[i], &input_args[i].ty, args[i+1..].live_before(env, &state, places_live)) => state))
518✗(prove_where_clauses(env, assumptions, state, where_clauses) => state)
──────── ("call")
52082(borrow_check_expr(env, assumptions, state, Expr::Call { callee, args }, places_live) => (output_ty, state))
binop
LineCoverageSource
5233(borrow_check_expr(env, assumptions, state, lhs, rhs.live_before(env, &state, places_live_on_exit)) => (lhs_ty, state))
524✗(prove_ty_is_rigid(env, assumptions, state, &lhs_ty) => (RigidTy {name: RigidName::ScalarId(scalar), parameters: _}, state))
5256(if scalar.is_int())
5268(borrow_check_expr_has_ty(env, assumptions, state, rhs, &lhs_ty, places_live_on_exit) => state)
──────── ("binop")
52891(borrow_check_expr(env, assumptions, state, Expr::BinOp{lhs, op: _, rhs}, places_live_on_exit) => (lhs_ty, state))
literal
LineCoverageSource
──────── ("literal")
533205(borrow_check_expr(_env, _assumptions, state, Literal { value: _, ty }, _places_live_on_exit) => (ty, state))
true
LineCoverageSource
──────── ("true")
53828(borrow_check_expr(_env, _assumptions, state, Expr::True, _places_live_on_exit) => (ScalarId::Bool, state))
false
LineCoverageSource
──────── ("false")
5437(borrow_check_expr(_env, _assumptions, state, Expr::False, _places_live_on_exit) => (ScalarId::Bool, state))
ref
LineCoverageSource
547✗(borrow_check_place_expr(
env,
assumptions,
state,
place,
) => (place, state))
555N/A(let access_kind = match kind {
RefKind::Shared => AccessKind::Read,
RefKind::Mut => AccessKind::Write,
})
55913(access_permitted(
env,
assumptions,
state,
Access::new(access_kind, place),
places_live_on_exit,
) => state)
568N/A(let state = state.with_loan(Loan::new(lt, place, kind)))
569N/A(let state = state.with_outlives(&reborrow_constraints(place, lt)))
5761(verify_universal_outlives(env, assumptions, &state.current.outlives) => ())
577N/A(let ty = place.ty.ref_ty_of_kind(kind, lt))
──────── ("ref")
57963(borrow_check_expr(env, assumptions, state, Expr::Ref { kind, lt, place }, places_live_on_exit) => (ty, state))
place
LineCoverageSource
5833(borrow_check_place_expr(env, assumptions, state, place) => (place, state))
584✗(access_kind_for_place_use(env, assumptions, state, place) => (access_kind, state))
58520(access_permitted(env, assumptions, state, Access::new(access_kind, place), places_live_on_exit) => state)
586✗(record_place_use(state, access_kind, place) => state)
5873(prove_place_is_movable(env, assumptions, state, place) => state)
──────── ("place")
589139(borrow_check_expr(env, assumptions, state, Expr::Place(place), places_live_on_exit) => (&place.ty, state))
fn-name
LineCoverageSource
595✗(if let PlaceExpr::Var(id) = place)
596✗(if !state.has_local(id))
5973(borrow_check_fn_ref(env, assumptions, state, id, Vec::<Parameter>::new()) => (ty, state))
──────── ("fn-name")
59932(borrow_check_expr(env, assumptions, state, Expr::Place(place), _places_live_on_exit) => (ty, state))
turbofish
LineCoverageSource
60411(borrow_check_fn_ref(env, assumptions, state, id, args) => (ty, state))
──────── ("turbofish")
60658(borrow_check_expr(env, assumptions, state, Expr::Turbofish { id, args }, _places_live_on_exit) => (ty, state))
struct
LineCoverageSource
6261(let Struct { id: _, binder } = env.crates().struct_named(&adt_id)?)
627✗(if turbofish.parameters.len() == binder.len())
628✗(let StructBoundData { where_clauses, fields } = binder.instantiate_with(&turbofish.parameters)?)
631N/A(let expected_names: Set<FieldName> = for_all field in fields => field.name)
632N/A(let provided_names: Set<FieldName> = for_all field in field_exprs => field.name)
633✗(if expected_names == provided_names)
6371(if field_exprs.len() == provided_names.len())
640✗(for_all(i in 0..field_exprs.len()) with(state)
(field in fields)
(if field.name == field_exprs[i].name)
(borrow_check_expr_has_ty(env, assumptions, state, &field_exprs[i].value, &field.ty, field_exprs[i+1..].live_before(env, &state, places_live_on_exit)) => state))
645✗(prove_where_clauses(env, assumptions, state, where_clauses) => state)
647N/A(let ty = RigidTy::new(adt_id, &turbofish.parameters))
──────── ("struct")
64925(borrow_check_expr(env, assumptions, state, Expr::Struct { adt_id, turbofish, field_exprs }, places_live_on_exit) => (ty, state))

How to read this page