Feature Request: Avoid brackets on if (And similar) statements

I believe it would come in handy if we could do something like this:

fn main() -> Result<(), String>
    if 1 == 3
        println!("1 is equal to 3!");
    else {
        println!("1 isn't equal to 3... (Well what do you expect?)");
        Err(String::from("1 wasn't equal to three and you get punished."))

Clearly, there isn't any reason to waste space and typing on brackets on the first statement. It is already pretty straightforward.

Another advantage would be that this basically breaks no code. At the worst case, the compiler will implicitly insert brackets at compile time. Also I think it's known to everyone many C and C++ compilers support this.

Last, we could extend this to simply being indentation based (Like Python) and make brackets completely optional, but that's too crazy of a change for me so I won't elaborate further.

And there it has caused more than one security issue due to confusion about what is inside and outside of the if.


This has come up before:


To re-use my most-liked post on this forum:

1 Like

I think we need a "frequently asked questions" or "frequently proposed ideas" or similar, and this should probably be near the top of the list.


Is there a Discourse plugin that could detect "feature request" from brand-new accounts and perhaps interject "have you looked at the FPI list first?" kind of assistance?

Note that even Python doesn't support

Instead, it requires

if 1 == 3:
    print('1 is equal to 3!')

with a colon that is technically completely unnecessary.

Total minimalism of syntax isn't good for humans.


This would also create ambiguities in the syntax, for instance:

if 10 > 3 - 2 - 1 else -4
if foo[1][0] else return

We need the anti-RFCS repo: design proposals that will not happen.


Frequently Requested Changes?


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