Do not fire unused_crate_dependencies on Kani's injected std extern - #4689
Merged
feliperodri merged 1 commit intoJul 29, 2026
Merged
Conversation
Kani unconditionally passes '--extern noprelude:std=<kani libstd>' so that user code referencing std gets Kani's overlay. For #[no_std] crates that deny(unused_crate_dependencies) (e.g. zerocopy-style strict-lint crates), that injected extern trips the lint and the build fails through no fault of the crate's own dependency declarations. Add rustc's 'nounused' extern modifier, which exists exactly for such compiler-injected externs, so the lint keeps working for the crate's real dependencies. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents #[deny(unused_crate_dependencies)] from failing #[no_std] crates under Kani by marking Kani’s injected std extern as nounused, which is intended for compiler-injected externs and preserves the lint’s usefulness for real crate dependencies.
Changes:
- Add the
nounusedmodifier to Kani’s injected--extern ...:std=...argument. - Add a new
cargo-uiregression test exercising ano_stdcrate that deniesunused_crate_dependenciesand verifies successfully.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/cargo-ui/no-std-strict-lints/src/lib.rs | New no_std crate that denies unused_crate_dependencies and includes a Kani proof harness. |
| tests/cargo-ui/no-std-strict-lints/expected | Expects successful verification output for the new regression test. |
| tests/cargo-ui/no-std-strict-lints/Cargo.toml | Minimal Cargo manifest enabling cfg(kani) check-cfg linting for the test crate. |
| kani-driver/src/call_single_file.rs | Updates injected std extern wrapper to include nounused alongside noprelude. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
feliperodri
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Kani unconditionally passes
--extern noprelude:std=<kani libstd>so that code referencingstdgets Kani's overlay. A#[no_std]crate never referencesstd, so if it alsodenysunused_crate_dependencies(as strict-lint crates like zerocopy do), the injected extern trips the lint and the crate fails to build under Kani through no fault of its own dependency declarations:Add rustc's
nounusedextern modifier to the injectedstd(alongside the already-usednoprelude); it exists exactly for compiler-injected externs and keeps the lint fully functional for the crate's real dependencies.Found while evaluating
kani autoharnesson the top-100 crates.io crates (and while validating #4682, with which this composes: together, a strict-lintno_stdcrate verifies out of the box).Testing
New cargo-ui test
no-std-strict-lints: ano_stdcrate withdeny(unused_crate_dependencies)and a proof harness now verifies successfully (previously: hard error). Fullcargo-uisuite passes (30 tests).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.