[rust-dev] Patterns that'll never match

Gábor Lehel glaebhoerl at gmail.com
Sun Jun 1 03:48:52 PDT 2014


Well, not possible in the general case, to be more precise. It would be
possible in theory to teach the compiler about e.g. the comparison
operators on built-in integral types, which don't involve any user code. It
would only be appropriate as a warning rather than an error due to the
inherent incompleteness of the analysis and the arbitrariness of what
things to include in it. No opinion about whether it would be worth doing.

On Sun, Jun 1, 2014 at 10:40 AM, Corey Richardson <corey at octayn.net> wrote:

> We already *do* do this, but not for guards because that's not possible.
>
> On Sun, Jun 1, 2014 at 12:02 AM, Tommi <rusty.gates at icloud.com> wrote:
> > Would it be possible to get a compile-time error for a `match` branch
> that can never be reached due to a previous branch encompassing it. For
> example, for the middle branch here:
> >
> > let n = 0;
> > match n {
> >     x if x < 2 => (),
> >     x if x < 1 => (),
> >     _ => ()
> > }
> >
> > If this is a too complicated a problem in the general case, then perhaps
> there could be warnings for some (implementation defined) simple cases.
> >
> > _______________________________________________
> > Rust-dev mailing list
> > Rust-dev at mozilla.org
> > https://mail.mozilla.org/listinfo/rust-dev
>
>
>
> --
> http://octayn.net/
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>



On Sun, Jun 1, 2014 at 10:40 AM, Corey Richardson <corey at octayn.net> wrote:

> We already *do* do this, but not for guards because that's not possible.
>
> On Sun, Jun 1, 2014 at 12:02 AM, Tommi <rusty.gates at icloud.com> wrote:
> > Would it be possible to get a compile-time error for a `match` branch
> that can never be reached due to a previous branch encompassing it. For
> example, for the middle branch here:
> >
> > let n = 0;
> > match n {
> >     x if x < 2 => (),
> >     x if x < 1 => (),
> >     _ => ()
> > }
> >
> > If this is a too complicated a problem in the general case, then perhaps
> there could be warnings for some (implementation defined) simple cases.
> >
> > _______________________________________________
> > Rust-dev mailing list
> > Rust-dev at mozilla.org
> > https://mail.mozilla.org/listinfo/rust-dev
>
>
>
> --
> http://octayn.net/
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140601/ad9153f9/attachment.html>


More information about the Rust-dev mailing list