Skip to content

Possible improvement in lack-of-semicolon error messages #36413

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

Closed
alexcrichton opened this issue Sep 12, 2016 · 2 comments
Closed

Possible improvement in lack-of-semicolon error messages #36413

alexcrichton opened this issue Sep 12, 2016 · 2 comments
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

@alexcrichton
Copy link
Member

Talking to some folks at RustConf recently a common point of confusion seemed to be "where are semicolons required?" The compiler seemingly has arcane restrictions at the beginning and this means that we can perhaps improve errors in this respect to help guide beginners!

For example, in this code:

pub fn foo() {
    if true {
        3
    } else {
        foo();
    }
}

it yields the error:

error[E0308]: mismatched types
 --> foo.rs:3:9
  |
3 |         3
  |         ^ expected (), found integral variable
  |
  = note: expected type `()`
  = note:    found type `{integer}`

error: aborting due to previous error

Perhaps we could detect that the other branch of the if has a semicolon, and as a result a semicolon here is probably also the fix?

@alexcrichton alexcrichton added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 12, 2016
@estebank
Copy link
Contributor

I believe PR #36409 would handle this case.

@steveklabnik steveklabnik added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

Closing as a duplicate of #41897.

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

4 participants