Skip to content

Detect errors in opaque type bounds when deriving errors in next solver - #163801

Open
darkraider01 wants to merge 2 commits into
rust-lang:mainfrom
darkraider01:next-solver-derive-opaque-errors
Open

darkraider01 wants to merge 2 commits into
rust-lang:mainfrom
darkraider01:next-solver-derive-opaque-errors

Conversation

@darkraider01

@darkraider01 darkraider01 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Forgetting .await here makes the next solver complain about an opaque-type mismatch, which doesn’t really tell you what went wrong.

The tricky part was tracking down why the diagnostic walker missed the actual trait failure. Opaque-type normalization could fail before its nested goals became visible through the normal candidate traversal.

This change follows those failing goals and reports that the future doesn’t implement Iterator (or whatever trait the function returns). The fix stays in diagnostic derivation and uses existing messages. It still points at the return type, so there’s room to improve the location later.

Added coverage for missing .await, awaited returns, and intentionally returning a future. Forced next-solver mode still has the same 296 baseline failures.

The diagnostic still highlights the declared return type rather than other(), where .await is missing. Improving that location can be done in a follow up maybe?

Fixes #163536

@rustbot

rustbot commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Oct 5, 2026
@rustbot

rustbot commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

r? @dingxiangfei2009

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

self.detect_error_in_self_ty_normalization(goal, pred.projection_term.self_ty())?;
self.detect_non_well_formed_assoc_item(goal, pred.projection_term)?;
}
Some(ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)))

@darkraider01 darkraider01 Oct 5, 2026 •

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.

I’m handling this here because normalization can fail before a candidate gets recorded. The usual diagnostic walk then misses the actual trait failure and reports the opaque mismatch. This fallback lets me reach the missing trait bound instead.

View changes since the review

));
}
}
let () = instantiate_canonical_state(

@darkraider01 darkraider01 Oct 5, 2026 •

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.

Rebuilt the nested goals first, apply the recorded constraints, then revisit them. That order matters here, the goals need the constraints from the failed attempt. I’m using the existing diagnostic probe so the inference changes get rolled back afterward.

View changes since the review

@@ -0,0 +1,32 @@
//@ edition:2021
//@ check-pass

@darkraider01 darkraider01 Oct 5, 2026 •

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.

I kept these in a separate check-pass test to cover both solvers. It checks that adding .await works, and that leaving it out is still fine when the function intentionally returns a future.

View changes since the review

@darkraider01

Copy link
Copy Markdown
Contributor Author

r? JonathanBrouwer

@rustbot

rustbot commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

JonathanBrouwer is currently at their maximum review capacity.
They may take a while to respond.

@JonathanBrouwer

JonathanBrouwer commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

r? types
Don't know enough about the inner workings of the trait solver to feel comfortable reviewing this, sorry
Thanks for fixing the issue tho!

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Oct 5, 2026
@rustbot rustbot assigned spastorino and unassigned JonathanBrouwer Oct 5, 2026
@darkraider01

Copy link
Copy Markdown
Contributor Author

r? types

@rustbot rustbot assigned jackh726 and unassigned spastorino Oct 22, 2026

This branch has not been deployed

No deployments
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. T-types Relevant to the types team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Next trait solver provides confusing error when .await is forgotten

6 participants