Skip to content

expected (), found usize, while really this is the other way around #51767

Description

@DutchGhost

When playing around in the playground, I found an error message that was kind of strange for the situation:

fn main() {
    [(); loop { break; } ]    
}

The error message is as follow:

  Compiling playground v0.0.1 (file:///playground)
error[E0308]: mismatched types
 --> src/main.rs:2:17
  |
2 |     [(); loop { break; } ]    
  |                 ^^^^^ expected (), found usize
  |
  = note: expected type `()`
             found type `usize`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

playground link: https://play.rust-lang.org/?gist=c6caaee68d6886fce7e3f0af324f5338&version=nightly&mode=debug
The error message would make more sense if described as Expected usize, found (), or just not permit loop {} constructs at all at the place of the length of an array.

Activity

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 lints

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions