Skip to content

Detect cyclic subtypes during generalization in the new solver#157786

Open
PrazwalR wants to merge 1 commit into
rust-lang:mainfrom
PrazwalR:cyclic-subtype-generalization
Open

Detect cyclic subtypes during generalization in the new solver#157786
PrazwalR wants to merge 1 commit into
rust-lang:mainfrom
PrazwalR:cyclic-subtype-generalization

Conversation

@PrazwalR

Copy link
Copy Markdown

The generalizer's occurs check only catches the case where the type variable being instantiated occurs directly in the instantiated type. If the two are merely related via subtyping (e.g. ?a <: &?b where ?a and ?b were already sub-unified), each fulfillment round grows the inferred type by one level until the recursion limit is hit. The resulting overflow is then reported on whichever unrelated obligation trips the limit first, with a misleading span and message:

fn main() {
    let mut v = vec![];
    let x = v.last().unwrap();
    v.push(x); // actual error: should be `v.push(*x)`
}

error[E0275]: overflow evaluating whether `&_` is well-formed
 --> src/main.rs:3:13
  |
3 |     let x = v.last().unwrap();
  |             ^^^^^^^^

Copilot AI review requested due to automatic review settings June 11, 2026 18:41
@rustbot

rustbot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

changes to the core type system

cc @lcnr

@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 Jun 11, 2026
@rustbot

rustbot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @mati865 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
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 20 candidates

This comment was marked as off-topic.

@Kivooeo

Kivooeo commented Jun 12, 2026

Copy link
Copy Markdown
Member

Hi, thank your for your PR. I have a question regarding LLM tools: Was and how LLMs been used to create this PR?

@PrazwalR

Copy link
Copy Markdown
Author

Yes, I used Claude Code to help with this PR. It helped me navigate the relevant code paths and understand how sub_unification_table relates to the generalizer's occurs check, drafting the fix and tests based on my reading of #140375 and #119989,I reviewed and validated everything myself ran the full UI test suite and confirmed the MCVEs produce expected diagnostics. The core insight (sub-unification root equality implies a cyclic type, safe to check only under next_trait_solver()) came from lcnr's comment in #140375; Claude helped me turn that into working code.

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.

5 participants