Skip to content

Improve suggestions when multiples tuples implement the same trait - #159672

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
rperier:better_suggestions_for_trait_impls_tuples
Aug 1, 2026
Merged

Improve suggestions when multiples tuples implement the same trait#159672
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
rperier:better_suggestions_for_trait_impls_tuples

Conversation

@rperier

@rperier rperier commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@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 Jul 21, 2026
@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
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, types
  • compiler, types expanded to 74 candidates
  • Random selection from 16 candidates

@rperier

rperier commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Perhaps a ui test dedicated to this use case, specifically might be helpful, imho. It was convered by any tests.

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk 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 21, 2026
@rperier
rperier force-pushed the better_suggestions_for_trait_impls_tuples branch from 114f1a4 to f9303a9 Compare July 21, 2026 18:11
@mejrs

mejrs commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Idea: can we style the type like rustdoc does: https://doc.rust-lang.org/nightly/std/fmt/trait.Debug.html#impl-Debug-for-(T,) , like this

(T₁, T₂, …, Tₙ)

I'm a bit worried that it's going to look like shit in a terminal, though...

@rperier

rperier commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Idea: can we style the type like rustdoc does: https://doc.rust-lang.org/nightly/std/fmt/trait.Debug.html#impl-Debug-for-(T,) , like this

(T₁, T₂, …, Tₙ)

I'm a bit worried that it's going to look like shit in a terminal, though...

I like this idea, the output would be more concise and simpler. Plus, I would not have to count the max number of tuples args, so the code would be simpler.

However, I agree with you, how is it about to be rendered in a terminal ? I am going to investigate

@rperier

rperier commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Idea: can we style the type like rustdoc does: https://doc.rust-lang.org/nightly/std/fmt/trait.Debug.html#impl-Debug-for-(T,) , like this

(T₁, T₂, …, Tₙ)

I'm a bit worried that it's going to look like shit in a terminal, though...

I like this idea, the output would be more concise and simpler. Plus, I would not have to count the max number of tuples args, so the code would be simpler.

However, I agree with you, how is it about to be rendered in a terminal ? I am going to investigate

Simply by using UTF8 ? UTF8 can handle these kind of notation, normally (exponent, indices, etc...)

@rperier

rperier commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@rperier
rperier force-pushed the better_suggestions_for_trait_impls_tuples branch from f9303a9 to 93c6b30 Compare July 22, 2026 12:30
@rustbot

This comment has been minimized.

@rperier

rperier commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

What about something like this ? The rendering in a terminal is quiet good.
I have left n as indice of T but I could also display 12 , which is more correct.

@mejrs

mejrs commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

I have left n as indice of T but I could also display 12 , which is more correct.

I do think it would be nice to say "up to tuples of length 12" or something.

@rperier

rperier commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

I have left n as indice of T but I could also display 12 , which is more correct.

I do think it would be nice to say "up to tuples of length 12" or something.

Like :

error[E0277]: `Foo` doesn't implement `Debug`
 --> tests/ui/suggestions/multiple_tuples_implement_same_trait.rs:8:17
  |
8 |     testing((1, Foo));
  |     -------     ^^^ the trait `Debug` is not implemented for `Foo`
  |     |
  |     required by a bound introduced by this call
  |
  = help: the following other types implement trait `Debug`:  
            ()
            (T₁, T₂, …, Tₙ) // up to tuples of length 12
            // Other relevant impls here
          and 5 others
  = note: required for `({integer}, Foo)` to implement `Debug`

?

@rperier
rperier force-pushed the better_suggestions_for_trait_impls_tuples branch from 93c6b30 to 1b78e29 Compare July 22, 2026 14:05
@rperier

rperier commented Jul 22, 2026

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 22, 2026

@mejrs mejrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r? me

Thanks, great work. I love this message specifically being more concise.

How does this diagnostic compose with #[splat]? Can you add a test documenting what that looks like? If it's weird or doesn't work then no need to fix that necessarily, feel free to punt it towards the splat people :)

Also cc @estebank I know you care deeply about how errors show up in the terminal, is use of subscript acceptable to you?

View changes since this review

Comment thread compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs Outdated
Comment thread compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs Outdated
Comment thread compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs Outdated
Comment thread tests/ui/suggestions/multiple_tuples_implement_same_trait.stderr Outdated
@rustbot rustbot assigned mejrs and unassigned oli-obk Jul 22, 2026
@rperier

rperier commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

r? me

Thanks, great work. I love this message specifically being more concise.

How does this diagnostic compose with #[splat]? Can you add a test documenting what that looks like? If it's weird or doesn't work then no need to fix that necessarily, feel free to punt it towards the splat people :)

Also cc @estebank I know you care deeply about how errors show up in the terminal, is use of subscript acceptable to you?

View changes since this review

Sorry, I don't know what #[splat] is . It's a community crate or as part of the compiler ?

