Add trybuild test for Captured::state lifetime correctness (#314)#378
Add trybuild test for Captured::state lifetime correctness (#314)#378leynos wants to merge 1 commit into
Conversation
`MacroStateGuard::as_ref()` returns a `&State` derived from a `NonNull<Captured<'static>>`, relying on the type system to prevent a `&State` outliving its owning `Captured`. No compile-time test pinned that guarantee after the migration from `eval_to_state` to `render_captured`. Introduce trybuild infrastructure: - `tests/compile_fail_tests.rs` runs the two UI cases; - `tests/ui/captured_state_outlives_captured.rs` holds a `&State` beyond its `Captured` and must fail with E0597 (committed `.stderr` records the expected diagnostic); - `tests/ui/captured_state_within_scope.rs` uses `captured.state()` inside the owning scope and must compile; - `trybuild` added as a dev-dependency with the `diff` feature.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideAdds trybuild-based UI tests to pin the borrow-checker guarantees around Sequence diagram for trybuild-based Captured::state lifetime testssequenceDiagram
actor Developer
participant compile_fail_tests as compile_fail_tests_rs
participant TestCases as trybuild_TestCases
participant rustc
Developer->>compile_fail_tests: run captured_state_lifetime_tests
compile_fail_tests->>TestCases: new()
compile_fail_tests->>TestCases: compile_fail("tests/ui/captured_state_outlives_captured.rs")
TestCases->>rustc: compile captured_state_outlives_captured.rs
rustc-->>TestCases: E0597 matches captured_state_outlives_captured.stderr
compile_fail_tests->>TestCases: pass("tests/ui/captured_state_within_scope.rs")
TestCases->>rustc: compile captured_state_within_scope.rs
rustc-->>TestCases: success (no diagnostics)
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary
Closes #314
Adds the trybuild scaffolding the issue specifies:
tests/compile_fail_tests.rswithcaptured_state_lifetime_testsrunning both UI cases.tests/ui/captured_state_outlives_captured.rs— holds a&Statebeyond the owningCaptured; rejected by the borrow checker (E0597, "captureddoes not live long enough").tests/ui/captured_state_within_scope.rs— usescaptured.state()only within the owningCaptured's lifetime; compiles.trybuild = { version = "1", features = ["diff"] }dev-dependency..stderrrecorded once withTRYBUILD=overwriteand committed.Acceptance checks:
fd -e rs . tests/ui | wc -l→ 2;rg trybuild Cargo.toml→ the new dev-dependency.Validation
make check-fmt/make lint/make test— pass (38 suites, including the new compile-fail target)🤖 Generated with Claude Code
Summary by Sourcery
Add compile-time UI tests to validate the lifetime correctness of
Captured::state()using trybuild.Build:
trybuildas a dev-dependency with thedifffeature enabled.Tests:
Captured::state()lifetime behavior, including a failing outlives case and a passing well-scoped case.