Skip to content

Incorrect bracket is pointed to for return type in closure #50085

Closed
@varkor

Description

@varkor
fn main() {
    let _ = || {
        if true {
            true
        } else {
            false
        } // Whoops, forgot a semicolon!
        false
    };
}

Gives the error:

error[E0308]: mismatched types
 --> src/main.rs:4:13
  |
1 | fn main() {
  |           - expected `()` because of default return type
...
4 |             true
  |             ^^^^ expected (), found bool
  |
  = note: expected type `()`
             found type `bool`

The return type of main is referenced, which is wrong — but really the problem is that there are two consecutive expressions that are not separated by a semicolon. It would be good to have an improvement in either respect, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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