Skip to content

Commit 081ffca

Browse files
authored
Merge branch 'main' into bench-on-pull-request
2 parents 36ced2e + e2cbd21 commit 081ffca

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

kani-compiler/src/kani_compiler.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ impl Callbacks for KaniCompiler {
170170
// injecting `extern crate std` there would pull in a *second* `std`
171171
// (and `core`), causing duplicate-lang-item errors (E0152).
172172
&& compiler.sess.opts.externs.get("std").is_some()
173+
// Do not inject into external (registry/git) dependencies: the
174+
// `#[macro_use]` scope is ambiguous (E0659) with an explicit glob
175+
// import of the same macro name, and external crates may
176+
// legitimately do that (e.g. libc >= 0.2.188 re-exports
177+
// `core::assert` in an internal prelude that its modules
178+
// glob-import, and calls `assert!`). External dependencies thus
179+
// use the real `assert!`/`panic!`/... macros, which Kani models
180+
// soundly, consistent with `no_std` dependencies which never had
181+
// the overrides. Cargo passes `--cap-lints allow` exactly for
182+
// non-local dependencies, so use that as the discriminator (like
183+
// rustc's `Session::opts` consumers do for dependency-only
184+
// behavior); local path/workspace crates and standalone `kani`
185+
// builds keep the overrides.
186+
&& compiler.sess.opts.lint_cap.is_none()
173187
{
174188
inject_kani_macro_overrides(compiler, krate);
175189
}

library/std/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ pub mod prelude {
3232
// Kani's versions here makes `#![no_std]` dependencies that import this prelude
3333
// explicitly (`extern crate std; use std::prelude::v1::*;`, e.g. lazy_static)
3434
// ambiguous against the injected core prelude (E0659). Instead, kani-compiler
35-
// injects those overrides only into the crate under verification (see
36-
// kani_compiler's macro-override injection). The print family is defined in this
35+
// injects those overrides only into local crates, not external (registry/git)
36+
// dependencies (see kani_compiler's macro-override injection). The print family
37+
// is defined in this
3738
// crate (std) with no core-prelude counterpart, so overriding it here is safe and
3839
// applies everywhere (dependencies included), which is important so that a
3940
// dependency's `println!` does not run real formatting/IO during verification.

0 commit comments

Comments
 (0)