Are empty <> allowed in Rust?

I've found that this code compiles:

#[derive(Debug)]
struct S<>;
fn foo<>(){}
fn bar(){}

fn main() {
    let s = S;
    println!("{:?}", s);
    foo();
    foo::<>();
    bar::<>();
}

Is this intentional? It is not specified in the reference.

I don't see why they should be disallowed. In general, Rust's syntax tends to err on the side of lenience for things like this, trailing commas, and so on, since allowing that makes it a lot easier to write macros without having to special case degenerate cases or edge cases.

4 Likes

I don't believe it's intentional, exactly, but it's not harmful either.

1 Like

I've wanted this when writing deriving-style syntax extensions with the quasi quoting macros.

Yep, this is officially allowed: https://github.com/rust-lang/rust/pull/32023