No warning on overlapping match patterns

Just noticed by chance that this:

    match 10i64 {
        i64::MIN..=1000 => (),
        1000..=i64::MAX => (),
    }

correctly warns that the ranges overlap on 1000. However, this:

    match 10i64 {
        i64::MIN..=1001 => (),
        1000..=i64::MAX => (),
    }

does not, even though 1000, 1001 are in both ranges.

Is this an expected behavior? A known issue? I'm assuming the first pattern to match is what gets executed, though I think the compiler should warn me anyway.

I suspect that was put in as a special-case warning. In general overlapping patterns are allowed, and the first arm to match is used. This lets you put the catch-all pattern _ at the bottom of a match statement to serve as an else clause, and any variant of that you can think of.

It would make sense to warn on overlap-with-off-by-one-error too.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.