-
Notifications
You must be signed in to change notification settings - Fork 182
Fix assert! and cover! expansions in expression contexts #4875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
feliperodri
merged 5 commits into
model-checking:main
from
trevordcampbell:fix-assert-expression-contexts
Sep 29, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc25a4a
Fix no-message assert expansion in expression contexts
trevordcampbell cb23c20
Fix cover macro expression expansions and document assertion block
trevordcampbell d6175fb
Merge branch 'main' into fix-assert-expression-contexts
trevordcampbell 33649c3
Merge upstream main into fix-assert-expression-contexts
trevordcampbell e3f659f
Merge branch 'main' into fix-assert-expression-contexts
tautschnig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Status: SATISFIED\ | ||
| Description: "cover location"\ | ||
| main.rs:16:17 in function cover_expression_contexts | ||
|
|
||
| Status: SATISFIED\ | ||
| Description: "cover condition: counted_true(&mut evaluations)"\ | ||
| main.rs:17:17 in function cover_expression_contexts | ||
|
|
||
| Status: UNSATISFIABLE\ | ||
| Description: "unsatisfiable cover condition"\ | ||
| main.rs:18:17 in function cover_expression_contexts | ||
|
|
||
| ** 2 of 3 cover properties satisfied | ||
|
|
||
| VERIFICATION:- SUCCESSFUL |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| #![deny(warnings)] | ||
|
|
||
| fn counted_true(evaluations: &mut u8) -> bool { | ||
| *evaluations += 1; | ||
| *evaluations == 1 | ||
| } | ||
|
|
||
| // Regression for #4874: expression-position cover! calls must still emit coverage properties. | ||
| #[kani::proof] | ||
| fn cover_expression_contexts() { | ||
| let mut evaluations = 0; | ||
|
|
||
| let _: () = kani::cover!(); | ||
| let _: () = kani::cover!(counted_true(&mut evaluations),); | ||
| let _: () = kani::cover!(false, "unsatisfiable cover condition"); | ||
|
|
||
| assert!(evaluations == 1); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| //! Regression for https://github.com/model-checking/kani/issues/4874: | ||
| //! No-message assertions must expand to expressions without trailing semicolons. | ||
|
|
||
| #![deny(warnings)] | ||
|
|
||
| const _: () = assert!(true); | ||
| const _: () = const { assert!(true) }; | ||
|
|
||
| fn require_unit(_: ()) {} | ||
|
|
||
| #[kani::proof] | ||
| fn expression_contexts() { | ||
| assert!(true); | ||
| let () = assert!(true); | ||
| require_unit(assert!(true,)); | ||
| let () = { assert!(true) }; | ||
| match kani::any::<bool>() { | ||
| true => assert!(true), | ||
| false => assert!(true,), | ||
| } | ||
| } | ||
|
|
||
| #[kani::proof] | ||
| fn condition_is_evaluated_once() { | ||
| let mut evaluations = 0u8; | ||
| assert!({ | ||
| evaluations += 1; | ||
| true | ||
| }); | ||
| assert_eq!(evaluations, 1); | ||
| } | ||
|
|
||
| #[kani::proof] | ||
|
feliperodri marked this conversation as resolved.
|
||
| #[kani::should_panic] | ||
| fn false_assertion_still_fails() { | ||
| assert!(false); | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.