Skip to content

Report unsatisfied opaque item bounds instead of a type mismatch under -Znext-solver - #162123

Open
yashksaini-coder wants to merge 2 commits into
rust-lang:mainfrom
yashksaini-coder:issue-162093-tait-on-unimplemented
Open

Report unsatisfied opaque item bounds instead of a type mismatch under -Znext-solver#162123
yashksaini-coder wants to merge 2 commits into
rust-lang:mainfrom
yashksaini-coder:issue-162093-tait-on-unimplemented

Conversation

@yashksaini-coder

@yashksaini-coder yashksaini-coder commented Sep 1, 2026

Copy link
Copy Markdown

LLM disclosure

I used Claude extensively on this PR: to explore the compiler source. The initial diagnosis it produced was wrong twice — the first patch it suggested compiled but was entirely dead code. The actual cause (FreeTy rather than OpaqueTy) came from debug output I added and ran locally at its suggestion. I have read and understand the final patch, and verified it against a local build and the full tests/ui suite.

Fixes #162093

Under -Znext-solver, a TAIT whose hidden type doesn't satisfy the opaque's item bounds reported a bare type mismatch rather than naming the unsatisfied bound. This also meant #[diagnostic::on_unimplemented] on that trait never applied.

Before

error[E0271]: type mismatch resolving `Ta == u32`
 --> src/main.rs:9:19
  |
9 | fn construct() -> Ta {
  |                   ^^ types differ

After

error[E0277]: my custom message
 --> src/main.rs:9:19
  |
9 | fn construct() -> Ta {
  |                   ^^ the trait `Marker` is not implemented for `u32`

What was happening

type Ta = impl Marker; is a free type alias whose value is the opaque, so the failing goal is a projection on a FreeTy alias rather than on the opaque directly.

normalize_free_alias normalizes the alias' value and propagates failure with ?, returning before evaluate_added_goals_and_make_canonical_response. No MakeCanonicalResponse step gets recorded, and candidates_recur only builds a candidate when shallow_certainty was set — so the goal ends up with no candidates at all. BestObligation has nothing to descend into and falls back to the projection obligation, which fulfillment_error_for_no_solution turns into E0271.

The fix recurses into the alias' value from detect_error_from_empty_candidates. That reaches the opaque, which does record a candidate and carries its item bounds as nested GoalSource::AliasWellFormed goals, so the real u32: Marker failure surfaces.

Test changes

Three errors in tests/ui/traits/next-solver/stalled-coroutine-obligations.rs improve from type mismatch resolving to naming the unsatisfied trait bound.

Known gaps

  • RPIT (-> impl Future + Send) has no free alias in front of the opaque, so it still reports E0271 — this is the fourth error in stalled-coroutine-obligations, left unchanged.
  • The ObligationCauseCode::OpaqueReturnType cause code isn't attached, so the return type was inferred to be u32 here note the old solver emits is still missing under next. Visible as a difference between the current and next revisions of the new test.

Full tests/ui run is clean (20484 passed, 0 failed).

r? lcnr

@rustbot

rustbot commented Sep 1, 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 Sep 1, 2026
@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @lcnr (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

@rustbot

This comment has been minimized.

@yashksaini-coder yashksaini-coder changed the title Issue 162093 tait on unimplemented Report unsatisfied opaque item bounds instead of a type mismatch under -Znext-solver Sep 1, 2026
@rustbot

rustbot commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2026
A `Projection` goal on a free alias -- e.g. the `Ta` in
`type Ta = impl Marker;` -- normalizes to the alias' value. When
normalizing that value fails, `normalize_free_alias` returns before
reaching `evaluate_added_goals_and_make_canonical_response`, so no
`MakeCanonicalResponse` step is recorded and the goal ends up with no
candidates at all. `BestObligation` then has nothing to descend into and
falls back to reporting a bare `Ta == u32` type mismatch.

Recurse into the alias' value instead. That reaches the opaque, which does
record a candidate and carries its item bounds as nested
`GoalSource::AliasWellFormed` goals, so the unsatisfied bound is reported
and `#[diagnostic::on_unimplemented]` applies.
@yashksaini-coder
yashksaini-coder force-pushed the issue-162093-tait-on-unimplemented branch from d8c69be to 721f4af Compare September 6, 2026 14:01
@rustbot

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2026
Regression test. Also updates stalled-coroutine-obligations,
where three errors improve from `type mismatch resolving` to naming the
unsatisfied trait bound. The fourth is an RPIT, which has no free alias in
front of the opaque and still reports E0271.
@yashksaini-coder
yashksaini-coder force-pushed the issue-162093-tait-on-unimplemented branch from 721f4af to 812f3a9 Compare September 6, 2026 14:05
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. 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.

Worse error message with TAIT + next_solver

3 participants