Add combined contract attribute#118
Conversation
|
Warning Review limit reached
Next review available in: 37 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughAdds a public ChangesCombined contract attribute
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AnnotatedFunction
participant contract
participant ContractClauses
participant FuncWithContracts
AnnotatedFunction->>contract: provide clauses and function tokens
contract->>ContractClauses: parse combined clauses
ContractClauses-->>contract: return contracts
contract->>FuncWithContracts: generate contracted function
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5e9b06e to
1c3b1dd
Compare
8dbfe10 to
9efeb12
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/ui/pass/combined_contract.rs (1)
3-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover combined
invariantclauses in the regression test.This validates
requires,ensures, anddebug_ensures, but the new API also promises combinedinvariantclauses. Add one (for example,debug_invariant(x >= 0)) so both invariant parsing and its pre/post generation paths are covered.Suggested addition
#[contract( requires(x >= 0, "input is non-negative"), + debug_invariant(x >= 0), ensures(ret >= x), debug_ensures(ret == x + 1), )]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/ui/pass/combined_contract.rs` around lines 3 - 7, Add a combined invariant clause, such as debug_invariant(x >= 0), to the contract attribute in the combined contract regression test, alongside the existing requires, ensures, and debug_ensures clauses. Keep the test’s current behavior unchanged while covering invariant parsing and pre/post generation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/implementation/contract.rs`:
- Line 20: Replace the infallible syn::parse_quote! call assigning func in the
contract macro with syn::parse2(...), propagating parse failures through
emit_error(err, toks) as done in the other contract macros. Preserve the
existing ItemFn result for valid input while returning a compile error instead
of panicking on invalid macro input.
---
Nitpick comments:
In `@tests/ui/pass/combined_contract.rs`:
- Around line 3-7: Add a combined invariant clause, such as debug_invariant(x >=
0), to the contract attribute in the combined contract regression test,
alongside the existing requires, ensures, and debug_ensures clauses. Keep the
test’s current behavior unchanged while covering invariant parsing and pre/post
generation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 40c64443-cb14-425e-add1-e72d98cf9bb8
📒 Files selected for processing (6)
CHANGELOG.mdsrc/implementation/contract.rssrc/implementation/mod.rssrc/lib.rstests/issues.rstests/ui/pass/combined_contract.rs
9efeb12 to
c742ce1
Compare
c742ce1 to
04c49d7
Compare
Summary
#[contract(...)]attribute for grouping contract clauses in one macro invocationrequires,ensures,invariant, and mode-prefixed clausescontractunderdeny(unused_imports)Closes #9.
Validation
Summary by CodeRabbit
New Features
#[contract(...)]attribute.Documentation
Tests