Skip to content

Handle generic reborrow in expression-use adjustment walking#156795

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
P8L1:fix-generic-reborrow-expr-use-visitor
Jun 18, 2026
Merged

Handle generic reborrow in expression-use adjustment walking#156795
rust-bors[bot] merged 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
@dingxiangfei2009

Copy link
Copy Markdown
Contributor

@P8L1 Thank you so much for contributing! With the flag implemented, indeed it matches the intention of the feature design.

@bors r+ rollup=always

@rust-bors

rust-bors Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a5e4dc9 has been approved by dingxiangfei2009

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 18, 2026
…-visitor, r=dingxiangfei2009

Handle generic reborrow in expression-use adjustment walking

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 rust-lang#156339
Tracking: rust-lang#145612
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 18, 2026
…-visitor, r=dingxiangfei2009

Handle generic reborrow in expression-use adjustment walking

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 rust-lang#156339
Tracking: rust-lang#145612
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #158026 (`RegionValues`: disable unnecessary range check)
 - #156795 (Handle generic reborrow in expression-use adjustment walking)
 - #157694 (Enhance documentation on wake call memory ordering)
 - #158034 (Fix reborrow source expression visits)
 - #158074 (Document transient connection errors from TcpListener::accept)
 - #158086 (renovate: Loosen dashboard approval and adopt recommended config)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 18, 2026
…-visitor, r=dingxiangfei2009

Handle generic reborrow in expression-use adjustment walking

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 rust-lang#156339
Tracking: rust-lang#145612
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #158026 (`RegionValues`: disable unnecessary range check)
 - #156795 (Handle generic reborrow in expression-use adjustment walking)
 - #157694 (Enhance documentation on wake call memory ordering)
 - #157935 (Make `proc_macro::ConversionErrorKind` non exhaustive)
 - #158002 (Replace `unwrap` with `expect` in `get_module_children`)
 - #158034 (Fix reborrow source expression visits)
 - #158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103)
 - #158074 (Document transient connection errors from TcpListener::accept)
 - #158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard)
 - #158086 (renovate: Loosen dashboard approval and adopt recommended config)
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #158026 (`RegionValues`: disable unnecessary range check)
 - #156795 (Handle generic reborrow in expression-use adjustment walking)
 - #157694 (Enhance documentation on wake call memory ordering)
 - #157935 (Make `proc_macro::ConversionErrorKind` non exhaustive)
 - #158002 (Replace `unwrap` with `expect` in `get_module_children`)
 - #158034 (Fix reborrow source expression visits)
 - #158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103)
 - #158074 (Document transient connection errors from TcpListener::accept)
 - #158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard)
 - #158086 (renovate: Loosen dashboard approval and adopt recommended config)
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
Rollup of 12 pull requests

Successful merges:

 - #156795 (Handle generic reborrow in expression-use adjustment walking)
 - #157694 (Enhance documentation on wake call memory ordering)
 - #157935 (Make `proc_macro::ConversionErrorKind` non exhaustive)
 - #158002 (Replace `unwrap` with `expect` in `get_module_children`)
 - #158009 (Reject `impl const Trait` since the right syntax is `const impl Trait` now)
 - #158034 (Fix reborrow source expression visits)
 - #158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103)
 - #158074 (Document transient connection errors from TcpListener::accept)
 - #158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard)
 - #158086 (renovate: Loosen dashboard approval and adopt recommended config)
 - #158088 (codegen_ssa: no dbginfo for scalable vec local w/ `-O0`)
 - #158089 (Fix invalid "jump-to-def" doc link generation when an item has a `derive` proc-macro)
@rust-bors rust-bors Bot merged commit 95cc3df into rust-lang:main Jun 18, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 18, 2026
rust-timer added a commit that referenced this pull request Jun 18, 2026
Rollup merge of #156795 - P8L1:fix-generic-reborrow-expr-use-visitor, r=dingxiangfei2009

Handle generic reborrow in expression-use adjustment walking

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
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Jun 19, 2026
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#156795 (Handle generic reborrow in expression-use adjustment walking)
 - rust-lang/rust#157694 (Enhance documentation on wake call memory ordering)
 - rust-lang/rust#157935 (Make `proc_macro::ConversionErrorKind` non exhaustive)
 - rust-lang/rust#158002 (Replace `unwrap` with `expect` in `get_module_children`)
 - rust-lang/rust#158009 (Reject `impl const Trait` since the right syntax is `const impl Trait` now)
 - rust-lang/rust#158034 (Fix reborrow source expression visits)
 - rust-lang/rust#158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103)
 - rust-lang/rust#158074 (Document transient connection errors from TcpListener::accept)
 - rust-lang/rust#158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard)
 - rust-lang/rust#158086 (renovate: Loosen dashboard approval and adopt recommended config)
 - rust-lang/rust#158088 (codegen_ssa: no dbginfo for scalable vec local w/ `-O0`)
 - rust-lang/rust#158089 (Fix invalid "jump-to-def" doc link generation when an item has a `derive` proc-macro)
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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