Skip to content

Conversation

@tiif
Copy link
Member

@tiif tiif commented Oct 27, 2025

Fixes rust-lang/trait-system-refactor-initiative#235

Problem

The fundamental issue here is OpaqueTypeCollector operates on rustc_middle::Ty, but check_type_wf operates on HIR.

Since check_type_wf operates on HIR, it can see the stranded opaque and tries to infer it's hidden type. But OpaqueTypeCollector operates on rustc_middle::Ty, so the OpaqueTypeCollector can no longer see a stranded opaque, hence its hidden type could not be inferred.

As a result, the tests ICE'ed at

assert!(!tcx.next_trait_solver_globally());

Proposed solution

This PR detects stranded opaque types during wf check and emit a delayed bug for it.

Alternative solution

@BoxyUwU and I had considered rewriting OpaqueTypeCollector to be a HIR visitor instead of a rustc_middle::Ty visitor, but we believe a HIR-based OpaqueTypeCollector will not work and might not worth the cost of rewriting.

Acknowledgement

This PR is a joint effort with @BoxyUwU :3

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Oct 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2025

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

@tiif
Copy link
Member Author

tiif commented Oct 27, 2025

@rustbot rustbot assigned BoxyUwU and unassigned jackh726 Oct 27, 2025
@tiif tiif changed the title Fix opaque ice Emit delayed bug during wfck for stranded opaque Oct 27, 2025
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Oct 28, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 28, 2025

📌 Commit c797724 has been approved by BoxyUwU

It is now in the queue for this repository.

@bors bors 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 28, 2025
bors added a commit that referenced this pull request Oct 28, 2025
Rollup of 3 pull requests Successful merges: - #148173 (Emit delayed bug during wfck for stranded opaque) - #148177 (Allow codegen backends to indicate which crate types they support) - #148180 (rustdoc: remove `--emit=unversioned-shared-resources`) r? `@ghost` `@rustbot` modify labels: rollup
@bors bors merged commit 1fe1483 into rust-lang:master Oct 28, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Oct 28, 2025
rust-timer added a commit that referenced this pull request Oct 28, 2025
Rollup merge of #148173 - tiif:fix-opaque-ice, r=BoxyUwU Emit delayed bug during wfck for stranded opaque Fixes rust-lang/trait-system-refactor-initiative#235 ## Problem The fundamental issue here is ``OpaqueTypeCollector`` operates on ``rustc_middle::Ty``, but ``check_type_wf`` operates on HIR. Since [check_type_wf](https://github.com/rust-lang/rust/blob/2f7620a5ccfea7d59d1f500e2a2e59cf1c867a1b/compiler/rustc_hir_analysis/src/check/wfcheck.rs#L2262) operates on HIR, it can see the stranded opaque and tries to infer it's hidden type. But ``OpaqueTypeCollector`` operates on ``rustc_middle::Ty``, so the ``OpaqueTypeCollector`` can no longer see a stranded opaque, hence its hidden type could not be inferred. As a result, the tests ICE'ed at https://github.com/rust-lang/rust/blob/34a8c7368c84fc699fc83a8851a02f93fd655931/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs#L253 ## Proposed solution This PR detects stranded opaque types during wf check and emit a delayed bug for it. ## Alternative solution `@BoxyUwU` and I had considered rewriting ``OpaqueTypeCollector`` to be a HIR visitor instead of a ``rustc_middle::Ty`` visitor, but we believe a HIR-based ``OpaqueTypeCollector`` will not work and might not worth the cost of rewriting. ## Acknowledgement This PR is a joint effort with `@BoxyUwU` :3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

6 participants