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| Line | Coverage | Source |
|---|---|---|
| 387 | N/A | (let expr = Expr::bin_op(lhs, BinOpKind::Div, rhs)) |
| 388 | 2 | (borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state)) |
| ──────── ("division") | ||
| 390 | 19 | (borrow_check_expr(env, assumptions, state, Expr::Div { lhs, rhs }, places_live_on_exit) => (ty, state)) |
parenthesized| Line | Coverage | Source |
|---|---|---|
| 394 | ✗ | (borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state)) |
| ──────── ("parenthesized") | ||
| 396 | 14 | (borrow_check_expr(env, assumptions, state, Expr::Parens(expr), places_live_on_exit) => (ty, state)) |
multiplication| Line | Coverage | Source |
|---|---|---|
| 400 | N/A | (let expr = Expr::bin_op(lhs, BinOpKind::Mul, rhs)) |
| 401 | 2 | (borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state)) |
| ──────── ("multiplication") | ||
| 403 | 15 | (borrow_check_expr(env, assumptions, state, Expr::Mul { lhs, rhs }, places_live_on_exit) => (ty, state)) |
remainder| Line | Coverage | Source |
|---|---|---|
| 407 | N/A | (let expr = Expr::bin_op(lhs, BinOpKind::Rem, rhs)) |
| 408 | 2 | (borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state)) |
| ──────── ("remainder") | ||
| 410 | 11 | (borrow_check_expr(env, assumptions, state, Expr::Rem { lhs, rhs }, places_live_on_exit) => (ty, state)) |
bitwise or| Line | Coverage | Source |
|---|---|---|
| 414 | N/A | (let expr = Expr::bin_op(lhs, BinOpKind::BitOr, rhs)) |
| 415 | 3 | (borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state)) |
| ──────── ("bitwise or") | ||
| 417 | 13 | (borrow_check_expr(env, assumptions, state, Expr::BitOr { lhs, rhs }, places_live_on_exit) => (ty, state)) |
bitwise xor| Line | Coverage | Source |
|---|---|---|
| 421 | N/A | (let expr = Expr::bin_op(lhs, BinOpKind::BitXor, rhs)) |
| 422 | 2 | (borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state)) |
| ──────── ("bitwise xor") | ||
| 424 | 15 | (borrow_check_expr(env, assumptions, state, Expr::BitXor { lhs, rhs }, places_live_on_exit) => (ty, state)) |
bitwise and| Line | Coverage | Source |
|---|---|---|
| 428 | N/A | (let expr = Expr::bin_op(lhs, BinOpKind::BitAnd, rhs)) |
| 429 | 3 | (borrow_check_expr(env, assumptions, state, expr, places_live_on_exit) => (ty, state)) |
| ──────── ("bitwise and") | ||
| 431 | 14 | (borrow_check_expr(env, assumptions, state, Expr::BitAnd { lhs, rhs }, places_live_on_exit) => (ty, state)) |
assign| Line | Coverage | Source |
|---|---|---|
| 436 | 1 | (borrow_check_expr( env, assumptions, state, expr, Assignment(place).live_before(env, &state, places_live_on_exit), ) => (value_ty, state)) |
| 445 | 2 | (borrow_check_place_expr( env, assumptions, state, place, ) => (place, state)) |
| 453 | 1 | (prove_assignable(env, assumptions, state, value_ty, &place.ty) => state) |
| 455 | 16 | (access_permitted( env, assumptions, state, Access::new(AccessKind::Write, place), places_live_on_exit, ) => state) |
| 463 | N/A | (let state = kill_loans(place, state)) |
| 464 | N/A | (let state = state.with_initialized(&place.to_place_expression())) |
| ──────── ("assign") | ||
| 466 | 43 | (borrow_check_expr(env, assumptions, state, Expr::Assign { place, expr }, places_live_on_exit) => (Ty::unit(), state)) |
assign-op| Line | Coverage | Source |
|---|---|---|
| 471 | 1 | (borrow_check_expr( env, assumptions, state, rhs, Seq(place, Assignment(place)).live_before(env, &state, places_live_on_exit), ) => (rhs_ty, state)) |
| 478 | N/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)) |
| 482 | 1 | (if scalar.is_int()) |
| 483 | 4 | (prove_assignable(env, assumptions, state, rhs_ty, &place.ty) => state) |
| 485 | 2 | (access_permitted(env, assumptions, state, Access::new(AccessKind::Read, place), places_live_before_write) => state) |
| 486 | 1 | (access_permitted(env, assumptions, state, Access::new(AccessKind::Write, place), places_live_on_exit) => state) |
| 487 | N/A | (let state = kill_loans(place, state)) |
| ──────── ("assign-op") | ||
| 489 | 19 | (borrow_check_expr(env, assumptions, state, Expr::AssignOp { place, op: _, rhs }, places_live_on_exit) => (Ty::unit(), state)) |
call| Line | Coverage | Source |
|---|---|---|
| 494 | 12 | (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)?) |
| 513 | 1 | (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") | ||
| 520 | 82 | (borrow_check_expr(env, assumptions, state, Expr::Call { callee, args }, places_live) => (output_ty, state)) |
binop| Line | Coverage | Source |
|---|---|---|
| 523 | 3 | (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)) |
| 525 | 6 | (if scalar.is_int()) |
| 526 | 8 | (borrow_check_expr_has_ty(env, assumptions, state, rhs, &lhs_ty, places_live_on_exit) => state) |
| ──────── ("binop") | ||
| 528 | 91 | (borrow_check_expr(env, assumptions, state, Expr::BinOp{lhs, op: _, rhs}, places_live_on_exit) => (lhs_ty, state)) |
literal| Line | Coverage | Source |
|---|---|---|
| ──────── ("literal") | ||
| 533 | 205 | (borrow_check_expr(_env, _assumptions, state, Literal { value: _, ty }, _places_live_on_exit) => (ty, state)) |
true| Line | Coverage | Source |
|---|---|---|
| ──────── ("true") | ||
| 538 | 28 | (borrow_check_expr(_env, _assumptions, state, Expr::True, _places_live_on_exit) => (ScalarId::Bool, state)) |
false| Line | Coverage | Source |
|---|---|---|
| ──────── ("false") | ||
| 543 | 7 | (borrow_check_expr(_env, _assumptions, state, Expr::False, _places_live_on_exit) => (ScalarId::Bool, state)) |
ref| Line | Coverage | Source |
|---|---|---|
| 547 | ✗ | (borrow_check_place_expr( env, assumptions, state, place, ) => (place, state)) |
| 555 | N/A | (let access_kind = match kind { RefKind::Shared => AccessKind::Read, RefKind::Mut => AccessKind::Write, }) |
| 559 | 13 | (access_permitted( env, assumptions, state, Access::new(access_kind, place), places_live_on_exit, ) => state) |
| 568 | N/A | (let state = state.with_loan(Loan::new(lt, place, kind))) |
| 569 | N/A | (let state = state.with_outlives(&reborrow_constraints(place, lt))) |
| 576 | 1 | (verify_universal_outlives(env, assumptions, &state.current.outlives) => ()) |
| 577 | N/A | (let ty = place.ty.ref_ty_of_kind(kind, lt)) |
| ──────── ("ref") | ||
| 579 | 63 | (borrow_check_expr(env, assumptions, state, Expr::Ref { kind, lt, place }, places_live_on_exit) => (ty, state)) |
place| Line | Coverage | Source |
|---|---|---|
| 583 | 3 | (borrow_check_place_expr(env, assumptions, state, place) => (place, state)) |
| 584 | ✗ | (access_kind_for_place_use(env, assumptions, state, place) => (access_kind, state)) |
| 585 | 20 | (access_permitted(env, assumptions, state, Access::new(access_kind, place), places_live_on_exit) => state) |
| 586 | ✗ | (record_place_use(state, access_kind, place) => state) |
| 587 | 3 | (prove_place_is_movable(env, assumptions, state, place) => state) |
| ──────── ("place") | ||
| 589 | 139 | (borrow_check_expr(env, assumptions, state, Expr::Place(place), places_live_on_exit) => (&place.ty, state)) |
fn-name| Line | Coverage | Source |
|---|---|---|
| 595 | ✗ | (if let PlaceExpr::Var(id) = place) |
| 596 | ✗ | (if !state.has_local(id)) |
| 597 | 3 | (borrow_check_fn_ref(env, assumptions, state, id, Vec::<Parameter>::new()) => (ty, state)) |
| ──────── ("fn-name") | ||
| 599 | 32 | (borrow_check_expr(env, assumptions, state, Expr::Place(place), _places_live_on_exit) => (ty, state)) |
turbofish| Line | Coverage | Source |
|---|---|---|
| 604 | 11 | (borrow_check_fn_ref(env, assumptions, state, id, args) => (ty, state)) |
| ──────── ("turbofish") | ||
| 606 | 58 | (borrow_check_expr(env, assumptions, state, Expr::Turbofish { id, args }, _places_live_on_exit) => (ty, state)) |
struct| Line | Coverage | Source |
|---|---|---|
| 626 | 1 | (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)?) |
| 631 | N/A | (let expected_names: Set<FieldName> = for_all field in fields => field.name) |
| 632 | N/A | (let provided_names: Set<FieldName> = for_all field in field_exprs => field.name) |
| 633 | ✗ | (if expected_names == provided_names) |
| 637 | 1 | (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) |
| 647 | N/A | (let ty = RigidTy::new(adt_id, &turbofish.parameters)) |
| ──────── ("struct") | ||
| 649 | 25 | (borrow_check_expr(env, assumptions, state, Expr::Struct { adt_id, turbofish, field_exprs }, places_live_on_exit) => (ty, state)) |