-
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
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use r? to explicitly pick a reviewer |
I see you added the tests in the first commit and then made the change in the second commit. This is a good way to do things for PRs like this, because it makes it easy for the reviewer to see the effect of the change on the error messages. Except you didn't add the Everything else seems fine to me but I'm going to say r? @estebank because I don't know the answer to this question:
|
I will do this again: r? @estebank because the bors queue is still showing me as the assignee. |
Could not assign reviewer from: |
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.
Interestingly, #121826 also happens to address the specific case seen in the test here and in the original report, but almost tangentially because of changing the reporting to looking at the root obligation, which in these cases is IntoIterator
instead of the more commonly used Iterator
. I think we need both changes (for people that would write trait T: IntoIterator { .. }
).
I still think that it'd be better to provide more filtering information rather than less.
// Don't add specialized notes on types | ||
if !self.tcx.hir().is_impl_block(obligation.cause.body_id) { |
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 an impl
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 the rustc_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?
error[E0277]: `Vec<T>` does not implement the trait `Iterator`
--> test.rs:12:17
|
12 | impl<T> Bar for Vec<T> {}
| ^^^^^^ Implementing this trait for `Vec<T>` requires you to implement trait `Iterator` for `Vec<T>`
|
= help: consider implementing the trait `Iterator` for `Vec<T>`
note: required by a bound in `Bar`
--> test.rs:10:12
|
10 | trait Bar: Iterator {}
| ^^^^^^^^ required by this bound in `Bar`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
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.
@veera-sivarajan any updates on this? thanks |
Working on it. Will push my updates in a couple of days. |
My implementation of |
@veera-sivarajan wouldn't |
No, it doesn't. It returns
Will try to find some other way to check for types in impl signature. |
Fixes #121398
Previously, the
on_unimplemented
mechanism was adding specialized notes by blindly matching on the type. This resulted in specialized notes for a span pointing toString
.This PR fixes it by checking if the expected obligation is enclosed in a impl block; assuming that calls like
.iter()
can only happen inside a function/method block. While this satisfies all the test cases, I'm not sure if there is a better way to check if a span is pointing to an expression or type.