@mejrs

mejrs commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Sorry, I don't know what #[splat] is . It's a community crate or as part of the compiler ?

It's an experiment, see https://rust-lang.github.io/rust-project-goals/2026/overloading-for-ffi.html and #153629

@mejrs mejrs 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 25, 2026
@rperier
rperier force-pushed the better_suggestions_for_trait_impls_tuples branch from 1b78e29 to a16ffa9 Compare July 29, 2026 10:05
@rustbot

This comment has been minimized.

@rperier

rperier commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

There are two branches actually, the case when all types implements the same traits , with less than 5 candidates and the case where there are more than 5 candidates. I did not changes anything to the case with less than 5 candidates, I have added a "concise output" for continuous arities (ranges from 0 to N or from K to N) where there are more than 5 candidates.

@rustbot ready

EDIT: in order to be sure that all tuples and continuous by step of 1, I had to sort the candidates. That's why I have updated the output of some tests, only the ordering output of these test have changed.

@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 29, 2026

@mejrs mejrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks good to me, just a few nits

View changes since this review

Comment thread compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs Outdated
Comment thread compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs Outdated
Comment thread tests/ui/editions/never-type-fallback-breaking.e2024.stderr
@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 30, 2026
@rustbot

rustbot commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

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

Instead of displaying all kind of tuples that implement a given trait, which
might flood the user, it displays a concise message only when all the involved
types are tuples.
@rperier
rperier force-pushed the better_suggestions_for_trait_impls_tuples branch from a16ffa9 to 507283d Compare July 31, 2026 16:37
@rustbot

rustbot commented Jul 31, 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.

@rperier

rperier commented Jul 31, 2026

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 31, 2026

@mejrs mejrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 507283d has been approved by mejrs

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 Jul 31, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 1, 2026
…it_impls_tuples, r=mejrs

Improve suggestions when multiples tuples implement the same trait

Fixes rust-lang#152903
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 1, 2026
…it_impls_tuples, r=mejrs

Improve suggestions when multiples tuples implement the same trait

Fixes rust-lang#152903
rust-bors Bot pushed a commit that referenced this pull request Aug 1, 2026
Rollup of 14 pull requests

Successful merges:

 - #159245 (Emit retags in codegen to support BorrowSanitizer (part 5))
 - #159864 (Report "capacity overflow" for oversized Rc<[T]>/Arc<[T]>)
 - #160079 (make atomic operations const)
 - #160124 (Structurally prevent zero-count `BackendRepr::SimdVector`s)
 - #160162 (Make `#[fundamental]` only apply to the first argument of `Box`)
 - #160210 (Remove an outdated FIXME)
 - #160282 (Improve diagnostic for patterns in function pointer types)
 - #157928 (Eagerly fetch typeck results when linting)
 - #159672 (Improve suggestions when multiples tuples implement the same trait)
 - #159861 (Add documentation for the `non_exhaustive` attribute)
 - #159907 (Fix `hidden_glob_reexports` in `rustc_ast`)
 - #159998 (Align expect messages with guidance)
 - #160145 (Expand checks for register_tool)
 - #160307 (Update `minifier` version to `0.4.0`)
@rust-bors
rust-bors Bot merged commit 3ae0608 into rust-lang:main Aug 1, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 1, 2026
rust-timer added a commit that referenced this pull request Aug 1, 2026
Rollup merge of #159672 - rperier:better_suggestions_for_trait_impls_tuples, r=mejrs

Improve suggestions when multiples tuples implement the same trait

Fixes #152903
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Aug 2, 2026
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#159245 (Emit retags in codegen to support BorrowSanitizer (part 5))
 - rust-lang/rust#159864 (Report "capacity overflow" for oversized Rc<[T]>/Arc<[T]>)
 - rust-lang/rust#160079 (make atomic operations const)
 - rust-lang/rust#160124 (Structurally prevent zero-count `BackendRepr::SimdVector`s)
 - rust-lang/rust#160162 (Make `#[fundamental]` only apply to the first argument of `Box`)
 - rust-lang/rust#160210 (Remove an outdated FIXME)
 - rust-lang/rust#160282 (Improve diagnostic for patterns in function pointer types)
 - rust-lang/rust#157928 (Eagerly fetch typeck results when linting)
 - rust-lang/rust#159672 (Improve suggestions when multiples tuples implement the same trait)
 - rust-lang/rust#159861 (Add documentation for the `non_exhaustive` attribute)
 - rust-lang/rust#159907 (Fix `hidden_glob_reexports` in `rustc_ast`)
 - rust-lang/rust#159998 (Align expect messages with guidance)
 - rust-lang/rust#160145 (Expand checks for register_tool)
 - rust-lang/rust#160307 (Update `minifier` version to `0.4.0`)
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit better diagnostic suggestions for trait implementations on tuples

5 participants