A space after colons in macros


#1

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?


#2

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


#3

I try to use $e: expr because the expr is essentially a type for the $e variable.


#4

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


#5

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.


#6

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