close
Skip to content

diagnostics: point to coroutine body on higher-ranked auto trait errors#156226

Open
shivendra02467 wants to merge 1 commit into
rust-lang:mainfrom
shivendra02467:fix-diagnostic-155880
Open

diagnostics: point to coroutine body on higher-ranked auto trait errors#156226
shivendra02467 wants to merge 1 commit into
rust-lang:mainfrom
shivendra02467:fix-diagnostic-155880

Conversation

@shivendra02467
Copy link
Copy Markdown
Contributor

@shivendra02467 shivendra02467 commented May 6, 2026

Fixes #155880

When encountering a higher-ranked auto trait bound error involving a coroutine or async function,the trait solver previously used the span of the outermost cause (eg. spawn(...) or is_send(...)).

This PR modifies the TraitPlaceholderMismatch formatting logic to walk down the ObligationCauseCode chain.If the obligation originates from a ty::Coroutine or ty::CoroutineWitness, it extracts that specific span, providing a much more accurate underline for the user.

Before:

error: implementation of `Send` is not general enough
  --> src/main.rs:25:5
   |
25 |     is_send(outer())
   |     ^^^^^^^^^^^^^^^^ implementation of `Send` is not general enough

After:

error: implementation of `Send` is not general enough
  --> src/main.rs:13:74
   |
13 |   async fn inner<'a, T: Trait + 'a>(_: T, x: T::Assoc<'a>) -> T::Assoc<'a> {
   |  __________________________________________________________________________^
14 | |     std::future::ready(x).await
15 | | }
   | |_^ implementation of `Send` is not general enough

@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 May 6, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 6, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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 20 candidates

@nnethercote
Copy link
Copy Markdown
Contributor

Seems plausible but I don't know enough about the underlying issue to review effectively. Let's try someone else:

r? @lcnr

@rustbot rustbot assigned lcnr and unassigned nnethercote May 8, 2026
@shivendra02467
Copy link
Copy Markdown
Contributor Author

Hi @lcnr, just a gentle ping on this whenever you have a moment! Since you opened the original issue, I'd love to get your thoughts on this approach.

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.

coroutine higher-ranked auto trait errors should point at the definition whose bound vars are part of the error

4 participants