Skip to content

Commit b8c999d

Browse files
authored
Allow assert with custom message to be used in const contexts (#1858)
1 parent 37d742f commit b8c999d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ macro_rules! assert {
5454
// strategy, which is tracked in
5555
// https://github.com/model-checking/kani/issues/692
5656
if false {
57-
let _ = format_args!($($arg)+);
57+
::std::panic!($($arg)+);
5858
}
5959
}};
6060
}

tests/kani/Assert/in_const_fn_args.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! This test checks that `assert!` with a custom message can be used in a const
5+
//! fn
6+
7+
const fn const_add(x: i32, y: i32) {
8+
assert!(x + y == x, "some message");
9+
}
10+
11+
#[kani::proof]
12+
fn check() {
13+
let x = kani::any();
14+
let y = 0;
15+
const_add(x, y);
16+
}

0 commit comments

Comments
 (0)