-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Better closure error message #42443
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
Better closure error message #42443
Changes from 1 commit
9d188e6
9cbb5f9
94c808c
2c282b8
b1b6490
345b833
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ error[E0525]: expected a closure that implements the `Fn` trait, but this closur | |
15 | | num += 1; | ||
16 | | }; | ||
| |_____^ | ||
17 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nikomatsakis that space is to pad to compensate for the multiline markers. We can add a check for empty lines and avoid it. |
||
18 | Box::new(closure) | ||
| ----------------- the requirement to implement `Fn` derives from here | ||
| | ||
note: closure is `FnMut` because it mutates the variable `num` here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slick |
||
--> $DIR/issue-26046-fn-mut.rs:15:9 | ||
|
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.
One minor point -- in this arm, we emit neither the new note nor the old one. Seems like the old one might still be helpful?
Actually, maybe we should always emit the old note -- but instead of a note, just make it a
span_label
? Seems like it's useful information either way. In other words, the old note tells you "why it has to beFn
", and the new note tells you why it cannot be...If you agree, maybe move the body of the
else
below out and above thisif
, and convertspan_note
tospan_label
(so that it prints within one code snippet)Uh oh!
There was an error while loading. Please reload this page.
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.
Good point, I didn't think about that!