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

Provide context for missing comma in match arm and if statement without block #48338

Merged
merged 5 commits into from
Mar 3, 2018

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Feb 18, 2018

When finding:

match &Some(3) {
    &None => 1
    &Some(2) => { 3 }
    _ => 2
}

provide the following diagnostic:

error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>`
 --> $DIR/missing-comma-in-match.rs:15:18
  |
X |         &None => 1
  |               --  - help: missing comma
  |               |
  |               while parsing the match arm starting here
X |         &Some(2) => { 3 }
  |                  ^^ expected one of `,`, `.`, `?`, `}`, or an operator here

When unnecessarily using a fat arrow after an if condition, suggest the
removal of it.

error: expected `{`, found `=>`
  --> $DIR/missing-block-hint.rs:13:18
   |
13 |         if (foo) => {} //~ ERROR expected `{`, found `=>`
   |                  ^^ help: only necessary in match arms, not before if blocks

When finding an if statement with no block, point at the if keyword to
provide more context:


error: expected `{`, found `}`
  --> file.rs:6:1
   |
13 |     if 5 == {
   |     -- this `if` statement has a condition, but no block
...
17 | }
   | ^

Fix #29586, fix #30035.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2018
@estebank estebank force-pushed the match-missing-comma branch 3 times, most recently from 8d880f5 to aabfe31 Compare February 19, 2018 06:31
@estebank estebank changed the title Provide missing comma in match arm suggestion Provide context for missing comma in match arm and if statement without block Feb 19, 2018
@estebank
Copy link
Contributor Author

r? @nikomatsakis

@petrochenkov petrochenkov self-assigned this Feb 19, 2018
if let Some(sp) = fat_arrow_sp {
// if cond => expr
err.span_suggestion(sp,
"only necessary in match arms, not before if blocks",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I found this confusingly phrased. Maybe this?

"only necessary with `match`, not `if`"

I'm also aiming to avoid jargon like "arms" and "blocks", which users may not be familiar with.


let expr = self.parse_expr_res(Restrictions::STMT_EXPR, None)
.map_err(|mut err| {
err.span_label(arrow_span, "while parsing the match arm starting here");
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say:

 "while parsing the `match` arm starting here"

13 | &None => 1
| -- - help: missing a comma here to end this match arm
| |
| while parsing the match arm starting here
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is "heavy", but I'm not sure how to suggest an improvement yet. I wonder if just the suggestion would be enough?

error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>`
  --> $DIR/missing-comma-in-match.rs:14:18
   |
13 |         &None => 1
   |                   - help: maybe missing a comma here: `1,`
14 |         &Some(2) => { 3 }
   |                  ^^ expected one of `,`, `.`, `?`, `}`, or an operator here

error: aborting due to previous error

Would that be hard to add?

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 shouldn't.

};
let thn = self.parse_block().map_err(|mut err| {
if let Some(sp) = fat_arrow_sp {
// if cond => expr
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an issue about this or any other confirmation that this mistake is realistic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was an existing test case, but it is indeed a big corner case. I can remove the special diagnostic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think just removing this would be for the better.

@petrochenkov
Copy link
Contributor

LGTM except for maybe removing special diagnostics for https://github.com/rust-lang/rust/pull/48338/files#r169751541

@petrochenkov petrochenkov 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 Feb 21, 2018
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 25, 2018

📌 Commit 3e730aa has been approved by petrochenkov

@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 Feb 25, 2018
@bors
Copy link
Contributor

bors commented Feb 27, 2018

☔ The latest upstream changes (presumably #48449) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 27, 2018
When finding:

```rust
match &Some(3) {
    &None => 1
    &Some(2) => { 3 }
    _ => 2
}
```

provide the following diagnostic:

```
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>`
 --> $DIR/missing-comma-in-match.rs:15:18
  |
X |         &None => 1
  |               --  - help: missing comma
  |               |
  |               while parsing the match arm starting here
X |         &Some(2) => { 3 }
  |                  ^^ expected one of `,`, `.`, `?`, `}`, or an operator here
```
When unnecessarily using a fat arrow after an if condition, suggest the
removal of it.

When finding an if statement with no block, point at the `if` keyword to
provide more context.
@nikomatsakis
Copy link
Contributor

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Feb 27, 2018

📌 Commit d63d363 has been approved by petrochenkov

@bors
Copy link
Contributor

bors commented Mar 1, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 1, 2018
@kennytm
Copy link
Member

kennytm commented Mar 1, 2018

@bors retry #46903 (check i686-pc-windows-msvc)

34 minutes spent on building stage1-rustc.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 1, 2018
@bors
Copy link
Contributor

bors commented Mar 2, 2018

⌛ Testing commit 24be75d with merge b78bf234740ed8f040c8546e21d509fc137cb468...

@Manishearth Manishearth closed this Mar 2, 2018
@Manishearth Manishearth reopened this Mar 2, 2018
@Manishearth
Copy link
Member

@bors retry

(rollup priority)

@bors
Copy link
Contributor

bors commented Mar 2, 2018

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 2, 2018
@petrochenkov
Copy link
Contributor

Looks like this hasn't landed as a part of rollup.

@petrochenkov petrochenkov reopened this Mar 2, 2018
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 2, 2018

💡 This pull request was already approved, no need to approve it again.

  • This pull request previously failed. You should add more commits to fix the bug, or use retry to trigger a build again.
  • There's another pull request that is currently being tested, blocking this pull request: rust: Import LLD for linking wasm objects #48125

@bors
Copy link
Contributor

bors commented Mar 2, 2018

📌 Commit 24be75d has been approved by petrochenkov

@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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 2, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 2, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 3, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 3, 2018
@bors bors merged commit 24be75d into rust-lang:master Mar 3, 2018
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
8 participants