Skip to content

Commit ce697e6

Browse files
authored
Allow &bool in asserts (rust-lang#2117)
1 parent e437fc2 commit ce697e6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

library/std/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ pub mod process;
4444
#[macro_export]
4545
macro_rules! assert {
4646
($cond:expr $(,)?) => {
47-
kani::assert($cond, concat!("assertion failed: ", stringify!($cond)));
47+
// The double negation is to resolve https://github.com/model-checking/kani/issues/2108
48+
kani::assert(!!$cond, concat!("assertion failed: ", stringify!($cond)));
4849
};
4950
($cond:expr, $($arg:tt)+) => {{
50-
kani::assert($cond, concat!(stringify!($($arg)+)));
51+
kani::assert(!!$cond, concat!(stringify!($($arg)+)));
5152
// Process the arguments of the assert inside an unreachable block. This
5253
// is to make sure errors in the arguments (e.g. an unknown variable or
5354
// an argument that does not implement the Display or Debug traits) are

tests/kani/Assert/bool_ref.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! This test makes sure Kani handles the valid `assert!(&b)` syntax where `b` is a `bool`
5+
//! See https://github.com/model-checking/kani/issues/2108 for details.
6+
7+
#[kani::proof]
8+
fn check_assert_with_reg() {
9+
let b1: bool = kani::any();
10+
let b2 = b1 || !b1; // true
11+
assert!(&b2);
12+
}

0 commit comments

Comments
 (0)