Skip to content

missing type in match arms have incompatible types diagnostic #58695

Closed
@bjorn3

Description

@bjorn3
fn main() {
    match Some(0u32) {
        Some(x) => {
            x
        },
        None => {}
    };
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0308]: match arms have incompatible types
 --> src/main.rs:6:17
  |
2 | /     match Some(0u32) {
3 | |         Some(x) => {
4 | |             x
  | |             - this is found to be of type `_` <----------- this should be `u32`, removing the {} around x fixes it.
5 | |         },
6 | |         None => {}
  | |                 ^^ expected u32, found ()
7 | |     };
  | |_____- `match` arms have incompatible types
  |
  = note: expected type `u32`
             found type `()`

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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