-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Don't Add Specialized Notes to Error Messages Pointing at a Type #121717
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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
12 changes: 12 additions & 0 deletions
12
tests/ui/errors/traits/no-specialized-error-for-types-121398.rs
This file contains 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,12 @@ | ||
trait Bar: Iterator {} | ||
|
||
impl Bar for String {} //~ ERROR `String` is not an iterator [E0277] | ||
|
||
impl<T> Bar for Vec<T> {} //~ ERROR `Vec<T>` is not an iterator [E0277] | ||
|
||
use std::ops::IndexMut; | ||
trait Foo<Idx>: IndexMut<Idx> {} | ||
|
||
impl<Idx> Foo<Idx> for String {} //~ ERROR the type `String` cannot be mutably indexed by `Idx` [E0277] | ||
|
||
fn main() {} |
46 changes: 46 additions & 0 deletions
46
tests/ui/errors/traits/no-specialized-error-for-types-121398.stderr
This file contains 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,46 @@ | ||
error[E0277]: `String` is not an iterator | ||
--> $DIR/no-specialized-error-for-types-121398.rs:3:14 | ||
| | ||
LL | impl Bar for String {} | ||
| ^^^^^^ `String` is not an iterator | ||
| | ||
= help: the trait `Iterator` is not implemented for `String` | ||
note: required by a bound in `Bar` | ||
--> $DIR/no-specialized-error-for-types-121398.rs:1:12 | ||
| | ||
LL | trait Bar: Iterator {} | ||
| ^^^^^^^^ required by this bound in `Bar` | ||
|
||
error[E0277]: `Vec<T>` is not an iterator | ||
--> $DIR/no-specialized-error-for-types-121398.rs:5:17 | ||
| | ||
LL | impl<T> Bar for Vec<T> {} | ||
| ^^^^^^ `Vec<T>` is not an iterator | ||
| | ||
= help: the trait `Iterator` is not implemented for `Vec<T>` | ||
note: required by a bound in `Bar` | ||
--> $DIR/no-specialized-error-for-types-121398.rs:1:12 | ||
| | ||
LL | trait Bar: Iterator {} | ||
| ^^^^^^^^ required by this bound in `Bar` | ||
|
||
error[E0277]: the type `String` cannot be mutably indexed by `Idx` | ||
--> $DIR/no-specialized-error-for-types-121398.rs:10:24 | ||
| | ||
LL | impl<Idx> Foo<Idx> for String {} | ||
| ^^^^^^ `String` cannot be mutably indexed by `Idx` | ||
| | ||
= help: the trait `IndexMut<Idx>` is not implemented for `String` | ||
note: required by a bound in `Foo` | ||
--> $DIR/no-specialized-error-for-types-121398.rs:8:17 | ||
| | ||
LL | trait Foo<Idx>: IndexMut<Idx> {} | ||
| ^^^^^^^^^^^^^ required by this bound in `Foo` | ||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | ||
| | ||
LL | impl<Idx> Foo<Idx> for String where String: IndexMut<Idx> {} | ||
| +++++++++++++++++++++++++++ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains 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,4 @@ | ||
fn main() { | ||
let s = String::from("hello"); | ||
for _ in s {} //~ `String` is not an iterator [E0277] | ||
} |
This file contains 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,12 @@ | ||
error[E0277]: `String` is not an iterator | ||
--> $DIR/specialized-error-for-expr.rs:3:14 | ||
| | ||
LL | for _ in s {} | ||
| ^ `String` is not an iterator; try calling `.chars()` or `.bytes()` | ||
| | ||
= help: the trait `Iterator` is not implemented for `String`, which is required by `String: IntoIterator` | ||
= note: required for `String` to implement `IntoIterator` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of flat out removing the information from
rustc_on_unimplemented
, wouldn't it be better to add the information that this obligation is coming from animpl
block so that it can be specially targeted for custom notes too? I'm thinking of things like "implementing this trait requires you to implement this other one because foo". That would require changing therustc_on_unimplemented
annotation itself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comments.
Based on the suggestions, the error would roughly look like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's exactly the right amount of context needed for this.