Make assert! and cover! expand to blocks so they work in expression position - #4897
Closed
tautschnig wants to merge 1 commit into
Closed
tautschnig wants to merge 1 commit into
tautschnig wants to merge 1 commit into
Conversation
…osition Kani's `assert!` (std override) and `cover!` macros expand to a statement with a trailing semicolon. Used in expression position, e.g. as a `match` arm, this triggers the future-incompatible `semicolon_in_expressions_from_non_local_macros` warning in the user's code (the lint's local-macro counterpart, `semicolon_in_expressions_from_macros`, is already deny-by-default). Wrap the expansions in blocks. Add a regression test that denies the lint. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The changes are reviewed and remaining comments are minor documentation nits.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Updates Kani’s assert! and cover! macros to expand as blocks, avoiding semicolon lint warnings in expression positions.
Changes:
- Wraps
assert!andcover!expansions in blocks. - Adds regression coverage for match arms and conditional expressions.
| File | Summary |
|---|---|
tests/kani/Macros/assert_cover_in_expression_position.rs |
Adds expression-position regression coverage. |
library/std/src/lib.rs |
Updates assert! expansion. |
library/kani/src/lib.rs |
Updates cover! expansions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+77
to
+79
| // The block wrapper keeps the expansion valid in expression position (e.g. as a | ||
| // `match` arm): a trailing semicolon there triggers the future-incompatible | ||
| // `semicolon_in_expressions_from_macros` lint in user code. |
Comment on lines
+89
to
+91
| // The block wrapper keeps the expansion valid in expression position (e.g. as a | ||
| // `match` arm): a trailing semicolon there triggers the future-incompatible | ||
| // `semicolon_in_expressions_from_macros` lint in user code. |
Member
|
what is the difference between this PR and #4875? @tautschnig |
Member
Author
|
Closing in favour of #4875. |
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.

Kani's
assert!(std override) andcover!macros expand to a statement with a trailing semicolon. Used in expression position, e.g. as amatcharm, this triggers the future-incompatiblesemicolon_in_expressions_from_non_local_macroswarning in the user's code (the lint's local-macro counterpart,semicolon_in_expressions_from_macros, is already deny-by-default). Wrap the expansions in blocks.Add a regression test,
tests/kani/Macros/assert_cover_in_expression_position.rs, that denies the lint; it fails without the fix.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.