Skip to content

Reject ordinary stubs of contract targets - #5211

Merged
feliperodri merged 1 commit into
model-checking:mainfrom
Tiramisu-Cake:fix/stub-contract-target-conflict-v2
Nov 20, 2026
Merged

feliperodri merged 1 commit into
model-checking:mainfrom
Tiramisu-Cake:fix/stub-contract-target-conflict-v2

Conversation

@Tiramisu-Cake

Copy link
Copy Markdown
Contributor

On main, combining #[kani::stub(f, g)] with #[kani::proof_for_contract(f)] or #[kani::stub_verified(f)] in the same harness fails with Failed to find contract closure __kani_recursion_check_f. The ordinary stub replaces the body containing f's contract instrumentation.

Kani now rejects these combinations while resolving the harness's stubs, with an error naming the function and conflicting attributes. Ordinary stubs of other functions and reverse-direction stubs remain supported.

Resolves #5206.

Testing: tests/ui/function-contracts/ordinary_stub_target_conflict checks both errors, and tests/expected/function-contract/ordinary_stub_different_target covers a stub of another function and a reverse-direction stub under each attribute. CI in my fork: regression on Ubuntu 22.04, Ubuntu 24.04, Ubuntu 24.04 ARM and macOS 15 Intel, documentation, perf, benchcomp, LLBC, format, Clippy and Cargo Deny passed. The macOS 15 job did not get a runner, and Ubuntu 22.04 passed on a rerun after the intermittent codegen_cache failure addressed by #5207.

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

Disclosure: this change and description were prepared with the help of AI assistants.

@Tiramisu-Cake
Tiramisu-Cake requested review from a team as code owners November 20, 2026 17:09
@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 Nov 20, 2026

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking up #5206. Rejecting the combination while resolving the harness stubs is the right place: the error comes before codegen and replaces the internal "Failed to find contract closure" failure. I tried a few more shapes locally: a trait method target (<S as T>::m, which crashes on main) and a generic target (gen::<u8>) are both rejected with the new message; a repeated stub_verified reports once; and malformed contract paths are still reported only once. The function-contract, stubbing and UI suites, clippy and fmt pass.

Two optional suggestions: the error currently points at the harness function, and pointing at the #[kani::stub] attribute (with a note on the contract attribute) would make it easier to act on; and since harness_stub_map now also reports conflicts, a line in its doc comment would help. Approving.

@feliperodri
feliperodri added this pull request to the merge queue Nov 20, 2026
Merged via the queue into model-checking:main with commit 70d7da0 Nov 20, 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.

Ordinary stub of a proof_for_contract or stub_verified target fails with an internal error

2 participants