Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

nonsense help message for stray => #35907

Closed
durka opened this issue Aug 22, 2016 · 1 comment · Fixed by #35953
Closed

nonsense help message for stray => #35907

durka opened this issue Aug 22, 2016 · 1 comment · Fixed by #35953
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST

Comments

@durka
Copy link
Contributor

durka commented Aug 22, 2016

Code:

if true => { }

Output:

error: expected `{`, found `=>`
 --> expr.rs:5:10
  |
5 | if true => { }
  |         ^^
  |
  = help: place this code inside a block

"Place this code inside a block" doesn't make any sense here.

@Aatch
Copy link
Contributor

Aatch commented Aug 23, 2016

It's there to catch this:

if (foo)
   bar;

But the way it's implemented means that if we get something that isn't a block, we say to put it in a block. We might be able try parsing an expression, and show the help only if that works.

@Aatch Aatch added A-parser Area: The parsing of Rust source code to an AST A-diagnostics Area: Messages for errors, warnings, and lints labels Aug 23, 2016
@Aatch Aatch self-assigned this Aug 23, 2016
bors pushed a commit that referenced this issue Aug 26, 2016
We want to catch this error:

```
if (foo)
    bar;
```

as it's valid syntax in other languages, and say how to fix it.
Unfortunately it didn't care if the suggestion made sense and just
highlighted the unexpected token.

Now it attempts to parse a statement, and if it succeeds, it shows the
help message.

Fixes #35907
Manishearth added a commit to Manishearth/rust that referenced this issue Aug 27, 2016
…=nrc

Improve error message when failing to parse a block

We want to catch this error:

```
if (foo)
    bar;
```

as it's valid syntax in other languages, and say how to fix it.
Unfortunately it didn't care if the suggestion made sense and just
highlighted the unexpected token.

Now it attempts to parse a statement, and if it succeeds, it shows the
help message.

Fixes rust-lang#35907
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants