Description
I've created a discussion topic on Reddit, but for some reason it disappeared from the Rust page, so I'm filling an issue here. If there's a better place to discuss similar suggestions, please tell me.
I was just playing with Rust on http://rustbyexample.com/, and I've accidentally discovered that writeln can be called without a semicolon.
It doesn't look like a big deal, but for a perfectionist like me, I see it as a consistency flaw, especially for (probably) the most common macro in the language.
The author of Rust by example explained what's going on here, but that doesn't look right to me. Even C has a do-while(0) hack for this case.
This is an expanded println!("test")
. The match
looks very similar to the do-while(0) C hack for macros, and I think that it's the wrong way to do it, not only because it looks and feels like a hack, but also because it behaves differently than a native Rust function. For example, println!("test") println!("test")
compiles, while returns_unit() returns_unit()
doesn't.
My proposal: use a self-calling function, similar to what JavaScript allows. I don't know whether it's currently possible in Rust, but if not, I think it could be a natural addition to the language. Here's how I expect it to look, more or less.