This was prompted by the 'minor annoyances thread'. A big annoyance
for me is the recurring `_ {}` at the end of alt patterns that fall
through. A worse form is `_ { fail "this is a bug"; }` (alt already
fails when not matching, with a line number reference to the alt that
blew up, so this kind of `fail` statements mostly just muddle up the
code).

Instead, I propose:

    // This one falls through without failing
    alt myoption pass {
       some(x) { do_something_with(x); }
    }
    // This one explicitly says that is is non-exhaustive, and that
    // it will fail for bad input
    alt myoption fail {
       some(x) { ... }
    }

Normal alt would be required to be exhaustive, and give a compile-time
error if it isn't. This is more self-documenting (you're explicitly
annotating what you're trying to do when writing a non-exhaustive
alt), and somewhat more succinct.

I'm not terribly attached to those keywords (`pass` and `fail`), would
happily hear alternatives.

Best,
Marijn
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to