Skip to content

Resolve the prophecy of a value overwritten through a reference - #311

Open
coord-e wants to merge 1 commit into
mainfrom
claude/gifted-bohr-56e7sa
Open

coord-e wants to merge 1 commit into
mainfrom
claude/gifted-bohr-56e7sa

Conversation

@coord-e

@coord-e coord-e commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Fixes #310.

An assignment through a reference (*x = y, *slot = None) is rewritten by ReborrowVisitor into m1 = &mut *x; *m1 = y, and assign_to_local only assumes ^m1 = y. The old value *m1 was thrown away without being dropped. When it contains a &mut, that borrow's prophecy was never resolved, so the lender was havoc'd after the borrow ended.

Change

  • ReborrowVisitor::visit_assign: if the assigned place goes through a Deref of a reference, drop *m1 (the old value) once the rvalue's reborrows have been processed. A value behind a reference can't have been moved out. Local-rooted places (s.f = .., *boxed = ..) are left alone because their old value may already have been moved, and resolving it again would be unsound.
  • Env::drop_place / Analyzer::drop_place: these are the same dropping assumption as drop_local, applied to a place.
  • tests/ui/{pass,fail}/mut_ref_overwrite.rs: a callee writes through *x and then retargets it. pass was Unsat before this change.

Testing

🤖 Generated with Claude Code

https://claude.ai/code/session_01KXQQHZrWQHhtpyTtWNgBP3


Generated by Claude Code

An assignment through a reference (`*x = y`, `*slot = None`) is
rewritten into a reborrow `m1 = &mut *x` followed by `^m1 = y`, and the
old value `*m1` was discarded without being dropped. When it carries a
`&mut`, that borrow's prophecy was never resolved, leaving the lender
unconstrained after the borrow ends.

A value behind a reference cannot have been moved out, so drop it at
the assignment. Local-rooted places are left alone since their old
value may already have been moved.

Fixes #310

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KXQQHZrWQHhtpyTtWNgBP3
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T21:28:04.146048Z 4401809 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants