Skip to content

Do not fail on crates that forbid(unstable_features) - #4688

Open
tautschnig wants to merge 1 commit into
model-checking:mainfrom
tautschnig:fix-forbid-unstable-features
Open

Do not fail on crates that forbid(unstable_features)#4688
tautschnig wants to merge 1 commit into
model-checking:mainfrom
tautschnig:fix-forbid-unstable-features

Conversation

@tautschnig

Copy link
Copy Markdown
Member

Description

Kani injects feature(register_tool) via -Zcrate-attr into every crate it compiles, so crates that forbid(unstable_features) fail to build under Kani with "error: use of an unstable feature" — through no fault of their own. rustls is a prominent example: it applies the forbid unless benchmarking/coverage cfgs are set, so cargo kani on rustls fails immediately.

Downgrade the lint with --force-warn unstable_features, which overrides even a forbid in the crate source. The injected feature gate is a Kani implementation detail, not something the crate author can or should fix, so downgrading unconditionally is the right semantics (the warning remains visible).

Found while evaluating kani autoharness on the top-100 crates.io crates; verified rustls-0.23.42 (previously failing) now compiles under cargo kani --only-codegen.

Testing

New regression test tests/kani/ForbidUnstableFeatures/forbid_unstable_features.rs: a crate with #![forbid(unstable_features)] and a proof harness now verifies successfully. kani-driver unit tests and formatting pass.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@tautschnig
tautschnig requested a review from a team as a code owner July 28, 2026 23:14
Copilot AI review requested due to automatic review settings July 28, 2026 23:14
@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 28, 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 makes Kani more robust when compiling third-party crates that set #![forbid(unstable_features)], which previously failed due to Kani injecting feature(register_tool) via -Z crate-attr. It unconditionally downgrades the unstable_features lint to a warning at the rustc invocation level and adds a regression test to ensure such crates can be verified.

Changes:

  • Add --force-warn unstable_features to Kani’s baseline rustc flags to override crate-level forbid(unstable_features) for injected features.
  • Add a new tests/kani regression test that forbids unstable_features and verifies successfully under Kani.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/kani/ForbidUnstableFeatures/forbid_unstable_features.rs Adds a regression test crate that forbids unstable_features to validate the new driver behavior.
kani-driver/src/call_single_file.rs Extends the base rustc flags with --force-warn unstable_features to prevent injected #![feature] from becoming a hard error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Kani injects 'feature(register_tool)' via -Zcrate-attr into every crate it
compiles, so crates that forbid(unstable_features) -- e.g. rustls, which
gates the forbid on 'not(any(read_buf, bench, coverage_nightly))' -- failed
to build under Kani with 'error: use of an unstable feature', through no
fault of their own.

Downgrade the lint with '--force-warn unstable_features', which overrides
even a forbid in the crate source. The injected feature gate is a Kani
implementation detail, not something the crate author can or should fix.

Verified that rustls-0.23.42 (previously failing) now compiles under
'cargo kani --only-codegen'.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig
tautschnig force-pushed the fix-forbid-unstable-features branch from c02c9b5 to cc5fe8f Compare July 29, 2026 00:42

@feliperodri feliperodri 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.

We should update the test case ui/ice-size-overflow/large_array.rs

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