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 / binop

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

91 tests exercised this rule:


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

fn main() -> () {
    let x: u32 = 6_u32;
    exists<'a> {
        let r: &'a mut u32 = &'a mut x;
        *r = 12_u32;
        println!(*r & x);
    }
}
Proof tree
… (200 of 1613 nodes shown)

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

fn main() -> () {
    let x: i32 = 1_i32 + 2_i32;
    println!(x);
}
Proof tree
… (200 of 1323 nodes shown)

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

fn main() -> () {
    let x: u32 = 0_u32;
    x = 1_u32 + 2_u32 + 3_u32;
    println!(x);
}
Proof tree
… (200 of 1344 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 tree
… (200 of 1368 nodes shown)

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

fn main() -> () {
    println!(sum(1_i32 + 2_i32, sum(3_i32, 4_i32)));
}
Proof tree
… (200 of 1414 nodes shown)

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

fn main() -> () {
    println!(10_i32 - 3_i32);
}
Proof tree
… (200 of 1300 nodes shown)

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

fn main() -> () {
    println!(3_i32 - 10_i32);
}
Proof tree
… (200 of 1300 nodes shown)

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

fn main() -> () {
    println!(10_i32 - 3_i32 - 2_i32);
}
Proof tree
… (200 of 1309 nodes shown)

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

fn main() -> () {
    println!(10_i32 - 3_i32 + 2_i32);
}
Proof tree
… (200 of 1309 nodes shown)

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);
}
Proof tree
… (200 of 1368 nodes shown)

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

fn main() -> () {
    println!(10_u32 - 3_u32);
}

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


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

fn main() -> () {
    println!(10_i32 - (3_i32 - 2_i32));
}

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

fn main() -> () {
    println!(20_i32 - (10_i32 - (3_i32 - 1_i32)));
}

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

fn main() -> () {
    let x: i32 = 10_i32;
    (x = (x - 3_i32));
    println!(x);
}

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

fn main() -> () {
    println!(3_i32 * 4_i32);
}

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

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

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

fn main() -> () {
    println!(-3_i32 * 4_i32);
}

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

fn main() -> () {
    println!(3_u32 * 4_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:1013 (all coverage from this test)

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

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

fn main() -> () {
    println!(20_i32 - 2_i32 * 3_i32);
    println!((20_i32 - 2_i32) * 3_i32);
}

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

fn main() -> () {
    let x: u32 = 1_u32;
    x += 2_u32 + 3_u32;
    println!(x);
}

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

fn main() -> () {
    let x: u32 = 20_u32;
    x -= 2_u32 + 3_u32;
    println!(x);
}

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

fn main() -> () {
    let p: Pair = Pair { a: 2_u32, b: 3_u32 };
    p.b *= p.a + 4_u32;
    println!(p.b);
    println!(p.a);
}

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

fn main() -> () {
    println!(12_i32 ^ 10_i32);
}

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

fn main() -> () {
    println!(1_i32 ^ 2_i32 + 3_i32);
    println!(5_i32 + 3_i32 ^ 6_i32);
    println!(10_i32 - 4_i32 ^ 1_i32);
    println!(7_i32 ^ 2_i32 * 3_i32);
}

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

fn main() -> () {
    println!(-1_i32 ^ 5_i32);
    println!(-8_i32 ^ -3_i32);
}

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

fn main() -> () {
    println!(255_u8 ^ 15_u8);
}

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:1209 (all coverage from this test)

fn main() -> () {
    println!((1_i32 ^ 2_i32) + 3_i32);
    println!(2_i32 * (3_i32 ^ 5_i32));
}

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

fn main() -> () {
    let x: i32 = 5_i32;
    x = x ^ 3_i32;
    println!(x);
}

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

fn main() -> () {
    let x: u32 = 12_u32;
    x ^= 3_u32 + 5_u32;
    println!(x);
}

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

fn main() -> () {
    println!(-128_i8 ^ -1_i8);
    println!(127_i8 ^ -1_i8);
}

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

fn main() -> () {
    println!(340282366920938463463374607431768211455_u128
        ^ 170141183460469231731687303715884105728_u128);
    println!(170141183460469231731687303715884105728_u128 ^ 1_u128);
    println!(-170141183460469231731687303715884105728_i128 ^ -1_i128);
}

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

fn main() -> () {
    println!(12_i32 | 10_i32);
}

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

fn main() -> () {
    println!(1_i32 | 2_i32 ^ 3_i32);
    println!(5_i32 ^ 1_i32 | 1_i32);
}

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

fn main() -> () {
    println!(3_i32 | 1_i32 + 1_i32);
    println!(3_i32 + 1_i32 | 1_i32);
    println!(9_i32 - 1_i32 | 1_i32);
    println!(5_i32 | 2_i32 * 3_i32);
}

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

fn main() -> () {
    println!(-16_i32 | 5_i32);
    println!(-8_i32 | -3_i32);
}

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

fn main() -> () {
    println!(240_u8 | 15_u8);
}

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:1376 (all coverage from this test)

fn main() -> () {
    println!((1_i32 | 2_i32) ^ 3_i32);
    println!(2_i32 * (1_i32 | 4_i32));
}

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

fn main() -> () {
    let x: i32 = 5_i32;
    x = x | 2_i32;
    println!(x);
}

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

fn main() -> () {
    let x: u32 = 6_u32;
    x |= 1_u32 + 2_u32;
    println!(x);
}

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

fn main() -> () {
    println!(-128_i8 | 127_i8);
    println!(64_i8 | 63_i8);
}

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

fn main() -> () {
    println!(170141183460469231731687303715884105728_u128
        | 170141183460469231731687303715884105727_u128);
    println!(170141183460469231731687303715884105728_u128 | 1_u128);
    println!(-170141183460469231731687303715884105728_i128
        | 170141183460469231731687303715884105727_i128);
}

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

fn main() -> () {
    println!(12_i32 & 10_i32);
}

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

fn main() -> () {
    println!(5_i32 ^ 6_i32 & 3_i32);
    println!(6_i32 & 3_i32 ^ 1_i32);
}

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

fn main() -> () {
    println!(5_i32 & 1_i32 + 2_i32);
    println!(3_i32 + 1_i32 & 6_i32);
    println!(9_i32 - 1_i32 & 12_i32);
    println!(6_i32 & 3_i32 * 2_i32);
}

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

fn main() -> () {
    println!(-1_i32 & 5_i32);
    println!(-6_i32 & -3_i32);
    println!(-16_i32 & 31_i32);
}

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

fn main() -> () {
    println!(240_u8 & 60_u8);
}

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:1547 (all coverage from this test)

fn main() -> () {
    println!((5_i32 ^ 6_i32) & 3_i32);
    println!((6_i32 & 3_i32) * 2_i32);
}

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

fn main() -> () {
    let x: i32 = 5_i32;
    x = x & 6_i32;
    println!(x);
}

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

fn main() -> () {
    let x: u32 = 14_u32;
    x &= 7_u32 + 5_u32;
    println!(x);
}

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

fn main() -> () {
    println!(-128_i8 & -1_i8);
    println!(127_i8 & -128_i8);
    println!(-1_i8 & 127_i8);
}

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

fn main() -> () {
    println!(340282366920938463463374607431768211455_u128
        & 170141183460469231731687303715884105729_u128);
    println!(170141183460469231731687303715884105728_u128
        & 170141183460469231731687303715884105727_u128);
    println!(-170141183460469231731687303715884105728_i128 & -1_i128);
}

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

fn main() -> () {
    let x: u32 = 12_u32;
    exists<'a, 'b> {
        let r: &'a u32 = &'a x;
        println!(and_left::<'a>(r));
        let s: &'b u32 = &'b x;
        println!(and_right::<'b>(s));
    }
}

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

fn main() -> () {
    let x: u32 = 12_u32;
    exists<'a> {
        let r: &'a u32 = &'a x;
        println!(*r & *r);
        println!(*r & 6_u32);
    }
}

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

fn main() -> () {
    println!(7_i32 % 3_i32);
}

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

fn main() -> () {
    println!(-7_i32 % 3_i32);
    println!(7_i32 % -3_i32);
    println!(-7_i32 % -3_i32);
}

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

fn main() -> () {
    println!(13_u32 % 3_u32);
    println!(2_u32 % 7_u32);
}

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

fn main() -> () {
    println!(10_i32 + 7_i32 % 4_i32);
    println!(7_i32 % 4_i32 + 10_i32);
    println!(20_i32 - 7_i32 % 4_i32);
}

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

fn main() -> () {
    println!(10_i32 % 4_i32 % 3_i32);
}

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

fn main() -> () {
    println!(3_i32 * 7_i32 % 4_i32);
    println!(7_i32 % 4_i32 * 3_i32);
}

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

fn main() -> () {
    println!(10_i32 % (4_i32 % 3_i32));
    println!((10_i32 + 7_i32) % 4_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:1785 (all coverage from this test)

fn main() -> () {
    println!(7_i32 % 0_i32);
}

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

fn main() -> () {
    println!(-2147483648_i32 % -1_i32);
}

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

fn main() -> () {
    println!(340282366920938463463374607431768211455_u128 % 2_u128);
    println!(-170141183460469231731687303715884105728_i128 % 3_i128);
    let x: u32 = 7_u32;
    exists<'a> {
        let r: &'a mut u32 = &'a mut x;
        println!(*r % x);
    }
}

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

fn main() -> () {
    println!(12_i32 / 3_i32);
}

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

fn main() -> () {
    println!(7_i32 / 2_i32);
}

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

fn main() -> () {
    println!(-7_i32 / 2_i32);
}

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

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

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

fn main() -> () {
    println!(24_i32 / 4_i32 / 2_i32);
}

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

fn main() -> () {
    println!(24_i32 / (4_i32 / 2_i32));
}

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

fn main() -> () {
    println!(13_u32 / 3_u32);
    println!(0_u32 / 3_u32);
}

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

fn main() -> () {
    println!(7_i32 / -2_i32);
    println!(-7_i32 / -2_i32);
}

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

fn main() -> () {
    println!(20_i32 - 12_i32 / 3_i32);
    println!(12_i32 / 3_i32 - 2_i32);
    println!((20_i32 - 12_i32) / 2_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:1975 (all coverage from this test)

fn main() -> () {
    println!(12_i32 / 0_i32);
}

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

fn main() -> () {
    println!(-2147483648_i32 / -1_i32);
}

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

fn main() -> () {
    println!(24_i32 / 4_i32 * 2_i32);
    println!(20_i32 * 3_i32 / 4_i32);
    println!(24_i32 / (4_i32 * 2_i32));
    println!(2_i32 + 24_i32 / 4_i32 * 2_i32);
}

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

fn main() -> () {
    println!(2_i32 / 7_i32);
    println!(-2_i32 / 7_i32);
}

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

fn main() -> () {
    println!(127_i8 / 2_i8);
    println!(-127_i8 / 2_i8);
    println!(18446744073709551616_u128 / 2_u128);
}

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

fn main() -> () {
    let x: i32 = 0_i32;
    x = 12_i32 / 3_i32;
    println!(x);
}

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/pr531_review_probes.rs:16 (all coverage from this test)

fn main() -> () {
    let x: u32 = 4_u32;
    exists<'a> {
        let r: &'a mut u32 = &'a mut x;
        println!(*r | x);
    }
}

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