Skip to content

Fix ICE in deny_equality_constraints with bare qualified self types#152344

Closed
lapla-cogito wants to merge 1 commit into
rust-lang:mainfrom
lapla-cogito:issue_152338
Closed

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

Conversation

@lapla-cogito

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

Copy link
Copy Markdown
Contributor

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

rustbot commented Feb 8, 2026

Copy link
Copy Markdown
Collaborator

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

Comment thread tests/ui/where-clauses/equality-constraint-with-bare-qself.rs Outdated

// 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
Copy Markdown
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
Copy Markdown
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

rustbot commented Feb 8, 2026

Copy link
Copy Markdown
Collaborator

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
Comment thread tests/ui/where-clauses/equality-constraint-with-bare-qself.rs
@Zalathar

Zalathar commented Feb 9, 2026

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@fmease

fmease commented Mar 24, 2026

Copy link
Copy Markdown
Member

I'm very sorry for the delay.

A lot of this code may soon go away depending on if #153513 (or rather a more drastic version of it that removes most code related to equality predicates) gets waved through.

Let's block this PR on it. It might get accepted or rejected soon.
@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 24, 2026
@rust-bors

rust-bors Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #157586) made this pull request unmergeable. Please resolve the merge conflicts.

@fmease

fmease commented Jun 8, 2026

Copy link
Copy Markdown
Member

As announced, this has been superseded by #153513. I'm now going to close this PR, thanks a lot for your contribution and your understanding.

@fmease fmease closed this Jun 8, 2026
@lapla-cogito lapla-cogito deleted the issue_152338 branch June 8, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-blocked Status: Blocked on something else such as an RFC or other implementation work. 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