fix(lowering): eliminate spurious E3002 alongside E3001 for moved struct members - #9994
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).
PR SummaryMedium Risk Overview When a scattered (destructured) struct is reassembled and a member was already moved, lowering still emits Borrow-check snapshots are updated accordingly, including a new regression case and refreshed expectations (returns/remaps use the original moved vars; one E3002 case now points at control-flow divergence rather than a panic note). Reviewed by Cursor Bugbot for commit 439b76f. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 513bc9906b
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 513bc99. Configure here.
513bc99 to
439b76f
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi resolved 2 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).


Summary
When a non-copy variable is moved (used more than once), the borrow checker previously created a fresh dummy variable to represent the already-moved value. This dummy variable had no corresponding lowering statement, which caused spurious
E3002("Variable not dropped") errors to appear alongside the realE3001("Variable was previously moved") error. Additionally, when assembling scattered (destructured) struct values that contained a moved member, the reconstructed struct variable was discarded and a new dummy variable was returned, causing the struct reconstruction statements to be emitted but their result to be orphaned.The fix changes
MovedVarto carry the originalVariableIdinstead of just theTypeId. When a move error is detected, the original variable ID is reused rather than allocating a new dummy. When assembling a scattered struct that contains a moved member, the struct is still reconstructed (so the statements are valid), and the resulting variable ID is propagated through theMovedVarerror. A new test case (Spurious E3002 alongside E3001 for orphaned inner struct construction) is added to confirm the fix.Type of change
Please check one:
Why is this change needed?
When a non-copy variable was used after being moved, the compiler emitted a spurious
E3002error in addition to the correctE3001error. This happened because a dummy variable was created to stand in for the moved value, but no statement ever defined that dummy variable, leaving it "undropped" from the borrow checker's perspective. Similarly, struct reconstruction statements were being emitted for orphaned variables, producing inconsistent lowering IR.What was the behavior or documentation before?
E3001(variable was previously moved) and a spuriousE3002(variable not dropped) diagnostic.E3002note incorrectly pointed to the second use site and cited a potential panic as the reason, rather than pointing to the divergence caused by theifbranch.struct_constructstatements in the lowered IR.What is the behavior or documentation after?
E3001diagnostic.E3002note now correctly identifies the divergence (e.g., anifblock) rather than a panic site.Related issue or discussion (if any)
Bug repro captured in the new test:
Spurious E3002 alongside E3001 for orphaned inner struct construction.Additional context
The
PanicDestructtrait note was also removed from theE3002diagnostic output, as it is no longer emitted in the updated test expectations.