[rust-dev] Heads up: syntax change with nullary tags in patterns

Patrick Walton pwalton at mozilla.com
Wed Jan 25 12:46:57 PST 2012

On 1/25/12 12:39 PM, Florian Weimer wrote:
> * Tim Chevalier:
>> To make this change possible, the typechecker now forbids local
>> variable names that shadow the name of a tag that's in scope.
> The "." was ugly, but doesn't this make the syntatic category of the
> token dependent on the contents of imported modules?  I think this is
> problematic for IDEs which want to go a bit beyond lexical syntax
> highlighting.

Depends on how you define syntactic categories. It just means that 
resolve has to disambiguate a bit.

> This change also breaks exhaustiveness checks to some degree.  Here's
> an example:
> enum enum_type {
>      a, b, c
> }
> fn repr(e: enum_type) ->  str {
>      alt e {
>        a { "a" }
>        b { "b" }
>        c { "c" }
>      }
> }
> We can remove the c variant from the enum_type definition, and the
> program still compiles (even though this smells like a bug).  It keeps
> compiling if we add a d variant to enum_type.  Flagging unused bound
> variables as error isn't a reliable countermeasure because the
> variant-now-variable might actually be used.

I see, this is a potential issue. Seems like a pretty rare case though, 
because you'd actually have to use the same tag variant inside the body.

Again, I'd point to Standard ML here... SML has the same rule and I've 
never seen it result in this bug.


More information about the Rust-dev mailing list