-
Notifications
You must be signed in to change notification settings - Fork 13k
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
use help rather than span note for no method error; a slight rephrasing #39441
use help rather than span note for no method error; a slight rephrasing #39441
Conversation
The use of the `span_note` diagnostic method resulted in error messages that some users (including the present author) found very confusing: the code snippet and highlighted span displayed with the "did you mean" note was easy to interpret as a suggested edit (as if it had been set by `span_suggestion`), but was in fact identical to the snippet/span displayed just above, indicating the error in the original code, making it look as if the compiler was suggesting a no-op change. To remedy this, we use `help` instead of `span_note`, and reword one of the affected messages to emphasize the concept of accessing a field being different from calling a method (when the message just said, "did you mean to write `self.foo`", it was not immediately obvious that this was meant in contrast to `self.foo()`, with method-call parens). Resolves rust-lang#38321.
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
Can you add a screenshot of actual and of new output please? |
how about moving to a suggestion entirely? |
@GuillaumeGomez Screenshot added. @oli-obk Respectfully, I disagree: I'd rather conserve vertical terminal space and have the correction in a one-line CI failure is spurious, as if our friend Travis has been sick lately. |
This does feel like a suggestion, rather than a help message because it is giving you a specific suggestion for fixing the code. On the other hand, I believe we tend to use suggestions when we are more sure that the suggestion is correct (here they might have meant something completely different). The advantage of using suggestion rather than help is that it allows automatic fixing by tools. OTOH, this PR is clearly an improvement and I do prefer the 'after' screenshot, so I don't object to this. |
I prefer the after screenshot as well. Waiting for @jonathandturner's confirmation. |
Actually, rustc only prints out one line.
see #39458 for distinguishing between guesses and suggestions Note: don't block this PR on account of that. It's definitely an improvement, there's no reason not to merge this and revisit making it a suggestion/guess later. |
My current thinking is that if the suggestions are small and directly for the underlined text, we should say them. For example:
The reason being that the faster we can get the person reading the error to know what to do to fix the issue, the better. In some cases, the suggestion is enough to jog your memory of "oh yeah, that's a field, not a method" Rather than taking up space to give the error and the suggestion, for simple suggestions, it's easier to just make them a label. For suggestions that don't easily fall into that category, like this one:
It's better to have a separate suggestion because it's a different span than the error (here, we're showing a larger expression surrounded by parentheses). There isn't a hard-fast rule or anything. I think we're still trying to figure out what is best. But my general rule is "less is more". If we can show less text to the user and enable to fix the issue is a similar amount of time, that's a good change. |
great idea. When the suggestion span and the error span are exactly the same, we can use the shorthand. |
@jonathandturner part of the problem where is that the actual span is instead
which is leads to the confusion. Agree with the rest of the points. |
@estebank - I wonder if we can fix the span that's giving the error, since the span should probably cover the whole function call piece rather than just the symbol name. Curious what @nikomatsakis thinks. |
@jonathandturner that seems eminently doable... we're probably working hard to only underline the method name right now, versus the whole call. |
yeah so the code like this: self.report_method_error(method_name.span,
expr_t,
method_name.node,
Some(rcvr),
error,
Some(args)); is passing |
@nikomatsakis @jonathandturner what's the disposition here? |
☔ The latest upstream changes (presumably #40911) made this pull request unmergeable. Please resolve the merge conflicts. |
@zackmdavis sorry about that, I completely forgot that there was already a PR for this. |
The use of the
span_note
diagnostic method resulted in error messagesthat some users (including the present author) found very confusing: the
code snippet and highlighted span displayed with the "did you mean" note
was easy to interpret as a suggested edit (as if it had been set by
span_suggestion
), but was in fact identical to the snippet/spandisplayed just above, indicating the error in the original code, making
it look as if the compiler was suggesting a no-op change.
To remedy this, we use
help
instead ofspan_note
, and reword one ofthe affected messages to emphasize the concept of accessing a field
being different from calling a method (when the message just said, "did
you mean to write
self.foo
", it was not immediately obvious that thiswas meant in contrast to
self.foo()
, with method-call parens).Resolves #38321.
Addendum (1 Feb): screenshot by reviewer request—