Skip to content

Commit 5834a57

Browse files
authored
Define different function for concrete playback (no user impact) (#2407)
1 parent 8d55244 commit 5834a57

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

library/kani/src/lib.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ pub use futures::block_on;
4848
/// ```
4949
#[inline(never)]
5050
#[rustc_diagnostic_item = "KaniAssume"]
51-
pub fn assume(_cond: bool) {
52-
if cfg!(feature = "concrete_playback") {
53-
assert!(_cond, "kani::assume should always hold");
54-
}
51+
#[cfg(not(feature = "concrete_playback"))]
52+
pub fn assume(cond: bool) {
53+
let _ = cond;
54+
}
55+
56+
#[inline(never)]
57+
#[rustc_diagnostic_item = "KaniAssume"]
58+
#[cfg(feature = "concrete_playback")]
59+
pub fn assume(cond: bool) {
60+
assert!(cond, "`kani::assume` should always hold");
5561
}
5662

5763
/// Creates an assertion of the specified condition and message.
@@ -63,12 +69,19 @@ pub fn assume(_cond: bool) {
6369
/// let y = !x;
6470
/// kani::assert(x || y, "ORing a boolean variable with its negation must be true")
6571
/// ```
72+
#[cfg(not(feature = "concrete_playback"))]
73+
#[inline(never)]
74+
#[rustc_diagnostic_item = "KaniAssert"]
75+
pub const fn assert(cond: bool, msg: &'static str) {
76+
let _ = cond;
77+
let _ = msg;
78+
}
79+
80+
#[cfg(feature = "concrete_playback")]
6681
#[inline(never)]
6782
#[rustc_diagnostic_item = "KaniAssert"]
68-
pub const fn assert(_cond: bool, _msg: &'static str) {
69-
if cfg!(feature = "concrete_playback") {
70-
assert!(_cond, "{}", _msg);
71-
}
83+
pub const fn assert(cond: bool, msg: &'static str) {
84+
assert!(cond, "{}", msg);
7285
}
7386

7487
/// Creates a cover property with the specified condition and message.
@@ -153,15 +166,17 @@ pub fn any_where<T: Arbitrary, F: FnOnce(&T) -> bool>(f: F) -> T {
153166
///
154167
/// Note that SIZE_T must be equal the size of type T in bytes.
155168
#[inline(never)]
169+
#[cfg(not(feature = "concrete_playback"))]
156170
pub(crate) unsafe fn any_raw_internal<T, const SIZE_T: usize>() -> T {
157-
#[cfg(feature = "concrete_playback")]
158-
return concrete_playback::any_raw_internal::<T, SIZE_T>();
159-
160-
#[cfg(not(feature = "concrete_playback"))]
161-
#[allow(unreachable_code)]
162171
any_raw_inner::<T>()
163172
}
164173

174+
#[inline(never)]
175+
#[cfg(feature = "concrete_playback")]
176+
pub(crate) unsafe fn any_raw_internal<T, const SIZE_T: usize>() -> T {
177+
concrete_playback::any_raw_internal::<T, SIZE_T>()
178+
}
179+
165180
/// This low-level function returns nondet bytes of size T.
166181
#[rustc_diagnostic_item = "KaniAnyRaw"]
167182
#[inline(never)]

0 commit comments

Comments
 (0)