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_expr / fn-name

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))

32 tests exercised this rule:


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

fn bar() -> u32 {
    exists<'r0, 'r1> {
        let v: u32 = 1_u32;
        let p: &'r0 u32 = &'r1 v;
        foo(0_u32);
        return *p;
    }
}
Proof tree
… (200 of 1569 nodes shown)

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

fn f() -> u32 {
    exists<'r0> {
        let v: u32 = 0_u32;
        let x: u32 = cb::<'r0>(v, &'r0 mut v);
        return x;
    }
}
Proof tree
… (200 of 1487 nodes shown)

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

fn f() -> u32 {
    exists<'r0, 'r1> {
        let v: u32 = 0_u32;
        let x: u32 = ss::<'r0, 'r1>(&'r0 v, &'r1 v);
        return x;
    }
}
Proof tree
… (200 of 1509 nodes shown)

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

fn f() -> u32 {
    exists<'r0, 'r1> {
        let s: S = S { a: 0_u32, b: 0_u32 };
        let x: u32 = both::<'r0, 'r1>(&'r0 mut s.a, &'r1 mut s.b);
        return x;
    }
}
Proof tree
… (200 of 1563 nodes shown)

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

fn f() -> u32 {
    exists<'r0, 'r1> {
        let v: u32 = 0_u32;
        let w: u32 = 0_u32;
        let r: &'r0 u32 = &'r0 w;
        let x: u32 = pair::<'r1, 'r0>(&'r1 mut v, r);
        return x;
    }
}
Proof tree
… (200 of 1576 nodes shown)

Source location: tests/codegen.rs:159 (all coverage from this test)

fn main() -> () {
    let y: i32 = add_one(1_i32);
    println!(y);
}
Proof tree
… (200 of 1373 nodes shown)

Source location: tests/codegen.rs:282 (all coverage from this test)

fn main() -> () {
    let a: i32 = f(1_i32);
    let b: i32 = f(2_i32);
    let c: i32 = f(3_i32);
    println!(a);
    println!(b);
    println!(c);
}
Proof tree
… (200 of 1451 nodes shown)

Source location: tests/codegen.rs:295 (all coverage from this test)

fn main() -> () {
    let y: i32 = f(f(42_i32));
    println!(y);
}
Proof tree
… (200 of 1387 nodes shown)

Source location: tests/codegen.rs:312 (all coverage from this test)

fn main() -> () {
    let r: i32 = outer(7_i32);
    println!(r);
}
Proof tree
… (200 of 1457 nodes shown)

Source location: tests/codegen.rs:332 (all coverage from this test)

fn main() -> () {
    a();
}
Proof tree
… (200 of 1482 nodes shown)

Source location: tests/codegen.rs:640 (all coverage from this test)

fn main() -> () { println!(left() + right()); }
}])
tc_ok()
ect_output("1\n2\n30\n")
)
}

#[test]
ion_in_call_arguments() {
alityTest::new(crates![crate test {
fn sum(x: i32, y: i32) -> i32 { return x + y; }
fn main() -> () {
    println!(sum(1_i32 + 2_i32, sum(3_i32, 4_i32)));
}

Proof trees omitted for the remaining 22 tests; each one is on its test’s page in Coverage by test.


Source location: tests/codegen.rs:653 (all coverage from this test)

fn main() -> () {
    println!(sum(1_i32 + 2_i32, sum(3_i32, 4_i32)));
}

Source location: tests/codegen.rs:693 (all coverage from this test)

fn main() -> () {
    let s: S = S { b: second(), a: first() };
    println!(s.a);
    println!(s.b);
}

Source location: tests/codegen.rs:769 (all coverage from this test)

fn main() -> () { println!(left() - right()); }
}])
tc_ok()
ect_output("1\n2\n7\n")
);
}

#[test]
er_subtraction_unsigned() {
alityTest::new(crates![crate Foo {
fn main() -> () {
    println!(10_u32 - 3_u32);
}

Source location: tests/codegen.rs:1000 (all coverage from this test)

fn main() -> () { println!(left() * right()); }
}])
tc_ok()
ect_output("1\n2\n12\n")
);
}

