Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Simplify attribute syntax #11141

Closed
glaebhoerl opened this issue Dec 25, 2013 · 3 comments
Closed

RFC: Simplify attribute syntax #11141

glaebhoerl opened this issue Dec 25, 2013 · 3 comments

Comments

@glaebhoerl
Copy link
Contributor

Instead of

#[attr1, attr2(foo)]

write

#attr1 #attr2(foo)

in other words, instead of a list of attributes delimited by [], # would introduce a single attribute, and multiple attributes would be written as multiple single attributes.

This is less busy visually, especially when there's only one attribute, which is common. In terms of character count it requires 1 character for a single attribute (vs. 3 with the current syntax), and 2 additional characters for each additional attribute (same as the current syntax).

And it looks like hashtags, which is cute and not a bad intuition.

I don't know why the syntax is the way it is right now: historically, I think it's probably because macros were originally #foo() rather than foo!()? But I don't see any other potential for conflict in today's syntax. (The only other place the # character is even used, as far as I know, is raw strings.)

@alexcrichton
Copy link
Member

Closing as a dupe of #2569. There has been a very large amount of discussion in that other bug, and I believe the settled-upon syntax was:

#^ inner(attribute)

#outer(attribute)
fn main() {}

And we would no longer attributes at the outer layer of the form name = "value"

@liigo
Copy link
Contributor

liigo commented Dec 26, 2013

2013/12/26 Gábor Lehel [email protected]

Instead of

#[attr1, attr2(foo)]

write

#attr1 #attr2(foo)

+1, this is better and simpler

@glaebhoerl
Copy link
Contributor Author

Oh, for some reason I hadn't remembered #2569 also talked about dropping the brackets. Sorry!

flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 20, 2025
…st-lang#14124)

An `if … { … } else { … }` used as the left operand of a binary
expression requires parentheses to be parsed as an expression.

Fix rust-lang#11141

changelog: [`obfuscated_if_else`]: fix bug in suggestion by issuing
required parentheses around the left side of a binary expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants