# A space after colons in macros

**URL:** <https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348>\
**Category:** style\
**Created:** [August 7, 2014, 4:02pm UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348 "2014-08-07T16:02:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanxiyn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/sanxiyn/32/8824_2.png) [@sanxiyn](https://internals.rust-lang.org/u/sanxiyn)\
**Post date:** [August 7, 2014, 4:02pm UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348/1 "2014-08-07T16:02:08Z")

</div>

I note that while style guide says “Use a space after colons”, almost no existing codes does so in macros. For example,

```
macro_rules! try(
    ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
)

```

That is, `$e:expr`, not `$e: expr`.

What do you prefer?

---

<div class="post-metadata">

**Author:** ![DiamondLovesYou](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/diamondlovesyou/32/3947_2.png) [@DiamondLovesYou](https://internals.rust-lang.org/u/DiamondLovesYou)\
**Post date:** [August 8, 2014, 6:37am UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348/2 "2014-08-08T06:37:34Z")

</div>

Former. No reason, other than everyone else follows that style too.

---

<div class="post-metadata">

**Author:** ![huon](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/huon/32/3698_2.png) [@huon](https://internals.rust-lang.org/u/huon)\
**Post date:** [August 8, 2014, 8:20am UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348/3 "2014-08-08T08:20:54Z")

</div>

I [try](https://github.com/huonw/cfor/blob/84cf472d8ffc5a256dee52e2de93a8955340026e/src/lib.rs#L191) to [use](https://github.com/huonw/icfp-2014/blob/bd246b6989f09bac559e98ef81ec3f39b13c0334/src/ghost.rs#L10) `$e: expr` because the `expr` is essentially a type for the `$e` variable.

---

<div class="post-metadata">

**Author:** ![lilyball](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lilyball/32/9086_2.png) [@lilyball](https://internals.rust-lang.org/u/lilyball)\
**Post date:** [August 8, 2014, 9:28pm UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348/4 "2014-08-08T21:28:44Z")

</div>

I prefer `$e:expr`, it makes it clear that `expr` is part of the nonterminal pattern token.

---

<div class="post-metadata">

**Author:** ![Florob](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@Florob](https://internals.rust-lang.org/u/Florob)\
**Post date:** [August 9, 2014, 3:33am UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348/5 "2014-08-09T03:33:23Z")

</div>

I personally prefer `$e: expr`, it seems more consistent to me. I actually tend to be confused/surprised for a second, whenever I come across the space-less variant.

---

<div class="post-metadata">

**Author:** ![iopq](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/iopq/32/78_2.png) [@iopq](https://internals.rust-lang.org/u/iopq)\
**Post date:** [August 9, 2014, 3:25pm UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348/6 "2014-08-09T15:25:30Z")

</div>

Oh, everything makes sense now. I couldn’t even parse the syntax for macro\_rules! because it just looked like magic macro things.

---

<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:22am UTC](https://internals.rust-lang.org/t/a-space-after-colons-in-macros/348/7 "2019-03-25T08:22:45Z")

</div>

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

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