-
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
Diagnostics doesn't provide proper explaination as to where type annotations should be added #48089
Comments
I would go further and say that we should always point to the definition span of the method that we failed to infer a type argument for, and when it is from another crate, present a reasonable signature, as we do for other diagnostics:
In cases where the type argument comes from a |
Triage: no change |
Output with #65951, which provides the right suggestion:
|
Code
Current Error message
This fails compilation (on purpose), and the error message is as below
Problem
The current error message isn't helpful by producing a message with the type
B
, which can be confusing to users, (it comes from te type signature offn sort_by_key<B, F>(&mut self, _: F) where B: Ord, F: FnMut(&T) -> B
asestebank
points out).As well as that, the positions of the arrows implies that the error comes from.sort_by_key()
, when in fact it comes from the need for type annotations for.sum()
.Proposed solution
The proposed change would be to point to the inside of the function, which would (in my opinion) be clearer to the user that the type annotations are needed inside the function, not with
.sort_by_key()
Playground
The text was updated successfully, but these errors were encountered: