# Idea: elide parens/brackets on unparametrized macros

**URL:** <https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527>\
**Category:** language design\
**Created:** [January 10, 2018, 7:33pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527 "2018-01-10T19:33:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark-i-m](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mark-i-m/32/3167_2.png) [@mark-i-m](https://internals.rust-lang.org/u/mark-i-m)\
**Post date:** [January 10, 2018, 7:33pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/1 "2018-01-10T19:33:40Z")

</div>

Could we syntactically eliminate the `()`/`{}`/`[]` after “calling” an unparameterized macro? In other words:

```rust
macro_rules! foo {
  () => { ... }
}

```

could be invoked with `foo!` rather than `foo!()`. The motivation is primarily to avoid a paper cut.

I can imagine a few use cases that would become more ergonomic:

```rust
let my_vec = vec!; // vec![]`
println!; // println!()
ok! // Maybe shorthand for Ok(()) -- just an idea ?

```

I don’t see any obvious syntactic ambiguities that arise, and the change is purely syntactic, so the only part of the compiler that changes is the parser, I think.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![bluss](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bluss/32/2264_2.png) [@bluss](https://internals.rust-lang.org/u/bluss)\
**Post date:** [January 10, 2018, 8:06pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/2 "2018-01-10T20:06:44Z")

</div>

macros without parameters rarely have very interesting effect, do they? It is unavoidably a knee-jerk reaction here, but I don’t think `vec!` is better than `vec![]` — then it even loses those brackets it has borrowed from the array or slice, to remind you of them.

---

<div class="post-metadata">

**Author:** ![leonardo](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/leonardo/32/1344_2.png) [@leonardo](https://internals.rust-lang.org/u/leonardo)\
**Post date:** [January 10, 2018, 8:10pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/3 "2018-01-10T20:10:49Z")

</div>

What I don’t like a lot is both versions being accepted:

```
fn main() {
    let v1: Vec<u8> = vec![];
    let v2: Vec<u8> = vec!();
}

```

Often in programming languages I prefer the Python Zen “There should be one-- and preferably only one --obvious way to do it.”.

---

<div class="post-metadata">

**Author:** ![mbrubeck](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mbrubeck/32/174_2.png) [@mbrubeck](https://internals.rust-lang.org/u/mbrubeck)\
**Post date:** [January 10, 2018, 9:02pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/4 "2018-01-10T21:02:26Z")

</div>

`unreachable!` seems like a good use case for this. Similarly, `unimplemented!`

---

<div class="post-metadata">

**Author:** ![petrochenkov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/petrochenkov/32/2784_2.png) [@petrochenkov](https://internals.rust-lang.org/u/petrochenkov)\
**Post date:** [January 10, 2018, 9:11pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/5 "2018-01-10T21:11:45Z")

</div>

This looks kinda tempting.

If macros with `()`/etc are “functions” and take arguments, then macros without `()` are “constants”.  
It would be nice to use them for macros that actually unwrap into constants, kinda like

```rust
/* "Constant" macro */
#define CONST 10
/* "Function" macro */
#define FN(a, b, c) ((a) + (b) + (c))

```

in C.

I don’t think there are syntactic ambiguities or any similar technical problems, but I still have mixed feelings about the syntax, not sure why.

---

<div class="post-metadata">

**Author:** ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)\
**Post date:** [January 10, 2018, 9:59pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/6 "2018-01-10T21:59:15Z")

</div>

I feel better about this for `panic!` variants than for `vec!`, but this seems like a very fuzzy feeling for which I don’t have a good justification.

---

<div class="post-metadata">

**Author:** ![mark-i-m](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mark-i-m/32/3167_2.png) [@mark-i-m](https://internals.rust-lang.org/u/mark-i-m)\
**Post date:** [January 10, 2018, 11:10pm UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/7 "2018-01-10T23:10:49Z")

</div>

> [@petrochenkov](#):
>
> but I still have mixed feelings about the syntax, not sure why.

> [@withoutboats](#):
>
> but this seems like a very fuzzy feeling for which I don’t have a good justification.

TBH, I had the same hesitation. On introspection, here what I think I am feeling: Macros are great if you have some little piece of code that works the same way but with a few values changed. I don't think that macros should be used if other language constructs could be instead. Using a macro to insert _the same constant AST_ in multiple places feels in some way like a violation of that intuition.

I would argue that this isn't a problem with this particular syntax though. Rather it's a choice of whether to use a macro at all for something.

---

<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:** [March 25, 2019, 8:29am UTC](https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527/8 "2019-03-25T08:29:30Z")

</div>

Closed on March 25, 2019, 8:29am UTC

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