Skip to content

Match is not smart enough to deduce the only possible catch-all type #51479

Closed
@Disasm

Description

@Disasm

This example compiles successfully:

fn f2() -> Result<i32, String> {
    unimplemented!()
}

fn f1() -> Result<i64, String> {
    match f2() {
        Ok(value) => Ok(value as i64),
        Err(err) => Err(err),
    }
}

However, this example does not:

fn f2() -> Result<i32, String> {
    unimplemented!()
}

fn f1() -> Result<i64, String> {
    match f2() {
        Ok(value) => Ok(value as i64),
        err => err,
    }
}

Obviously, err can only be of Err(e) kind so it's correct to return it from f1().

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions