Skip to content

Tweak the rendering of "not general enough" errors on the old trait solver - #163613

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
estebank:not-general-enough
Oct 4, 2026
Merged

rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
estebank:not-general-enough

Conversation

@estebank

@estebank estebank commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
  • Use a note to point at the source of the unmet obligation instead of labels (makes the order of the error consistent regardless of the order of the code)
  • Point at the found impl that doesn't meet the obligation
  • In a few cases, remove the same information being printed twice
  • Support #[primary_span] span: Option<Span> in Subdiagnostics
error: implementation of `TheTrait` is not general enough
  --> $DIR/associated-types-eq-hr.rs:96:5
   |
LL |     tuple_one::<Tuple>();
   |     ^^^^^^^^^^^^^^^^^^^^
   |
note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
  --> $DIR/associated-types-eq-hr.rs:59:8
   |
LL | fn tuple_one<T>()
LL | where
LL |     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `tuple_one`
note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
  --> $DIR/associated-types-eq-hr.rs:35:1
   |
LL | impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The output now is closer to what the next trait solver will emit (E0277).

@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

rustc_macros::diagnostics was changed

cc @TaKO8Ki, @JonathanBrouwer

rustc_error_messages was changed

cc @TaKO8Ki

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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 Oct 1, 2026
@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
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 21 candidates

@rust-bors

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after solving conflicts and nits

View changes since this review

Comment thread compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs Outdated
@JonathanBrouwer

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 Oct 3, 2026
@rustbot

rustbot commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

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

```
error: implementation of `TheTrait` is not general enough
  --> $DIR/associated-types-eq-hr.rs:96:5
   |
LL | fn tuple_one<T>()
   |    --------- due to a where-clause on `tuple_one`...
LL | where
LL |     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
   |        ----------------------------------------------------------- unsatisfied where-clause on `tuple_one`
...
LL |     tuple_one::<Tuple>();
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: ...`Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
  --> $DIR/associated-types-eq-hr.rs:35:1
   |
LL | impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
Use a span note instead of span labels so that when talking about the trait that should have been implemented, we always point at where the obligation was introduced in a consistent place.

```
error: implementation of `TheTrait` is not general enough
  --> $DIR/associated-types-eq-hr.rs:96:5
   |
LL |     tuple_one::<Tuple>();
   |     ^^^^^^^^^^^^^^^^^^^^
   |
note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
  --> $DIR/associated-types-eq-hr.rs:59:8
   |
LL | fn tuple_one<T>()
   |    --------- due to a where-clause on `tuple_one`
LL | where
LL |     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied where-clause on `tuple_one`
note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
  --> $DIR/associated-types-eq-hr.rs:35:1
   |
LL | impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
```
error: implementation of `Lengthen` is not general enough
  --> $DIR/gat-bounds-not-checked-with-right-substitutions.rs:20:20
   |
LL |     type Gat<'a> = &'a str;
   |                    ^^^^^^^
   |
note: `Lengthen<&'0 str>` would have to be implemented for the type `&'a str`, for any lifetime `'0`...
  --> $DIR/gat-bounds-not-checked-with-right-substitutions.rs:12:19
   |
