Skip to content

Improve error message of match arms have incompatible types #11319

Closed
@klutzy

Description

@klutzy

Currently this code:

fn i() -> int { 1 }
fn u() -> uint { 1 }
fn uu() -> u8 { 1 }

fn main() {
    match 0 {
        1 => i(),
        2 => u(),
        3 => uu(),
        _ => {},
    }
}

causes:

y.rs:6:5: 11:6 error: match arms have incompatible types: expected `int` but found `uint` (expected int but found uint)
y.rs:6     match 0 {
y.rs:7         1 => i(),
y.rs:8         2 => u(),
y.rs:9         3 => uu(),
y.rs:10         _ => {},
y.rs:11     }

The error message just says there exists some type mismatch between some arms, but it doesn't say which arms actually are.
It would be better if rustc indicates that arm 1 and arm 2 have incompatible types.

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