[rust-dev] Alt exhaustiveness checking

Tim Chevalier catamorphism at gmail.com
Tue Jul 26 12:05:51 PDT 2011

On Tue, Jul 26, 2011 at 1:32 AM, Marijn Haverbeke <marijnh at gmail.com> wrote:
> I'd like to implement this soon. Should non-exhaustive alts be errors
> or warnings? I guess, if we are to have warnings at all, these are
> fine as warnings.

IMHO, a non-exhaustive alt is always an error. If some cases are
"impossible", a static requirement for the programmer to declare their
intentions explicitly by inserting a fail (hopefully with an
informative error message) can save a lot of time later.

> To be able to control these warnings, I'd like to add support for
> forms like these:
> // I know this is non-exhaustive, fail on non-match
> alt fail (foo) {
>   1 {...}
>   2 {...}
> }
> // I know this is non-exhaustive, fall-through without failing on non-match
> alt cont (foo) {
>   1 {...}
>   2 {...}
> }
> I think this is more elegant and explicit than requiring people to say
> '_ {}' or '_ {fail;}' again and again.

This seems pretty reasonable; if you add support for this, I think my
first comment holds even more so :-)


Tim Chevalier * http://cs.pdx.edu/~tjc/ * Often in error, never in doubt
“I cannot hide my anger to spare you guilt, nor hurt feelings, nor
answering anger; for to do so insults and trivializes all our efforts.
Guilt is not a response to anger; it is a response to one’s own
actions or lack of action.” -- Audre Lorde

More information about the Rust-dev mailing list