Skip to content

reborrow: Fix various ICEs related to auto reborrowing of user-space types - #163769

Merged
rust-bors[bot] merged 10 commits into
rust-lang:mainfrom
jakubadamw:fix-various-reborrow-ices
Oct 25, 2026
Merged

rust-bors[bot] merged 10 commits into
rust-lang:mainfrom
jakubadamw:fix-various-reborrow-ices

Conversation

@jakubadamw

@jakubadamw jakubadamw commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

I appreciate the feature is a lang experiment, but it probably won’t hurt to get rid of these ICEs if the fix is relatively striaghtforward. And so this PR fixes several ICEs with #![feature(reborrow)]. Most of them happen when a Reborrow or CoerceShared impl is wrong. Coherence reports an error for the impl, but typeck still lets code reborrow through it. Then borrowck (or const eval) crashes, because the implementation isn't the shape it expects. Fix: when a reborrow coercion goes through, check whether coherence had already rejected any Reborrow/CoerceShared impl. If it did, taint the body so that borrowck and const evaluation skip it.

Related tracking issue: #145612

Note: invalid reborrows that only come from a where clause still ICE – that still needs a fix.

Tests: one test per issue closed, using the code from the issues’ contents. #162108's code no longer reproduces as posted, however, so its test uses a slightly smaller version that hits the same ICE. I also moved the reborrow crashes/ tests that don't crash any more into tests/ui/reborrow.

LLM disclosure: I used Claude Opus 5.5 to research the common denominator between the issues and come up with the solution that turns these ICEs into graceful compile-time errors. It also extracted the tests from the issues and extended them with the right error annotations, but I subsequenty verified them manually against the issues.

Closes #156307.
Closes #156308.
Closes #156311.
Closes #156315.
Closes #158149.
Closes #162108.
Closes #162141.
Closes #162142.

@rustbot

rustbot commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@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 Oct 4, 2026
@rustbot

rustbot commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

r? @Walnut356

rustbot has assigned @Walnut356.
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 77 candidates
  • Random selection from 18 candidates

@Walnut356

Copy link
Copy Markdown
Contributor

That makes sense, and the code changes look alright. Just in case, cc @aapoalas

@Walnut356

Copy link
Copy Markdown
Contributor

I apologize for the delay

@bors r+

@rust-bors

rust-bors Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e4206ab has been approved by Walnut356

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 Oct 25, 2026

@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.

Thank you, this is excellent! I had no idea doing something like this was necessary to stop the compiler from actually continuing with the lowering/compliation of Reborrow/CoerceShared :)

View changes since this review

rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #160404 (fd-views: AsRef<File>&Co. for BorrowedFd)
 - #161362 ( rustdoc: Correctly handle reexports when --document-private-items is used)
 - #163769 (reborrow: Fix various ICEs related to auto reborrowing of user-space types)
 - #164764 (Test(lib/sync): Fix `test_rwlock_max_readers` for 32bit architectures)
 - #164860 (std::fs: read interrupted by a signal, read_buf_exact_at reports EOF.)
 - #164869 (rustc_codegen_gcc subtree update)
 - #157123 (library: optimize truncate method)
 - #159916 (Optimize `str.escape_default().to_string()`)
 - #163510 (process: Improve the output of `Debug` for `ExitStatus` on Unix)
 - #164508 (ping me for layout invariant changes)
 - #164758 (Update dependency jinja2 to v3.1.6 [SECURITY])
 - #164816 (Take the colon span into account for struct field initializers)
 - #164836 (Add regression test for #162109)
 - #164846 (Remove contradictory inequalities from overflow safety docs)
 - #164857 (Do not checkout Cargo for bootstrap tests)
 - #164868 (Fix skipping library build with `--keep-stage[-std]`)
 - #164872 (cg_llvm: clarify Send / Sync story for modules)
 - #164880 (Add context span showing item that can't be annotated)
 - #164881 (Add FIXME comments to `from_ascii_bytes_radix_impl`)
 - #164884 (Windows: bounds-check the reparse point name in `read_link`)
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #160404 (fd-views: AsRef<File>&Co. for BorrowedFd)
 - #161362 ( rustdoc: Correctly handle reexports when --document-private-items is used)
 - #163769 (reborrow: Fix various ICEs related to auto reborrowing of user-space types)
 - #164764 (Test(lib/sync): Fix `test_rwlock_max_readers` for 32bit architectures)
 - #164860 (std::fs: read interrupted by a signal, read_buf_exact_at reports EOF.)
 - #164869 (rustc_codegen_gcc subtree update)
 - #157123 (library: optimize truncate method)
 - #159916 (Optimize `str.escape_default().to_string()`)
 - #163510 (process: Improve the output of `Debug` for `ExitStatus` on Unix)
 - #164508 (ping me for layout invariant changes)
 - #164758 (Update dependency jinja2 to v3.1.6 [SECURITY])
 - #164816 (Take the colon span into account for struct field initializers)
 - #164836 (Add regression test for #162109)
 - #164846 (Remove contradictory inequalities from overflow safety docs)
 - #164857 (Do not checkout Cargo for bootstrap tests)
 - #164868 (Fix skipping library build with `--keep-stage[-std]`)
 - #164872 (cg_llvm: clarify Send / Sync story for modules)
 - #164880 (Add context span showing item that can't be annotated)
 - #164881 (Add FIXME comments to `from_ascii_bytes_radix_impl`)
 - #164884 (Windows: bounds-check the reparse point name in `read_link`)
@rust-bors
rust-bors Bot merged commit 5638085 into rust-lang:main Oct 25, 2026
14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
Rollup merge of #163769 - jakubadamw:fix-various-reborrow-ices, r=Walnut356

reborrow: Fix various ICEs related to auto reborrowing of user-space types

I appreciate the feature is a lang experiment, but it probably won’t hurt to get rid of these ICEs if the fix is relatively striaghtforward. And so this PR fixes several ICEs with `#![feature(reborrow)]`. Most of them happen when a `Reborrow` or `CoerceShared` impl is wrong. Coherence reports an error for the impl, but typeck still lets code reborrow through it. Then borrowck (or const eval) crashes, because the implementation isn't the shape it expects. Fix: when a reborrow coercion goes through, check whether coherence had already rejected any `Reborrow`/`CoerceShared` impl. If it did, taint the body so that borrowck and const evaluation skip it.

Related tracking issue: #145612

Note: invalid reborrows that only come from a `where` clause still ICE – that still needs a fix.

Tests: one test per issue closed, using the code from the issues’ contents. #162108's code no longer reproduces as posted, however, so its test uses a slightly smaller version that hits the same ICE. I also moved the reborrow crashes/ tests that don't crash any more into tests/ui/reborrow.

**LLM disclosure**: I used Claude Opus 5.5 to research the common denominator between the issues and come up with the solution that turns these ICEs into graceful compile-time errors. It also extracted the tests from the issues and extended them with the right error annotations, but I subsequenty verified them manually against the issues.

Closes #156307.
Closes #156308.
Closes #156311.
Closes #156315.
Closes #158149.
Closes #162108.
Closes #162141.
Closes #162142.
@rustbot rustbot added this to the 1.101.0 milestone Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment