Repository navigation
Borrow a pointer-typed field itself when replacing it - #324
Merged
Merged
Conversation
ReborrowVisitor picked the Ref/Box arms from the type of the assigned place whenever it did not end in a Deref. For a Box- or &mut-typed struct or tuple field, that borrowed the field's pointee and rewrote `c.page = Box::new(5)` as a write through the old box, leaving the field typed as its pointee (and producing ill-sorted `mut<Mut<..>>` terms for `c.r = r`). Take those arms only when a trailing Deref was stripped, so a field replacement borrows the field itself. Refs #267 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3oq9H8cDHT88svt78yAmn
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Refs #267
ReborrowVisitor::visit_assignchose itsRef/Boxarms from the type ofinner_place. When the assigned place does not end inDeref,inner_placeis the place itself, so for aBox- or&mut-typed struct or tuple field those arms borrowed the field's pointee:c.page = Box::new(5)became a write through the old box. The field was left typed asint, and the next use of the struct aborted (PlaceType::derefunwrap,inconsistent types: got=int, expected=own int).c.v = von a&mutfield builtmut(<Mut<Int>>, <Int>), which the solver rejects as ill-sorted. Any setter likefn set(c: &mut Cell<'a>, v: &'a mut i64) { c.v = v; }failed the whole crate with a verificationError, even if nothing read the field afterwards.With this change the pointer arms are taken only when a trailing
Derefwas actually stripped. A field replacement now falls through to the_arm, which borrows the field itself, just as aVec-typed field already does.Results
Boxfield replaced, then read)safe, and the flipped assertion givesUnsat&mut-field setter (from the comment on #267)Error(ill-sorted term)safe, and the flipped assertion givesUnsatborrowing unbound varThe setter case still loses the old lender's value (
aafterset(&mut c, &mut b)). That is #310, which #311 addresses.Test
Added
tests/ui/{pass,fail}/assign_box_field.rs. All 394 UI tests pass locally with Z3 5.0.0 and the pinned PCSat.cargo fmt --checkandcargo clippy -D warningsare clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q3oq9H8cDHT88svt78yAmn
Generated by Claude Code