Skip to content

Fix ICE in deny_equality_constraints with bare qualified self types#152344

Open
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
lapla-cogito:issue_152338
Open

Fix ICE in deny_equality_constraints with bare qualified self types#152344
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
lapla-cogito:issue_152338

Conversation

@lapla-cogito
Copy link
Contributor

@lapla-cogito lapla-cogito commented Feb 8, 2026

close #152338

When processing equality constraints in where clauses like <T>::Item = T, the compiler would panic with an index underflow. This occurred because deny_equality_constraints assumed that qualified paths always include a trait (e.g., <T as Foo>::Bar), but <T>::Item has no trait part (qself.position == 0). After removing the associated type segment, the path becomes empty, causing underflow in segments.len()-1 in here.

I think this can be prevented by checking the value of qself.position, similar to how it's handled in rustc_resolve/src/late.rs:

// This is a case like `<T>::B`, where there is no
// trait to resolve. In that case, we leave the `B`
// segment to be resolved by type-check.

@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 Feb 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2026

r? @mati865

rustbot has assigned @mati865.
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 21 candidates
  • Random selection from 12 candidates


// Given `<A as Foo>::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.
if let TyKind::Path(Some(qself), full_path) = &predicate.lhs_ty.kind
&& qself.position > 0
Copy link
Member

Choose a reason for hiding this comment

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

For T: Trait, <T>::AssocTy = () we should be able to yield the same suggestion as for T: Trait, T::AssocTy = (). So, instead of bailing out you could handle the case if you want to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neat, thanks for the suggestion! Implemented in here: fd7cadd .

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 8, 2026
@fmease fmease assigned fmease and unassigned mati865 Feb 8, 2026
@Zalathar
Copy link
Member

Zalathar commented Feb 9, 2026

What’s the background leading to this PR?

I’m worried that it’s a machine-generated change, with little or no human understanding behind it.

@lapla-cogito
Copy link
Contributor Author

@Zalathar Do you believe this modification is inappropriate? (If so, I apologize—it simply reflects my incomplete understanding.) Regardless, IIUC, the background for this ICE is as follows: (This expands on the information provided in the PR's description.)

In cases like <T>::Item=RhsTy, when extracting the associated type segment, only the associated type name is included without the trait name. That is, full_path.segments = ["Item"] and qself.position = 0. Consequently, at line 1846, full_path.segments[qself.position..] evaluates to ["Item"], and inside the branch, assoc_path.segments.pop() causes assoc_path to become empty. When computing len on such an empty assoc_path, the result is naturally 0, causing an underflow when calculating len - 1 at here. This then leads to an ICE when accessing the array at here.

@lapla-cogito
Copy link
Contributor Author

However, I'm not very experienced in creating proper suggestions as mentioned above, so I may need some time to verify my implementation works well, which might delay when I can push a new version.

@lapla-cogito
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 9, 2026
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]: ast validation: index out of bounds: the len is 0 but the index is 18446744073709551615

5 participants