Repository navigation
Description
Summary
Kani 0.68.0's replacement for the no-message assert! macro emits a trailing
semicolon without an enclosing Rust block. Valid expression-position assertions,
including constant initializers, therefore trigger
semicolon_in_expressions_from_macros. With warnings denied, compilation stops
before verification can begin.
A small source-level fix is to make this arm emit an explicit block expression.
We applied that exact change locally, rebuilt the verifier libraries, and verified
both a positive regression and an intentionally false assertion. No application
assertions or warning settings needed to change.
Affected environment
- Kani: 0.68.0.
- Verifier toolchain: nightly-2026-08-21.
- Observed platform: Linux aarch64.
- Package edition: 2024.
- Strict warnings:
warnings = "deny", also exercised withRUSTFLAGS="-D warnings".
These identify the observed configuration, not the earliest affected release or
all affected platforms. The same no-message arm is still present in
main at 4e31125fdb4f01fad95150415cbafe46e0587d66,
checked by source inspection on 2026-09-25; the execution results below are from
0.68.0, not a new run against main.
Related: #1572 covered the message-bearing assert! arm in a match expression and
is closed. This report concerns the remaining no-message arm; the current
message-bearing arms already emit explicit blocks.
Minimal reproducer
Use an isolated library package with this Cargo.toml:
[package]
name = "kani-assert-expression-repro"
version = "0.0.0"
edition = "2024"
publish = false
[workspace]
[lints.rust]
warnings = "deny"
unexpected_cfgs = { level = "deny", check-cfg = ["cfg(kani)"] }src/lib.rs:
#[cfg(kani)]
mod proofs {
const _: () = assert!(true);
const _: () = const { assert!(true) };
fn statement_form() {
assert!(true);
}
#[kani::proof]
fn valid_forms() {
statement_form();
assert!(true);
}
#[kani::proof]
fn deliberate_false_control() {
assert!(false);
}
}With the affected Kani version already installed and set up, run the positive
harness separately:
RUSTFLAGS="-D warnings" cargo kani --harness valid_formsExpected: the valid constant and statement forms compile, and valid_forms
verifies successfully.
Observed with the original macro: compilation reports
semicolon_in_expressions_from_macros for the expression-position expansion.
Denying warnings turns the diagnostic into a compilation error, so this is a
compile-time failure rather than a counterexample to the harness.
The following command is a separate, intentionally failing control:
RUSTFLAGS="-D warnings" cargo kani --harness deliberate_false_controlAfter the fix, it must reach verification and fail specifically at
assertion failed: false. A compilation failure is not a successful negative
control.
Root cause
The affected arm is in
library/std/src/lib.rs at the examined release commit:
($cond:expr $(,)?) => {
kani::assert(!!$cond, concat!("assertion failed: ", stringify!($cond)));
};The outer braces delimit the macro transcriber; they do not emit a Rust block.
The generated tokens consequently end with a semicolon. That is suitable as a
statement, but causes the diagnostic when the macro is used as an expression,
such as the right-hand side of a constant initializer.
Proposed fix
Emit a unit-valued block expression while keeping the existing assertion
statement intact:
- ($cond:expr $(,)?) => {
+ ($cond:expr $(,)?) => {{
// The double negation is to resolve https://github.com/model-checking/kani/issues/2108
kani::assert(!!$cond, concat!("assertion failed: ", stringify!($cond)));
- };
+ }};The inner braces now appear in the expansion. The semicolon remains valid inside
that block. This preserves the existing condition, !! handling, assertion call,
diagnostic string construction, and optional trailing-comma matcher. It adds no
extra assertion call, branch, allocation, or message formatting operation.
Existing validation and downstream workaround
The exact patch above was applied to the pinned source and the verifier/model
libraries were rebuilt using the released Kani compiler. An isolated installation
was used so the original release bundle remained available for comparison.
Changing only the shipped source would not repair the already compiled libraries.
With the rebuilt libraries:
- The reproducer's positive harness compiled under strict warnings and verified.
- The negative harness reached verification and failed only at the intended
assertion failed: falseproperty. - An existing downstream package's retained proof suite also passed while keeping
its original assertion call sites, feature selection, and strict diagnostics.
These are previously obtained local results for this patch, not a claim that an
upstream branch or full upstream CI suite has been tested. The proposed fix is
small enough that downstream projects should not need to maintain a custom
verifier-library build once it is included in an adopted release.
Activity
Fix assert! and cover! expansions in expression contexts (model-check…