Skip to content

Handle generic reborrow in expression-use adjustment walking#156795

Open
P8L1 wants to merge 1 commit into
rust-lang:mainfrom
P8L1:fix-generic-reborrow-expr-use-visitor
Open

Handle generic reborrow in expression-use adjustment walking#156795
P8L1 wants to merge 1 commit into
rust-lang:mainfrom
P8L1:fix-generic-reborrow-expr-use-visitor

Conversation

@P8L1

@P8L1 P8L1 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Fixes an ICE in expression-use adjustment walking where Adjust::GenericReborrow could reach a match arm that assumed generic reborrow was unreachable.

GenericReborrow is already emitted by typeck and classified as rvalue-producing elsewhere in expr_use_visitor.rs, so the adjustment walker must handle it explicitly instead of panicking.

This PR models GenericReborrow as a borrow-like use of the source expression:

  • Mutability::Mut is treated like an exclusive/mutable reborrow use.
  • Mutability::Not is treated like a shared/coerce-shared borrow-like use.
  • The source is not moved or treated as a mere copy.

cc @aapoalas
@rustbot label F-reborrow
Fixes #156339
Tracking: #145612

@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

rustbot commented May 21, 2026

Copy link
Copy Markdown
Collaborator

r? @nikomatsakis

rustbot has assigned @nikomatsakis.
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

@P8L1 P8L1 force-pushed the fix-generic-reborrow-expr-use-visitor branch from 53084cc to 90709a5 Compare May 21, 2026 12:01

@aapoalas aapoalas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread compiler/rustc_hir_typeck/src/expr_use_visitor.rs
@theemathas

Copy link
Copy Markdown
Contributor

Does this fix #156339 ?

@P8L1

P8L1 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Does this fix #156339 ?

Yes, this should fix #156339. I tested the repro from that issue on this branch: the Reborrow trait usage during adjustment walk ICE is gone. I also checked the old behavior by restoring the previous GenericReborrow unreachable in expr_use_visitor, and the repro hits the old ICE again there.

The reduced repro can still produce ordinary diagnostics unrelated to this PR, including the trait-method and async-block type errors from the issue, but the ICE from #156339 is the same expression-use GenericReborrow path and is fixed by this change.

@aapoalas

Copy link
Copy Markdown
Contributor

r? @dingxiangfei2009

@P8L1

P8L1 commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

@bors squash

@rust-bors

This comment has been minimized.

* Handle generic reborrow in expression-use adjustment walking
* Require generic reborrow to be terminal in adjustment walks
@rust-bors

rust-bors Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

🔨 2 commits were squashed into a5e4dc9.

@rust-bors rust-bors Bot force-pushed the fix-generic-reborrow-expr-use-visitor branch from 4b11926 to a5e4dc9 Compare May 28, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-reborrow `#![feature(reborrow)]`; see #145612 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 trait usage during adjustment walk

6 participants