Diagnostics doesn't provide proper explaination as to where type annotations should be added #48089
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-type-system
Area: Type system
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
Uh oh!
There was an error while loading. Please reload this page.
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: