Skip to content

Unexpected "expected function" error with unit type #106515

Closed
@Ezrashaw

Description

@Ezrashaw

I tried this code:

fn main() {
    let x = 5

    ()
}

I expected to see this happen:

error: expected `;`, found `}`
 --> src/main.rs:2:14
  |
2 |     let x = 5
  |              ^ help: add `;` here
3 | }
  | - unexpected token

One error occurs from the missing semicolon.

Instead, this happened:

error: expected `;`, found `}`
 --> src/main.rs:4:7
  |
4 |     ()
  |       ^ help: add `;` here
5 | }
  | - unexpected token

error[E0618]: expected function, found `{integer}`
 --> src/main.rs:2:13
  |
2 |       let x = 5
  |  _____________^
3 | |
4 | |     ()
  | |______- call expression requires function

An additional unexpected error occurs when when I obviously do not want to invoke a closure. Also note that the semicolon error is after the supposed closure invocation, when I would expect it to be after the let x = 5.

Meta

Occurs on latest stable and nightly.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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