-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Parse alternative incorrect uses of await and recover #60873
Conversation
I'll split the code in smaller functions soon, but wanted to get this PR out the door. I decided against also supporting |
This comment has been minimized.
This comment has been minimized.
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.
:)
LL | let finished = result.await; | ||
| ^^^^^^^^^^^^ | ||
| ^^^^^^^^^^^^ only allowed inside `async` functions and blocks |
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 wonder if it would be more understandable to highlight like so:
LL | let finished = result.await;
| ^^^^^^ only allowed inside `async` functions and blocks
(if this is something that can be done feasibly within the current diagnostics infra without too many hacks, if not, let's not do that)
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.
Will leave for a later time.
src/libsyntax/parse/parser.rs
Outdated
err | ||
})?; | ||
let expr_str = self.sess.source_map().span_to_snippet(expr.span) | ||
.unwrap_or_else(|_| pprust::expr_to_string(&expr)); |
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.
This bit is duplicated from above. I have a feeling this pattern occurs frequently so it would be good to consider a cleanup after this PR (but deduplicate here for now).
This comment has been minimized.
This comment has been minimized.
self.sess, | ||
await_span, | ||
E0728, | ||
"`await` is only allowed inside `async` functions and blocks" | ||
); | ||
self.sess.abort_if_errors(); | ||
err.span_label(await_span, "only allowed inside `async` functions and blocks"); |
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.
this seems redundant with the message above
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'm trying to remove all primary spans without labels from the cli output. The main msg should be generic and the label text more targeted and suitable to show inline in (for example) VSCode.
Would you be ok if the main message was "await
in a function or block not marked with async
" or similar?
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 don't think we should have two messages conveying the same information-- the wording isn't the problem.
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.
Some people ignore the error message entirely and focus exclusively on the spans. I agree that unnecessary text is suboptimal, but I do not
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-51751.rs:11:20
|
LL | let finished = result.await;
| ^^^^^^^^^^^^
vs
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-51751.rs:11:20
|
LL | let finished = result.await;
| ^^^^^^^^^^^^ only allowed inside `async` functions and blocks
vs
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-51751.rs:11:20
|
LL | fn main() {
| ---- this is not `async`
LL | let result = inc(10000);
LL | let finished = result.await;
| ^^^^^^^^^^^^ only allowed inside `async` functions and blocks
vs
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-51751.rs:11:20
|
LL | fn main() {
| ---- this is not `async`
LL | let result = inc(10000);
LL | let finished = result.await;
| ^^^^^^^^^^^^
The last case is what this would be like if we remove the label, which has some text in the secondary label, but no text on the primary label, which I feel is suboptimal.
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.
@estebank Hmm, ok -- leave it as is then; in context I think your solution is the best UX.
- Change wording of suggestion - Move recovery logic to `diagnostics.rs` - Reduce ammount of code duplication
Code looks great now; thanks for doing this! r=me with green travis :) |
@Centril take one last look at the last commit that moves some recovery methods out of |
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.
Drive by review to your drive by cleanups... ;)
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.
Thanks! r=me with green travis. :)
@bors r=Centril |
📌 Commit c084d0e has been approved by |
Parse alternative incorrect uses of await and recover Fix rust-lang#60613. r? @Centril
Rollup of 6 pull requests Successful merges: - #60685 (Switch to SPDX 2.1 license expression) - #60687 (Fix .natvis visualizers.) - #60805 (remove compiletest's dependency on `filetime`) - #60862 (Get ty from local_decls instead of using Place) - #60873 (Parse alternative incorrect uses of await and recover) - #60894 (Add entry-like methods to HashSet) Failed merges: r? @ghost
Fix #60613.
r? @Centril