Hello, I've been experimenting with Rust since around the 0.3 release, but this is my first time posting an issue. I tried looking to see if there was already an open issue related to this, but I couldn't find anything.
Being a long-time C# programmer, I have a lot of code written in C# that I've transcribed to Rust. Attributes are a language feature that C# and Rust share in common, yet I've always found Rust's syntax for declaring attributes to be clunky and limiting.
Consider the following Rust code:
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct Point2D {
pub x: f32,
pub y: f32
}
If I were to write that same code in C# syntax, it would look somewhat like this pseudocode:
[Repr(C)]
[Derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
public struct Point2D
{
public float X;
public float Y;
}
However, C# allows you to condense attributes into a single pair of square brackets, like so:
[Repr(C), Derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
This allows us to save a line of text, and removes some noise from the screen. I wrote this issue because I wanted to propose that Rust should implement a similar setup for attribute declaration, making both of the following be valid syntax and having the same effect on code:
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct A;
#[repr(C), derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct A;
If this was brought up in the past and declined, I apologize. Thank you for taking the time to check this out.
https://github.com/rust-lang/rust/pull/50120 restricted the attribute grammar from arbitrary token streams to delimited token trees, so this should be possible to do now.
I plan to write an RFC for this once I get RFC #2539 implemented.
For more prior art, C
has __attr__()
with multiple attributes as well.
Closing in favor of https://github.com/rust-lang/rfcs/pull/2600.
Most helpful comment
I plan to write an RFC for this once I get RFC #2539 implemented.
For more prior art,
C
has__attr__()
with multiple attributes as well.