Skip to content

Invalid non-exhaustive pattern error on scalar values #16199

Closed
@lifthrasiir

Description

@lifthrasiir
fn foo(c: char) {
    match c {
        '\u0000'..'\ud7ff' | '\ue000'..'\uffff' => println!("BMP"),
        '\U00010000'..'\U0010ffff' => println!("non-BMP"),
    }
}

...results in:

<anon>:2:5: 5:6 error: non-exhaustive patterns: `_` not covered [E0004]
<anon>:2     match c {
<anon>:3         '\u0000'..'\ud7ff' | '\ue000'..'\uffff' => println!("BMP"),
<anon>:4         '\U00010000'..'\U0010ffff' => println!("non-BMP"),
<anon>:5     }

These patterns clearly encompass the entire domain of char but the exhaustiveness checker doesn't know that. In fact, this occurs for every scalar value:

fn foo(v: u8) {
    match v {
        -128 .. 7 => println!("<= 7"),
        8 .. 127 => println!("> 7"),
    }
}

...but char is the prominent example of this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions