Skip to content

trait_selection: fix assumptions-on-binders diagnostics - #158588

Merged
rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
Dnreikronos:trait_selection/assumptions_binders_diagnostics
Aug 22, 2026
Merged

trait_selection: fix assumptions-on-binders diagnostics#158588
rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
Dnreikronos:trait_selection/assumptions_binders_diagnostics

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

View all comments

fixes #157732

-Zassumptions-on-binders was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (:3 and meoow :c).

This keeps canonical solver responses and ExternalConstraintsData span-free, so source locations do not participate in candidate equality or caching. When a response is applied, EvalCtxt::origin_span is attached to each atomic solver RegionConstraint stored in InferCtxt. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report higher-ranked lifetime bound could not be satisfied at the type use that introduced the failing constraint. UI coverage checks the #157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into #161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.

@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the core trait solver

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 29, 2026
@rustbot rustbot added 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 Jun 29, 2026
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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

@rust-log-analyzer

This comment has been minimized.

@Dnreikronos
Dnreikronos force-pushed the trait_selection/assumptions_binders_diagnostics branch from 6d112e4 to 36f4d5a Compare June 29, 2026 23:09
@rust-log-analyzer

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor

r? types

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jun 30, 2026
@rustbot rustbot assigned jackh726 and unassigned folkertdev Jun 30, 2026
@lcnr

lcnr commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

r? BoxyUwU

We intend to fully rework the way these diagnostics work and the errors are currently intentionally bad as they don't even have span information (they point to the whole containing function).

I think keeping the status quo is preferable as a very explicit "this is still very WIP" and would personally prefer to close this PR

@rustbot rustbot assigned BoxyUwU and unassigned jackh726 Jun 30, 2026
@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

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

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

r? BoxyUwU

We intend to fully rework the way these diagnostics work and the errors are currently intentionally bad as they don't even have span information (they point to the whole containing function).

I think keeping the status quo is preferable as a very explicit "this is still very WIP" and would personally prefer to close this PR

thanks, that makes sense. i was mostly looking at this as remove the placeholder text, but imo you're right that the nicer message is a bit misleading if the span is still basically wrong.

i'll wait for boxyuwu's opinion before closing the pr. if i poke at this again later, i think i'd rather start by carrying more of the failed outlives predicate / binder info through first, then make the diagnostic nicer once it has enough data to not lie.

@BoxyUwU

BoxyUwU commented Jul 14, 2026

Copy link
Copy Markdown
Member

I think I agree with lcnr here 👍 Would you be interested in trying to do a more involved refactor here and figure out properly spanned diagnostics for -Zassumptions-on-binders? i.e. make it so we aren't just pointing to the whole item which the constraint originates from.

I think this would be really useful to have done and I won't get the time to do it for a while because of other priorities (getting std/core to compile and then custom test suite).

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

I think I agree with lcnr here 👍 Would you be interested in trying to do a more involved refactor here and figure out properly spanned diagnostics for -Zassumptions-on-binders? i.e. make it so we aren't just pointing to the whole item which the constraint originates from.

I think this would be really useful to have done and I won't get the time to do it for a while because of other priorities (getting std/core to compile and then custom test suite).

Of course!
I will do my best!

@BoxyUwU

BoxyUwU commented Jul 14, 2026

Copy link
Copy Markdown
Member

sick :3 it's probably a more involved change than your previous PRs so it's probably worth us chatting on zulip about it as you're working on it ✨ I would probably start by looking into where the spans for normal region errors come from (i.e. without -Zassumptions-on-binders) and then look into how to replicate that for -Zassumptions-on-binders

@BoxyUwU

BoxyUwU commented Jul 22, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 22, 2026
@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Dnreikronos
Dnreikronos force-pushed the trait_selection/assumptions_binders_diagnostics branch from 36f4d5a to 269fb71 Compare July 23, 2026 17:10
@Dnreikronos

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 Jul 23, 2026
Dnreikronos added a commit to Dnreikronos/rust that referenced this pull request Aug 20, 2026
Keep rust-lang#158588 focused on reporting solver region constraints. The type-op behavior and its borrowck coverage now live in rust-lang#161423.
@rustbot

This comment has been minimized.

Keep this branch focused on reporting solver region constraints. The type-op behavior and its borrowck coverage are handled separately.
@BoxyUwU

BoxyUwU commented Aug 21, 2026

Copy link
Copy Markdown
Member

@bors r+

sick thanks, once your other PR lands we can come back and re-add the test that you previously had added

@rust-bors

rust-bors Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7bffce8 has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 21, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 21, 2026
…tions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes rust-lang#157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the rust-lang#157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into rust-lang#161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 21, 2026
…tions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes rust-lang#157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the rust-lang#157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into rust-lang#161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 21, 2026
…tions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes rust-lang#157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the rust-lang#157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into rust-lang#161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 22, 2026
…tions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes rust-lang#157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the rust-lang#157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into rust-lang#161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
rust-bors Bot pushed a commit that referenced this pull request Aug 22, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #151061 (Build rustc and codegen backends with -Zembed-metadata=no)
 - #157949 (Allow self in const generics)
 - #158588 (trait_selection: fix assumptions-on-binders diagnostics)
 - #159954 (core: implement float conversion methods)
 - #160136 (Add `Default` implementation for `std::sync::Once`)
 - #160835 (resolver diagnostics: don't swallow labels and point out  similar items as a note, not a label)
 - #161048 (Improve the ABI between the panic runtime and libstd)
 - #161292 (Add safety comments in alloc::Wtf8)
 - #161444 (Add some `rustc_type_ir` comments)
 - #161465 (Remove leftover immediate creation)
 - #152433 (Use `symlink_dir` to create junctions on Windows instead of trying to use symbolic links in `copy_link_internal`)
 - #159098 (Add Arc/Rc::strong_count_from_raw)
 - #159282 (Update documentation for `-Zdump-dep-graph`)
 - #161401 (Remove fields from TypeKind: Bool, Char, Float and Int)
 - #161431 (bootstrap: (offload) be stricter about selected compiler and paths)
 - #161451 (Avoid arming the Windows TLS destructor guard in fibers)
 - #161463 (Add myself to mailmap)
 - #161476 (Use bitset for locals_with_use_data)

Failed merges:

 - #161443 (add internal DSL for testing binders)
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 22, 2026
…tions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes rust-lang#157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the rust-lang#157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into rust-lang#161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 22, 2026
…tions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes rust-lang#157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the rust-lang#157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into rust-lang#161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 22, 2026
…tions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes rust-lang#157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the rust-lang#157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into rust-lang#161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
rust-bors Bot pushed a commit that referenced this pull request Aug 22, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - #151061 (Build rustc and codegen backends with -Zembed-metadata=no)
 - #154992 (Error on projection of dyn noncompat type in old trait solver)
 - #157949 (Allow self in const generics)
 - #158588 (trait_selection: fix assumptions-on-binders diagnostics)
 - #159954 (core: implement float conversion methods)
 - #160136 (Add `Default` implementation for `std::sync::Once`)
 - #160835 (resolver diagnostics: don't swallow labels and point out  similar items as a note, not a label)
 - #161048 (Improve the ABI between the panic runtime and libstd)
 - #161292 (Add safety comments in alloc::Wtf8)
 - #161444 (Add some `rustc_type_ir` comments)
 - #161465 (Remove leftover immediate creation)
 - #159098 (Add Arc/Rc::strong_count_from_raw)
 - #159282 (Update documentation for `-Zdump-dep-graph`)
 - #161401 (Remove fields from TypeKind: Bool, Char, Float and Int)
 - #161431 (bootstrap: (offload) be stricter about selected compiler and paths)
 - #161451 (Avoid arming the Windows TLS destructor guard in fibers)
 - #161463 (Add myself to mailmap)
 - #161476 (Use bitset for locals_with_use_data)
 - #161483 (Warn about running ui-fulldeps tests in stage 1)

Failed merges:

 - #161443 (add internal DSL for testing binders)
@rust-bors
rust-bors Bot merged commit 50d27e1 into rust-lang:main Aug 22, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Aug 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 22, 2026
Rollup merge of #158588 - Dnreikronos:trait_selection/assumptions_binders_diagnostics, r=BoxyUwU

trait_selection: fix assumptions-on-binders diagnostics

fixes #157732

`-Zassumptions-on-binders` was losing the origin of solver region constraints. By the time regionck or borrowck reported them, every constraint received the containing item span, so diagnostics pointed at an entire function or const. Some paths were also still emitting placeholder text (`:3` and `meoow :c`).

This keeps canonical solver responses and `ExternalConstraintsData` span-free, so source locations do not participate in candidate equality or caching. When a response is applied, `EvalCtxt::origin_span` is attached to each atomic solver `RegionConstraint` stored in `InferCtxt`. Late region conversion then uses the span attached to each constraint, including for ambiguity diagnostics.

The affected paths now report `higher-ranked lifetime bound could not be satisfied` at the type use that introduced the failing constraint. UI coverage checks the #157732 call-site diagnostic and the existing regionck alias-outlives case. Unit coverage checks that the spanned evaluator stays in semantic parity with the type-ir evaluator and preserves the first ambiguity origin span.

The type-op behavior I ran into while working on this is split into #161423.

Future work: carry the failed outlives predicate or originating binder far enough through this path to name the exact bound that failed, rather than only pointing at its origin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

[ICE]: assumptions on binder: outlives clauses should not error outside borrowck

7 participants