-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Improve Try error messages #43984
Improve Try error messages #43984
Conversation
This commit implements the `Source type does not implement Try` situation of RFC 1859.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@huntiep just to be clear, when you asked "How would I differentiate between the first two situations of the RFC?", are you asking how to differentiate:
? |
@pnkfelix Yes, sorry for not being clear. |
r? @nikomatsakis -- I've been mentoring this |
| ----- | ||
| | | ||
| `?` cannot be applied to a value of type `u32` | ||
| in this macro invocation |
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.
Hmm, we have to get rid of this "in this macro invocation"....
@huntiep hmm, that's a good question! I think I overlooked that point in my mentoring instructions. Really, the easiest way to track this would be if we can further use the span. In particular, if we could give a distinct desugaring code to the "return" or "break" generated by the |
@@ -724,7 +724,9 @@ impl EmitterWriter { | |||
|
|||
// First, find all the spans in <*macros> and point instead at their use site | |||
for sp in span.primary_spans() { | |||
if *sp == DUMMY_SP { | |||
if *sp == DUMMY_SP || | |||
sp.is_compiler_desugaring(CompilerDesugaringKind::QuestionMark) |
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.
Cool =)
--> $DIR/try-unimplemented.rs:21:5 | ||
| | ||
21 | Ok(3u32)?; | ||
| ^^^^^^^^^ cannot use the `?` operator in a function that returns `()` |
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.
is this...aspirational?
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.
i.e., I don't see code that would emit this "cannot use" error
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.
It was intended to test Return type does not implement Try
. Looking at try-operator-on-main
, it has a pretty similiar error message, so maybe it was decided to use that error message instead.
@huntiep I took a shot at elaborating what I had in mind for distinguishing the two cases here: #35946 (comment) |
Superseded by #44191, which improves |
@arielb1 Should I close this then? |
Sure. |
This is a WIP. Fixing
ui/suggestions/try-operator-on-main.rs
requires implementing theReturn type does not implement Try
situation of RFC 1859. This is part of #35946.How would I differentiate between the first two situations of the RFC?