Skip to content

Commit 9b9e473

Browse files
authored
Include --check-cfg=cfg(kani) in the rust flags to avoid a warning about an unknown cfg. (rust-lang#3187)
Starting with the 2024-05-05 toolchain (and the upcoming Rust 1.80 release), the `unexpected_cfgs` lint has been turned on by default. As a result, running `cargo kani` on a crate that has a `#[cfg(kani)]` results in a warning (see rust-lang#3186). To avoid this warning, this PR adds `--check-cfg=cfg(kani)` to `RUSTFLAGS` when Kani invokes `cargo`. Call-outs: On such packages, doing a `cargo build` will also result in this warning, unless: ```rust println!("cargo::rustc-check-cfg=cfg(kani)"); ``` is added to the package's `build.rs` file. However, this warning would only occur with `cargo build` if the package uses the 2024-05-05 toolchain (or newer), or the Rust version used in the package is upgraded to 1.80 (when it's released at the end of July 2024). Since we're likely to release a new version of Kani sooner than the 1.80 release, this PR mitigates the issue that is more likely to impact users (a warning from `cargo kani`). Resolves rust-lang#3186 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 33b7d85 commit 9b9e473

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

kani-driver/src/call_single_file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl KaniSession {
133133
"panic_abort_tests=yes",
134134
"-Z",
135135
"mir-enable-passes=-RemoveStorageMarkers",
136+
"--check-cfg=cfg(kani)",
136137
]
137138
.map(OsString::from),
138139
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright Kani Contributors
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
[package]
5+
name = "unexpected_cfgs"
6+
version = "0.1.0"
7+
edition = "2021"
8+
9+
[dependencies]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERIFICATION:- SUCCESSFUL
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// This test checks that the `unexpected_cfgs` lint (enabled by default as of
5+
// the 2024-05-05 toolchain) does not cause `cargo kani` to emit warnings when
6+
// the code has `#[cfg(kani)]`. Kani avoids the warning by adding
7+
// `--check-cfg=cfg(kani)` to the rust flags.
8+
9+
#![deny(unexpected_cfgs)]
10+
11+
fn main() {}
12+
13+
#[cfg(kani)]
14+
mod kani_checks {
15+
#[kani::proof]
16+
fn check_unexpected_cfg() {
17+
assert_eq!(1, 1);
18+
}
19+
}

0 commit comments

Comments
 (0)