-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Improve suggestions when multiples tuples implement the same trait #159672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rust-bors
merged 1 commit into
rust-lang:main
from
rperier:better_suggestions_for_trait_impls_tuples
Aug 1, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/ui/suggestions/multiple_tuples_implement_same_trait_continuous_arities.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| use std::fmt::Debug; | ||
|
|
||
| fn testing_debug<T: Debug>(t: T) {} | ||
| fn testing_mytrait<T: MyTrait>(t: T) {} | ||
|
|
||
| trait MyTrait {} | ||
|
|
||
| impl MyTrait for (i8,) {} | ||
| impl MyTrait for (i8,i8) {} | ||
| impl MyTrait for (i8,i8,i8) {} | ||
| impl MyTrait for (i8,i8,i8,i8) {} | ||
| impl MyTrait for (i8,i8,i8,i8,i8) {} | ||
|
|
||
| struct Foo; | ||
|
|
||
| fn main() { | ||
| testing_debug((1, Foo)); | ||
| //~^ ERROR `Foo` doesn't implement `Debug` [E0277] | ||
| testing_mytrait((1, Foo)); | ||
| //~^ ERROR the trait bound `({integer}, Foo): MyTrait` is not satisfied [E0277] | ||
| } |
42 changes: 42 additions & 0 deletions
42
tests/ui/suggestions/multiple_tuples_implement_same_trait_continuous_arities.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| error[E0277]: `Foo` doesn't implement `Debug` | ||
| --> $DIR/multiple_tuples_implement_same_trait_continuous_arities.rs:17:23 | ||
| | | ||
| LL | testing_debug((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 arity 12 | ||
| and 5 others | ||
| = note: required for `({integer}, Foo)` to implement `Debug` | ||
| note: required by a bound in `testing_debug` | ||
| --> $DIR/multiple_tuples_implement_same_trait_continuous_arities.rs:3:21 | ||
| | | ||
| LL | fn testing_debug<T: Debug>(t: T) {} | ||
| | ^^^^^ required by this bound in `testing_debug` | ||
| help: consider annotating `Foo` with `#[derive(Debug)]` | ||
| | | ||
| LL + #[derive(Debug)] | ||
| LL | struct Foo; | ||
| | | ||
|
|
||
| error[E0277]: the trait bound `({integer}, Foo): MyTrait` is not satisfied | ||
| --> $DIR/multiple_tuples_implement_same_trait_continuous_arities.rs:19:21 | ||
| | | ||
| LL | testing_mytrait((1, Foo)); | ||
| | --------------- ^^^^^^^^ the trait `MyTrait` is not implemented for `({integer}, Foo)` | ||
| | | | ||
| | required by a bound introduced by this call | ||
| | | ||
| = help: the following other types implement trait `MyTrait`: | ||
| (T₁, T₂, …, Tₙ) for tuples of arity 1 up to and including 5 | ||
| note: required by a bound in `testing_mytrait` | ||
| --> $DIR/multiple_tuples_implement_same_trait_continuous_arities.rs:4:23 | ||
| | | ||
| LL | fn testing_mytrait<T: MyTrait>(t: T) {} | ||
| | ^^^^^^^ required by this bound in `testing_mytrait` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
23 changes: 23 additions & 0 deletions
23
tests/ui/suggestions/multiple_tuples_implement_same_trait_discontinuous_arities.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| fn testing_mytrait<T: MyTrait>(t: T) {} | ||
| fn testing_anothertrait<T: AnotherTrait>(t: T) {} | ||
|
|
||
| trait MyTrait {} | ||
|
|
||
| impl MyTrait for (i8,) {} | ||
| impl MyTrait for (i8,i8,i8) {} | ||
| impl MyTrait for (i8,i8,i8,i8) {} | ||
| impl MyTrait for (i8,i8,i8,i8,i8) {} | ||
| impl MyTrait for (i8,i8,i8,i8,i8,i8) {} | ||
|
|
||
| trait AnotherTrait {} | ||
| impl AnotherTrait for (i8,) {} | ||
| impl AnotherTrait for (i8,i8) {} | ||
|
|
||
| struct Foo; | ||
|
|
||
| fn main() { | ||
| testing_mytrait((1, Foo)); | ||
| //~^ ERROR the trait bound `({integer}, Foo): MyTrait` is not satisfied [E0277] | ||
| testing_anothertrait((1, Foo)); | ||
| //~^ ERROR the trait bound `({integer}, Foo): AnotherTrait` is not satisfied [E0277] | ||
| } |
44 changes: 44 additions & 0 deletions
44
tests/ui/suggestions/multiple_tuples_implement_same_trait_discontinuous_arities.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| error[E0277]: the trait bound `({integer}, Foo): MyTrait` is not satisfied | ||
| --> $DIR/multiple_tuples_implement_same_trait_discontinuous_arities.rs:19:21 | ||
| | | ||
| LL | testing_mytrait((1, Foo)); | ||
| | --------------- ^^^^^^^^ the trait `MyTrait` is not implemented for `({integer}, Foo)` | ||
| | | | ||
| | required by a bound introduced by this call | ||
| | | ||
| = help: the following other types implement trait `MyTrait`: | ||
| (i8,) | ||
| (i8, i8, i8) | ||
| (i8, i8, i8, i8) | ||
| (i8, i8, i8, i8, i8) | ||
| (i8, i8, i8, i8, i8, i8) | ||
| note: required by a bound in `testing_mytrait` | ||
| --> $DIR/multiple_tuples_implement_same_trait_discontinuous_arities.rs:1:23 | ||
| | | ||
| LL | fn testing_mytrait<T: MyTrait>(t: T) {} | ||
| | ^^^^^^^ required by this bound in `testing_mytrait` | ||
|
|
||
| error[E0277]: the trait bound `({integer}, Foo): AnotherTrait` is not satisfied | ||
| --> $DIR/multiple_tuples_implement_same_trait_discontinuous_arities.rs:21:26 | ||
| | | ||
| LL | testing_anothertrait((1, Foo)); | ||
| | -------------------- ^^^^^^^^ the trait `AnotherTrait` is not implemented for `({integer}, Foo)` | ||
| | | | ||
| | required by a bound introduced by this call | ||
| | | ||
| help: the following other types implement trait `AnotherTrait` | ||
| --> $DIR/multiple_tuples_implement_same_trait_discontinuous_arities.rs:13:1 | ||
| | | ||
| LL | impl AnotherTrait for (i8,) {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(i8,)` | ||
| LL | impl AnotherTrait for (i8,i8) {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(i8, i8)` | ||
| note: required by a bound in `testing_anothertrait` | ||
| --> $DIR/multiple_tuples_implement_same_trait_discontinuous_arities.rs:2:28 | ||
| | | ||
| LL | fn testing_anothertrait<T: AnotherTrait>(t: T) {} | ||
| | ^^^^^^^^^^^^ required by this bound in `testing_anothertrait` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.