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

r? @BoxyUwU

@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
//~| ERROR associated type `Assoc` not found for `Trait`
16
}

Copy link
Member

Choose a reason for hiding this comment

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

can you add a test case for something like -> String<impl Trait> which should also be another way of getting stranded opaques

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, done :)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

find_opaque_ty_constraints_for_rpit ICE for stranded opaques

4 participants