Skip to content

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

Closed
@alexcrichton

Description

@alexcrichton

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions