Skip to content

Syntax for multiple attributes #2516

Closed
Closed
@camden-smallwood-zz

Description

@camden-smallwood-zz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions