Skip to content

Do not fire unused_crate_dependencies on Kani's injected std extern - #4689

Merged
feliperodri merged 1 commit into
model-checking:mainfrom
tautschnig:fix-nounused-std-extern
Jul 29, 2026
Merged

Do not fire unused_crate_dependencies on Kani's injected std extern#4689
feliperodri merged 1 commit into
model-checking:mainfrom
tautschnig:fix-nounused-std-extern

Conversation

@tautschnig

Copy link
Copy Markdown
Member

Description

Kani unconditionally passes --extern noprelude:std=<kani libstd> so that code referencing std gets Kani's overlay. A #[no_std] crate never references std, so if it also denys unused_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:

error: extern crate `std` is unused in crate `nostd_test`

Add rustc's nounused extern modifier to the injected std (alongside the already-used noprelude); it exists exactly for compiler-injected externs and keeps the lint fully functional for the crate's real dependencies.

Found while evaluating kani autoharness on the top-100 crates.io crates (and while validating #4682, with which this composes: together, a strict-lint no_std crate verifies out of the box).

Testing

New cargo-ui test no-std-strict-lints: a no_std crate with deny(unused_crate_dependencies) and a proof harness now verifies successfully (previously: hard error). Full cargo-ui suite 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.

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>
Copilot AI review requested due to automatic review settings July 29, 2026 00:51
@tautschnig
tautschnig requested a review from a team as a code owner July 29, 2026 00:51
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nounused modifier to Kani’s injected --extern ...:std=... argument.
  • Add a new cargo-ui regression test exercising a no_std crate that denies unused_crate_dependencies and 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
feliperodri added this pull request to the merge queue Jul 29, 2026
Merged via the queue into model-checking:main with commit b82114b Jul 29, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants