Skip to content

diagnostics: Fix ICE building a trait ref in method suggestions#157264

Open
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:fix/method-suggest-trait-extra-generics-ice
Open

diagnostics: Fix ICE building a trait ref in method suggestions#157264
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:fix/method-suggest-trait-extra-generics-ice

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

@Dnreikronos Dnreikronos commented Jun 1, 2026

Fixes #157189

When a method call doesn't resolve, the no-method-found diagnostic probes every trait for one with a same-named method and builds a trait ref for it to spot trait items duplicated across crate versions. It only ever passed the receiver as the single argument, which works only when the trait's one generic is Self. Call .borrow() on something and the probe finds Borrow, whose extra Borrowed parameter leaves the args out of step with the trait's generics, so debug_assert_args_compatible fires. Same crash when the receiver type isn't known and there are zero args.

Now the args come from GenericArgs::for_item: the receiver fills Self when we have it, fresh inference variables cover the rest.

When a method call fails to resolve, the suggestion machinery probes
all traits for a method with the same name and builds a trait
reference for the providing trait to detect duplicate trait items
coming from multiple crate versions. It passed only the receiver type
as the single argument, which is correct only for traits whose sole
generic parameter is `Self`. For a trait with further parameters (for
example `Borrow<Borrowed>`), or when the receiver type is unknown, the
argument list no longer matched the trait's generics and tripped the
`debug_assert_args_compatible` assertion, producing an ICE.

Build the argument list with `GenericArgs::for_item` instead, using
the receiver type for `Self` when known and fresh inference variables
for the remaining parameters.
@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 1, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 1, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
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 73 candidates
  • Random selection from 17 candidates

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]: args not compatible with generics for Borrow

3 participants