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

Parse alternative incorrect uses of await and recover #60873

Merged
merged 10 commits into from
May 17, 2019

Conversation

estebank
Copy link
Contributor

Fix #60613.

r? @Centril

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 16, 2019
@estebank
Copy link
Contributor Author

I'll split the code in smaller functions soon, but wanted to get this PR out the door.

I decided against also supporting .await! and .await!() because those two won't be used by anyone that isn't also aware about what the correct syntax is.

@estebank estebank changed the title [WIP] Parse alternative incorrect uses of await and recover Parse alternative incorrect uses of await and recover May 16, 2019
@rust-highfive

This comment has been minimized.

Copy link
Contributor

@Centril Centril left a 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
Copy link
Contributor

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)

Copy link
Contributor Author

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 Show resolved Hide resolved
src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
err
})?;
let expr_str = self.sess.source_map().span_to_snippet(expr.span)
.unwrap_or_else(|_| pprust::expr_to_string(&expr));
Copy link
Contributor

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

src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
src/librustc/hir/lowering.rs Outdated Show resolved Hide resolved
@Mark-Simulacrum Mark-Simulacrum 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 May 16, 2019
@bors

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");
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@Centril
Copy link
Contributor

Centril commented May 16, 2019

Code looks great now; thanks for doing this!

r=me with green travis :)

@estebank
Copy link
Contributor Author

@Centril take one last look at the last commit that moves some recovery methods out of Parser to diagnostics as a drive-by clean-up.

Copy link
Contributor

@Centril Centril left a 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... ;)

src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/diagnostics.rs Show resolved Hide resolved
src/libsyntax/parse/diagnostics.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Centril Centril left a 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. :)

@estebank
Copy link
Contributor Author

@bors r=Centril

@bors
Copy link
Contributor

bors commented May 16, 2019

📌 Commit c084d0e has been approved by Centril

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 16, 2019
Centril added a commit to Centril/rust that referenced this pull request May 17, 2019
Parse alternative incorrect uses of await and recover

Fix rust-lang#60613.

r? @Centril
bors added a commit that referenced this pull request May 17, 2019
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
@bors bors merged commit c084d0e into rust-lang:master May 17, 2019
@bors
Copy link
Contributor

bors commented May 17, 2019

⌛ Testing commit c084d0e with merge 1bbb135...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide appropriate suggestions for some of the discussed await syntaxes
7 participants