Skip to content

typeck: diverging binding in pattern does not generate unreachable_code #68429

Open
@Centril

Description

@Centril

The following should probably result in the lint being emitted:

#![feature(never_type)]

pub fn foo(maybe_never: Option<!>) {
    match maybe_never {
        Some(_never) => {
            println!("foo");
        }
        None => {}
    }
}

as _never is matched on, and it has a diverging type.

Compare this with:

#![feature(never_type)]

pub fn foo(maybe_never: Option<!>) {
    match maybe_never {
        Some(never) => {
            let _ = never;
            println!("foo");
        }
        None => {}
    }
}

Currently, the pattern type checking code does not care about diverges.

We should probably avoid fixing this in typeck and have this be fixed automatically (?) by moving diverges logic to MIR or some such.

cc @eddyb #68422 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.C-enhancementCategory: An issue proposing an enhancement or a PR with one.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