Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Conversation

huntiep
Copy link
Contributor

@huntiep huntiep commented Aug 19, 2017

This is a WIP. Fixing ui/suggestions/try-operator-on-main.rs requires implementing the Return 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?

This commit implements the `Source type does not implement Try`
situation of RFC 1859.
@rust-highfive
Copy link
Collaborator

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.

@pnkfelix
Copy link
Member

@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:

  • Source type does not implement Try, vs
  • Return type does not implement Try

?

@huntiep
Copy link
Contributor Author

huntiep commented Aug 23, 2017

@pnkfelix Yes, sorry for not being clear.

@aidanhs aidanhs added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 23, 2017
@carols10cents
Copy link
Member

ping @pnkfelix, do you have an answer for @huntiep's question now that they've clarified?

@nikomatsakis
Copy link
Contributor

r? @nikomatsakis -- I've been mentoring this

@nikomatsakis
Copy link
Contributor

ah, er, didn't meant to steal from @pnkfelix :) either way is fine. @pnkfelix, I missed that you had left some comments.

| -----
| |
| `?` cannot be applied to a value of type `u32`
| in this macro invocation
Copy link
Contributor

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"....

@nikomatsakis
Copy link
Contributor

@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 ? desugaring, it seems like would work.

@@ -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)
Copy link
Contributor

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 `()`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this...aspirational?

Copy link
Contributor

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

Copy link
Contributor Author

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.

@nikomatsakis
Copy link
Contributor

@huntiep I took a shot at elaborating what I had in mind for distinguishing the two cases here: #35946 (comment)

@arielb1 arielb1 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 29, 2017
@arielb1
Copy link
Contributor

arielb1 commented Aug 30, 2017

Superseded by #44191, which improves on_unimplemented while setting the stage for better error reporting for other builtin traits.

@huntiep
Copy link
Contributor Author

huntiep commented Aug 31, 2017

@arielb1 Should I close this then?

@arielb1
Copy link
Contributor

arielb1 commented Aug 31, 2017

@huntiep

Sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants