Skip to content

Skip ignorable places when gathering Reborrow loans - #166070

Open
Dnreikronos wants to merge 3 commits into
rust-lang:mainfrom
Dnreikronos:borrowck/reborrow_behind_shared_ref
Open

Dnreikronos wants to merge 3 commits into
rust-lang:mainfrom
Dnreikronos:borrowck/reborrow_behind_shared_ref

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #165604

This was an ICE in borrowck when you reborrow a Reborrow type through a shared reference, something like let b = &a; reborrow(*b);. Instead of the normal "cannot borrow as mutable" error the compiler just crashed.

When the borrow set gets built, the Rvalue::Ref path already skips places that ignore_borrow says we don't care about, like stuff behind a shared ref. The Borrows dataflow skips them too, for both Ref and Reborrow. But the Reborrow arm never did that check, so it still recorded a loan, and later places_conflict ran into a loan it wasn't expecting and panicked.

So the fix is just doing the same ignore_borrow check for Reborrow that Ref already does. I went this way because it makes both paths act the same, and I'd rather not teach places_conflict about a case that shouldn't get there in the first place.

I added two tests. One is the exclusive reborrow from the issue, which now gives E0596 like you'd expect. The other is CoerceShared through a shared reference, which should still compile fine, and I wanted to be sure skipping the loan didn't break that.

Honestly I thought this would need a bigger change, but once I saw the Ref arm already had the check it felt pretty clear Reborrow just missed it. If someone who knows this code better thinks there's another spot with the same gap, happy to look at it.

Rvalue::Ref already skips places that ignore_borrow covers, and the
Borrows dataflow skips them for both Ref and Reborrow. Reborrow still
recorded the loan, so a reborrow through a shared reference left a
loan that places_conflict does not expect to see.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 16, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 16, 2026
@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

r? @fee1-dead

rustbot has assigned @fee1-dead.
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 79 candidates
  • Random selection from 23 candidates

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

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]: Tracking borrow behind shared reference.

3 participants