Skip to content

Incorrect "match arms have incompatible types" error message #24157

Closed
@offlinemark

Description

@offlinemark

I have code that matches on a Result<usize>, with cases for Ok(usize_var) and Err(why). I get a "match arms have incompatible types" error upon compilation which I believe is incorrect.

I'm not incredibly experienced with this, but discussion in irc (https://botbot.me/mozilla/rust/2015-04-06/?msg=35985521&page=37) supports that this may be a bug.

I tried this code (available at http://is.gd/Y00aRi):

fn main() {
    let mut input: String = String::new();
    match std::io::stdin().read_line(&mut input) {
        Ok(bytes_read) => bytes_read,
        Err(why) => panic!("{}", why)
    }
    println!("{}", input);
}

I expected it to compile, however there is a "match arms have incompatible types" error even though I believe the match arms should both be of type usize.

I should note that adding a semicolon after the match causes clean compilation.

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.D-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-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