Skip to content

Commit

Permalink
Allow assert with custom message to be used in const contexts (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhassan-aws authored Nov 7, 2022
1 parent 37d742f commit b8c999d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ macro_rules! assert {
// strategy, which is tracked in
// https://github.com/model-checking/kani/issues/692
if false {
let _ = format_args!($($arg)+);
::std::panic!($($arg)+);
}
}};
}
Expand Down
16 changes: 16 additions & 0 deletions tests/kani/Assert/in_const_fn_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test checks that `assert!` with a custom message can be used in a const
//! fn
const fn const_add(x: i32, y: i32) {
assert!(x + y == x, "some message");
}

#[kani::proof]
fn check() {
let x = kani::any();
let y = 0;
const_add(x, y);
}

0 comments on commit b8c999d

Please sign in to comment.