# Alternative syntax for working with enums

**URL:** <https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717>\
**Category:** language design\
**Created:** [January 28, 2020, 7:49pm UTC](https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717 "2020-01-28T19:49:16Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![gbutler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/gbutler/32/3670_2.png) [@gbutler](https://internals.rust-lang.org/u/gbutler)\
**Post date:** [February 21, 2020, 2:54am UTC](https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717/21 "2020-02-21T02:54:44Z")

</div>

I'd be cautious of doing this. It starts to sound a lot like:

```javascript
// legacy javascript
with foo {
   bar = "Hello";
}

```

which was found to be a huge foot-gun.

NOTE: similar "with ..." scoping has been present in many languages, and as far as I can recall, it was always found to be a foot-gun and everyone regretted having it in the language and it was eventually "deprecated".

If we did something like this for Rust, we'd have to be 100% sure it wasn't going to create problems, now or in the future, ever (which is not a bar that I think you could ever vault).

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [February 21, 2020, 12:17pm UTC](https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717/22 "2020-02-21T12:17:49Z")

</div>

`with` is only a footgun in JS because of JS-specific reasons: lack of static typing, which makes it JIT-unfriendly and can create global variables by accident. You can't create a global variable by accident in Rust, so this wouldn't apply.

---

<div class="post-metadata">

**Author:** ![Ixrec](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ixrec/32/6754_2.png) [@Ixrec](https://internals.rust-lang.org/u/Ixrec)\
**Post date:** [February 21, 2020, 12:33pm UTC](https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717/23 "2020-02-21T12:33:41Z")

</div>

More generally, the problem with `with` is that it introduced **dynamic scoping**. i.e. the meaning of a name/identifier has to depend on what runtime values get passed into a block of code. That is indeed a giant mess no one wants in their languages any more.

But AFAICT nobody has suggested any enum syntax that would bring in truly dynamic scoping.

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)\
**Post date:** [April 20, 2020, 5:06pm UTC](https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717/24 "2020-04-20T17:06:12Z")

</div>

I don't see patterns mentioned in this thread, but I think the syntax would be very useful for matching enum variations, like `Enum::{A | B | C}`. I posted that as a separate idea over [here](https://internals.rust-lang.org/t/idea-braced-or-patterns-enum-a-b-c/12208/).

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [July 19, 2020, 5:11pm UTC](https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717/25 "2020-07-19T17:11:54Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/alternative-syntax-for-working-with-enums/11717.md?page=1)
