Skip to content

Fix context extension lifetime issue in rules#33

Merged
evg4b merged 6 commits into
masterfrom
fix-context-extension-lifetime
Mar 23, 2026
Merged

Fix context extension lifetime issue in rules#33
evg4b merged 6 commits into
masterfrom
fix-context-extension-lifetime

Conversation

@evg4b
Copy link
Copy Markdown
Owner

@evg4b evg4b commented Mar 22, 2026

Summary

Fixes borrow checker error when using context extension. The ctx.extend() method returns a Box<dyn Context> that was being freed immediately, causing a temporary value lifetime issue.

Changes

  • Store extended context in a variable to ensure it lives long enough for rule checking
  • Update all rule types and integration tests to work with the new pattern
  • Resolves E0716 compiler error in RuleContext::check_rule

Test Plan

  • All unit tests pass
  • All integration tests pass
  • Lint checks pass

🤖 Generated with Claude Code

evg4b and others added 5 commits March 22, 2026 19:38
Update all rule implementations to properly handle context extension.
The issue was that ctx.extend() returned a temporary Box<dyn Context>
that was freed immediately, causing a borrow checker error. Fixed by
storing the extended context in a variable that lives long enough.

Also update all integration tests to work with the new context handling.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Cover all RuleContext::check_rule branches: no extract, with extract,
  when=true, when=false, skipped, extend error, condition error
- Cover GitRepoContext::extend: happy path, message_file inheritance,
  invalid repo error path
- Cover GitRepoContext::variables: None extract and Some extract branches

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@evg4b evg4b merged commit 0c33a0a into master Mar 23, 2026
7 of 13 checks passed
@evg4b evg4b deleted the fix-context-extension-lifetime branch March 23, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant