Allow more semicolons

Continuing the discussion from Make (Some) Separators Optional:

What would it take to allow semicolons after curly brace-delimited items? Like this?

// not valid Rust
struct MyStruct {
};
fn my_fn() {
};

There are two big reasons to want to allow this:

  1. They’re already allowed in function bodies, where they parse as empty statements. Not allowing them outside the functions seems inconsistent with that. In other words, this is already valid:

    fn my_fn() {
        fn my_fn_inside() {
        };
    }
    
  2. For non-brace-delimited items, semicolons are not only allowed, they’re required. This includes not only things that obvious need delimiters, like this unit-like struct:

    struct MainThreadWitness;
    

    They are also required with this tuple-like struct:

    struct MyNewType(u32);
    

    What’s so special about round braces compared to curly braces?

Me and @ExpHP wrote an RFC allowing this a few days ago. Sorry, should have linked in the thread :wink:

The exact technical solution are somewhat up in the air atm.

1 Like

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