#[test]
plication_with_parentheses() {
alityTest::new(crates![crate Foo {
fn main() -> () {
    println!((2_i32 + 3_i32) * 4_i32);
    println!(2_i32 * (3_i32 + 4_i32));
}

Source location: tests/codegen.rs:1196 (all coverage from this test)

fn main() -> () { println!(left() ^ right()); }
}])
tc_ok()
ect_output("1\n2\n6\n")
);
}

#[test]
se_xor_with_parentheses() {
alityTest::new(crates![crate Foo {
fn main() -> () {
    println!((1_i32 ^ 2_i32) + 3_i32);
    println!(2_i32 * (3_i32 ^ 5_i32));
}

Source location: tests/codegen.rs:1363 (all coverage from this test)

fn main() -> () { println!(left() | right()); }
}])
tc_ok()
ect_output("1\n2\n5\n")
);
}

#[test]
se_or_with_parentheses() {
alityTest::new(crates![crate Foo {
fn main() -> () {
    println!((1_i32 | 2_i32) ^ 3_i32);
    println!(2_i32 * (1_i32 | 4_i32));
}

Source location: tests/codegen.rs:1534 (all coverage from this test)

fn main() -> () { println!(left() & right()); }
}])
tc_ok()
ect_output("1\n2\n8\n")
);
}

#[test]
se_and_with_parentheses() {
alityTest::new(crates![crate Foo {
fn main() -> () {
    println!((5_i32 ^ 6_i32) & 3_i32);
    println!((6_i32 & 3_i32) * 2_i32);
}

Source location: tests/codegen.rs:1772 (all coverage from this test)

fn main() -> () { println!(left() % right()); }
}])
tc_ok()
ect_output("1\n2\n1\n")
);
}

panics on these; MiniRust reports them as undefined behavior.
 #543: assert a defined abort instead of accepting the MiniRust UB diagnostic.
#[test]
_panic(expected = "modulus of remainder is zero")]
er_remainder_by_zero() {
alityTest::new(crates![crate Foo {
fn main() -> () {
    println!(7_i32 % 0_i32);
}

Source location: tests/codegen.rs:1962 (all coverage from this test)

fn main() -> () { println!(left() / right()); }
}])
tc_ok()
ect_output("1\n2\n4\n")
);
}

ust reports invalid division as an execution error.
 #543: assert a defined abort instead of accepting the MiniRust UB diagnostic.
#[test]
_panic(expected = "division by zero")]
er_division_by_zero() {
alityTest::new(crates![crate Foo {
fn main() -> () {
    println!(12_i32 / 0_i32);
}

Source location: tests/codegen.rs:2056 (all coverage from this test)

fn main() -> () {
    println!(sum(12_i32 / 3_i32, 10_i32 / 2_i32));
}

Source location: tests/division_abort.rs:40 (all coverage from this test)

#[test]
#[should_panic(expected = "expected a defined abort, got Ub(String(\"division by zero\"))")]
fn division_by_zero_aborts() {
    assert_aborts(crates![crate Foo {
        fn divide(lhs: u32, rhs: u32) -> u32 { return lhs / rhs; }
        fn main() -> () { println!(divide(12_u32, 0_u32)); }
    }]);
}

Source location: tests/division_abort.rs:50 (all coverage from this test)

#[test]
#[should_panic(expected = "expected a defined abort, got Ub(String(\"overflow in division\"))")]
fn signed_division_overflow_aborts() {
    assert_aborts(crates![crate Foo {
        fn divide(lhs: i32, rhs: i32) -> i32 { return lhs / rhs; }
        fn main() -> () { println!(divide(-2147483648_i32, -1_i32)); }
    }]);
}

Source location: tests/division_abort.rs:60 (all coverage from this test)

#[test]
#[should_panic(expected = "expected a defined abort, got Ub(String(\"division by zero\"))")]
fn compound_division_by_zero_aborts() {
    assert_aborts(crates![crate Foo {
        fn divide(lhs: u32, rhs: u32) -> u32 {
            lhs /= rhs;
            return lhs;
        }
        fn main() -> () { println!(divide(12_u32, 0_u32)); }
    }]);
}

Source location: tests/division_abort.rs:73 (all coverage from this test)

#[test]
#[should_panic(expected = "expected a defined abort, got Ub(String(\"overflow in division\"))")]
fn signed_compound_division_overflow_aborts() {
    assert_aborts(crates![crate Foo {
        fn divide(lhs: i32, rhs: i32) -> i32 {
            lhs /= rhs;
            return lhs;
        }
        fn main() -> () { println!(divide(-2147483648_i32, -1_i32)); }
    }]);
}

Source location: tests/functions.rs:70 (all coverage from this test)

fn main() {
    helper();
}

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

fn bar(v1: u32) -> u32 {
    let v0: u32 = foo(v1);
    return v0;
}

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

fn main() -> () { require; }
}])
tc_ok()
);
}

