When multiple traits are applicable for method, do not specialize main message to the first one that applied#153679
Open
estebank wants to merge 1 commit intorust-lang:mainfrom
Open
When multiple traits are applicable for method, do not specialize main message to the first one that applied#153679estebank wants to merge 1 commit intorust-lang:mainfrom
estebank wants to merge 1 commit intorust-lang:mainfrom
Conversation
…n message to the first one that applied
When calling a method that appears on `Iterator`, we often say "`Foo` is not an iterator", even if that method exists in other traits, which is quite confusing and many times nonsensical. Now, if we mention multiple traits we revert the main message back:
```
error[E0599]: no method named `take` found for struct `Foo` in the current scope
--> $DIR/method-call-err-msg.rs:19:7
|
LL | pub struct Foo;
| -------------- method `take` not found for this struct because it doesn't satisfy `Foo: Iterator`
...
LL | / y.zero()
LL | | .take()
| | -^^^^ `Foo` is not an iterator
| |______|
|
|
= note: the following trait bounds were not satisfied:
`Foo: Iterator`
which is required by `&mut Foo: Iterator`
note: the trait `Iterator` must be implemented
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following traits define an item `take`, perhaps you need to implement one of them:
candidate rust-lang#1: `Iterator`
candidate rust-lang#2: `std::io::Read`
```
Collaborator
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Collaborator
|
JohnTitor
reviewed
Mar 11, 2026
| name = item_name, | ||
| ) | ||
| }; | ||
| if candidates_len > 1 { |
Member
There was a problem hiding this comment.
I think this is a bit loose and could cause a regression when it's still unsatisfied but multiple traits are found while a method actually existing. Maybe we can add a check for such a case not to override.
| --> $DIR/method-call-err-msg.rs:19:7 | ||
| | | ||
| LL | pub struct Foo; | ||
| | -------------- method `take` not found for this struct because it doesn't satisfy `Foo: Iterator` |
Contributor
There was a problem hiding this comment.
The error message is now correct, but the labels here still assume that Iterator is the correct trait
JonathanBrouwer
requested changes
Mar 11, 2026
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When calling a method that appears on
Iterator, we often say "Foois not an iterator", even if that method exists in other traits, which is quite confusing and many times nonsensical. Now, if we mention multiple traits we revert the main message back:Fix #113550.