Are empty <> allowed in Rust?


#1

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.


#2

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.


#3

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


#4

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


#5

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