#[test]
fn_value_with_forwarded_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () where 'a: 'b { require::<'a, 'b>; }
fn main() -> () { outer::<'static, 'static>(); }
}])
tc_ok()
);
}

#[test]
fn_value_with_unsatisfied_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () { require::<'a, 'b>; }
fn main() -> () {}
}])
tc_err(expect_test::expect![[r#"
error: lifetime may not live long enough
 --> lib.rs
  |
7 | pub fn outer<'a00, 'a01>() -> () {
  |              ----  ---- lifetime `'a01` defined here
  |              |
  |              lifetime `'a00` defined here
8 |     require::<'a00, 'a01>;
  |     ^^^^^^^^^^^^^^^^^^^^^ requires that `'a00` must outlive `'a01`
  |
  = help: consider adding the following bound: `'a00: 'a01`

error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect!["crates/formality-rust/src/prove/prove_outlives.rs:8:1: no applicable rules for prove_outlives { a: !lt_0, b: !lt_1, assumptions: {}, env: Env { variables: [!lt_0, !lt_1], bias: Soundness, pending: [], allow_pending_outlives: false } }"]);
}

ound assignment of an integer of a different type should fail.
#[test]
compound_add_mismatched_int_types() {
alityTest::new(crates![crate Foo {
fn foo() -> () {
    let x: u32 = 1_u32;
    x += 2_u8;
}

Source location: tests/pr502_liveness_prototypes.rs:26 (all coverage from this test)

fn f() -> () {
    exists<'r0, 'r1> {
        let v: u32 = 0_u32;
        let w: u32 = 1_u32;
        let r: &'r0 u32 = &'r0 v;
        pair::<'r1, 'r0>(&'r1 mut v, after_reset::<'r0>(r = &'r0 w, r));
    }
}

Source location: tests/pr502_liveness_prototypes.rs:134 (all coverage from this test)

fn f() -> () {
    exists<'r0, 'r1> {
        let v: u32 = 0_u32;
        let r: &'r0 u32 = &'r0 v;
        let p: Pair<'r1> = Pair::<'r1> { a: *r, b: &'r1 mut v };
        println!(p.a);
    }
}

Source location: tests/pr531_review_probes.rs:55 (all coverage from this test)

fn main() -> () {
    let x: u128 = 170141183460469231731687303715884105728_u128;
    x |= identity(1_u128 | 2_u128 ^ 3_u128);
    println!(x);
    println!(identity((1_u128 | 2_u128) ^ 3_u128));
}

Source location: tests/pr539_review_probes.rs:16 (all coverage from this test)

fn main() -> () {
    println!(identity(8_u32 | 6_u32 ^ 3_u32 & 1_u32));
    println!(identity((8_u32 | 6_u32 ^ 3_u32) & 1_u32));
    println!(identity(0_u32 & observed()));
}

How to read this page