Skip to content

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

@alexcrichton

Description

@alexcrichton
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?

Activity

estebank

estebank commented on Sep 13, 2016

@estebank
Contributor

I believe PR #36409 would handle this case.

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
and removed
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 9, 2017
Mark-Simulacrum

Mark-Simulacrum commented on Jun 4, 2017

@Mark-Simulacrum
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

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

        Participants

        @steveklabnik@alexcrichton@estebank@Mark-Simulacrum

        Issue actions

          Possible improvement in lack-of-semicolon error messages · Issue #36413 · rust-lang/rust