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 better diagnostic for forgotten semicolon token #32540

Closed
bungcip opened this issue Mar 27, 2016 · 1 comment
Closed

provide better diagnostic for forgotten semicolon token #32540

bungcip opened this issue Mar 27, 2016 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bungcip
Copy link
Contributor

bungcip commented Mar 27, 2016

this code

fn main(){
    let value = 20;
    let m = match value {
        20 => true,
        40 => false,
        _ => false
    }

    println!("{}", m);
}

give this error message:

C:\depot>rustc ex.rs
ex.rs:9:5: 9:12 error: expected one of `.`, `;`, `?`, or an operator, found `println`
ex.rs:9     println!("{}", m);
            ^~~~~~~
error: aborting due to previous error

ideally, the error is something like this:

C:\depot>rustc ex.rs
ex.rs:7:5: 7:12 error: expected one of `.`, `;`, `?`, or an operator after '}' token
ex.rs:7     }
            ^~
error: aborting due to previous error
@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 28, 2016
@jonas-schievink
Copy link
Contributor

I'm curious as to why this isn't accepted. Removing the let m = makes it parse. Since match, similarly to if, is one of the expressions that can be used as a statement without being followed by a semicolon, it shouldn't cause many issues if this would be accepted, too (after a corresponding RFC, of course).

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
bors added a commit that referenced this issue Apr 5, 2017
Point at last valid token on failed `expect_one_of`

```rust
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
  --> $DIR/token-error-correct-3.rs:29:9
   |
25 |         foo()
   |              - expected one of `.`, `;`, `?`, `}`, or an operator after this
...
29 |     } else {
   |     ^ unexpected token
```

Fix #32540.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants