[rust-dev] exhaustiveness checking can fail due to confusion of identifier and variant

Niko Matsakis niko at alum.mit.edu
Tue Jul 24 18:55:00 PDT 2012


Patrick, how hard would it be to allow something like:

     import A::foo::*

to get all the variants of an enum into scope?



Niko


On 7/24/12 6:50 PM, Niko Matsakis wrote:
> I just uncovered a rather surprising  "failure" of exhaustiveness 
> checking.  There was an enum defined like so in a module A:
>
>     enum foo { a, b, c }
>
> and then, in another module B:
>
>     import A::{foo, a, b}; // Note: no c!
>
>     fn bar(f: foo) {
>         alt f {
>             a {"a"}
>             b {"b"}
>             c {"c"}
>         }
>     }
>
> Now this code worked fine, but there is a subtle bug: the value c here 
> is not acting as a variant but rather a catch-all.  So now when I 
> added a new variant `d`, the code still compiled fine but just acted 
> funny.
>
> I recall this sort of hazard was pointed out earlier (though in that 
> case the example was of removing a variant, which can lead to a 
> similar sort of catch-all).  Also, fixing bug #941 (warn about unused 
> bindings in patterns) would also have prevented this error. But still, 
> nasty!
>
>
> Niko
>
>
>
>



More information about the Rust-dev mailing list