Skip to content

match + match compilation error #105179

Closed
@stormshield-pj50

Description

@stormshield-pj50

I tried this code:

fn foo(a: u64, b: u64) -> u64 {
    match a {
        0 => 1,
        value => value
    } + match b {
        1 => 0,
        value => value
    }
}

fn main() {
    println!("{}", foo(0, 1));
}

I expected to see this happen: the program compiles

Instead, this happened: the program doesn't compile. Note that if you use a return the program compiles and in that case clippy suggests to remove the return.

error: expected expression, found `+`
 --> src/main.rs:5:7
  |
5 |     } + match b {
  |       ^ expected expression

error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
 --> src/main.rs:2:5
  |
2 | /     match a {
3 | |         0 => 1,
4 | |         value => value
5 | |     } + match b {
  | |     ^- help: consider using a semicolon here
  | |_____|
  |       expected `()`, found `u64`

Meta

rustc --version --verbose:

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.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