LL | trait Gat {
LL |     type Gat<'a>: for<'b> Lengthen<Self::Gat<'b>>;
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Gat::Gat`
   = note: ...but `Lengthen<&'1 str>` is actually implemented for the type `&'1 str`, for some specific lifetime `'1`
```
@estebank
estebank force-pushed the not-general-enough branch from e114796 to 337f98d Compare October 3, 2026 17:28
@rustbot

rustbot commented Oct 3, 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.

@estebank

estebank commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@bors r=JonathanBrouwer

@rust-bors

rust-bors Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 337f98d has been approved by JonathanBrouwer

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 3, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 3, 2026
…athanBrouwer

Tweak the rendering of "not general enough" errors on the old trait solver

- Use a note to point at the source of the unmet obligation instead of labels (makes the order of the error consistent regardless of the order of the code)
- Point at the found impl that doesn't meet the obligation
- In a few cases, remove the same information being printed twice
- Support `#[primary_span] span: Option<Span>` in `Subdiagnostic`s

```
error: implementation of `TheTrait` is not general enough
  --> $DIR/associated-types-eq-hr.rs:96:5
   |
LL |     tuple_one::<Tuple>();
   |     ^^^^^^^^^^^^^^^^^^^^
   |
note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
  --> $DIR/associated-types-eq-hr.rs:59:8
   |
LL | fn tuple_one<T>()
LL | where
LL |     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `tuple_one`
note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
  --> $DIR/associated-types-eq-hr.rs:35:1
   |
LL | impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

The output now is closer to what the next trait solver will emit (E0277).
jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 3, 2026
…athanBrouwer

Tweak the rendering of "not general enough" errors on the old trait solver

- Use a note to point at the source of the unmet obligation instead of labels (makes the order of the error consistent regardless of the order of the code)
- Point at the found impl that doesn't meet the obligation
- In a few cases, remove the same information being printed twice
- Support `#[primary_span] span: Option<Span>` in `Subdiagnostic`s

```
error: implementation of `TheTrait` is not general enough
  --> $DIR/associated-types-eq-hr.rs:96:5
   |
LL |     tuple_one::<Tuple>();
   |     ^^^^^^^^^^^^^^^^^^^^
   |
note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
  --> $DIR/associated-types-eq-hr.rs:59:8
   |
LL | fn tuple_one<T>()
LL | where
LL |     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `tuple_one`
note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
  --> $DIR/associated-types-eq-hr.rs:35:1
   |
LL | impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

The output now is closer to what the next trait solver will emit (E0277).
rust-bors Bot pushed a commit that referenced this pull request Oct 4, 2026
Rollup of 18 pull requests

Successful merges:

 - #158102 (When compiling without a specified `--edition`, emit a message)
 - #162027 (std: add `fs::rename_noreplace`)
 - #162761 (Lower attributes for functions without bodies)
 - #163161 (implement FCW for `rustc_allowed_through_unstable_modules` items)
 - #163613 (Tweak the rendering of "not general enough" errors on the old trait solver)
 - #162062 (core: fix the docs of PanicInfo::location)
 - #163140 (document safety requirements for atomic intrinsics)
 - #163342 (Don't imply incorrect things about `Global` in the docs of `System`)
 - #163445 (Add safety comments for alloc::str)
 - #163503 (Mark Rc strong/weak count methods must_use)
 - #163548 (fs::set_permissions_nofollow: Android support, test cleanup)
 - #163585 ([triagebot] Create `debugger_visualizer` assign group)
 - #163597 (Add `SplitPathsRef` implementation for motor to make std build)
 - #163602 (Move media & home dirs tests to fs tests.)
 - #163667 (Finalize changes on expect messages for library/core/src/fmt/mod.rs)
 - #163682 ([rustdoc] Correctly link to (imported) enum variants with "jump to def")
 - #163683 (Fix GCC codegen backend comment in bootstrap)
 - #163703 (Move more `rustdoc-html tests` in the right location)

Failed merges:

 - #161491 (Rip out old solver coherence)
rust-bors Bot pushed a commit that referenced this pull request Oct 4, 2026
Rollup of 18 pull requests

Successful merges:

 - #158102 (When compiling without a specified `--edition`, emit a message)
 - #162761 (Lower attributes for functions without bodies)
 - #163161 (implement FCW for `rustc_allowed_through_unstable_modules` items)
 - #163613 (Tweak the rendering of "not general enough" errors on the old trait solver)
 - #162062 (core: fix the docs of PanicInfo::location)
 - #163140 (document safety requirements for atomic intrinsics)
 - #163342 (Don't imply incorrect things about `Global` in the docs of `System`)
 - #163445 (Add safety comments for alloc::str)
 - #163503 (Mark Rc strong/weak count methods must_use)
 - #163548 (fs::set_permissions_nofollow: Android support, test cleanup)
 - #163585 ([triagebot] Create `debugger_visualizer` assign group)
 - #163597 (Add `SplitPathsRef` implementation for motor to make std build)
 - #163602 (Move media & home dirs tests to fs tests.)
 - #163667 (Finalize changes on expect messages for library/core/src/fmt/mod.rs)
 - #163682 ([rustdoc] Correctly link to (imported) enum variants with "jump to def")
 - #163683 (Fix GCC codegen backend comment in bootstrap)
 - #163703 (Move more `rustdoc-html tests` in the right location)
 - #163725 (some crashes fixed with next-solver)

Failed merges:

 - #161491 (Rip out old solver coherence)
@rust-bors
rust-bors Bot merged commit c49221b into rust-lang:main Oct 4, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 4, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 4, 2026
Rollup merge of #163613 - estebank:not-general-enough, r=JonathanBrouwer

Tweak the rendering of "not general enough" errors on the old trait solver

- Use a note to point at the source of the unmet obligation instead of labels (makes the order of the error consistent regardless of the order of the code)
- Point at the found impl that doesn't meet the obligation
- In a few cases, remove the same information being printed twice
- Support `#[primary_span] span: Option<Span>` in `Subdiagnostic`s

```
error: implementation of `TheTrait` is not general enough
  --> $DIR/associated-types-eq-hr.rs:96:5
   |
LL |     tuple_one::<Tuple>();
   |     ^^^^^^^^^^^^^^^^^^^^
   |
note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
  --> $DIR/associated-types-eq-hr.rs:59:8
   |
LL | fn tuple_one<T>()
LL | where
LL |     T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `tuple_one`
note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
  --> $DIR/associated-types-eq-hr.rs:35:1
   |
LL | impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

The output now is closer to what the next trait solver will emit (E0277).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants