Skip to content

Fix reborrow ICE in MIR place lowering#156803

Open
P8L1 wants to merge 1 commit into
rust-lang:mainfrom
P8L1:fix/reborrow-thir-mir-rvalue-contract
Open

Fix reborrow ICE in MIR place lowering#156803
P8L1 wants to merge 1 commit into
rust-lang:mainfrom
P8L1:fix/reborrow-thir-mir-rvalue-contract

Conversation

@P8L1
Copy link
Copy Markdown
Contributor

@P8L1 P8L1 commented May 21, 2026

Summary

Fixes #156482.

This fixes an internal THIR/MIR contract inconsistency for generic reborrow expressions.

ExprKind::Reborrow is lowered into MIR as Rvalue::Reborrow, but MIR expression categorization treated it as place-like while expr_as_place treated evaluating it as a place as unreachable. That caused the #156482 ICE, where the compiler panicked with entered unreachable code in expr_as_place while building MIR for a generic reborrow expression.

The fix makes the MIR builder contract explicit: a reborrow expression is rvalue-producing. Its source may be a place, but the reborrow expression itself is not an assignable place.

What changed

  • Updated MIR expression categorization so ExprKind::Reborrow is categorized as rvalue-producing rather than place-like.
  • Updated place lowering so reborrow follows the normal rvalue temporary-materialization path if a place is needed.
  • Added a targeted UI regression test covering the exact [ICE]: Reborrow causes entered unreachable code in expr_as_place. #156482 repro.

cc @aapoalas

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 21, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 21, 2026

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

Copy link
Copy Markdown
Contributor

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you <3

View changes since this review

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: Reborrow causes entered unreachable code in expr_as_place.

4 participants