Skip to content

Confusing error message when missing an else in an if expression #4201

Closed
@ghost

Description

fn main() {
    let a = if true {
        0 
    } else if false {
        1
    };
}
./example.rs:4:20: 6:5 error: mismatched types: expected `()` but found `<VI1>` (expected () but found integral variable)
./example.rs:4     } else if false {
./example.rs:5         1
./example.rs:6     };
./example.rs:4:11: 6:5 error: mismatched types: expected `<VI0>` but found `()` (expected integral  variable but found ())
./example.rs:4     } else if false {
./example.rs:5         1
./example.rs:6     };
error: aborting due to 2 previous errors

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions