Description
As discussed in #2568, the trailing semicolon to differentiate 'inner' from 'outer' attributes is not intuitive. Also, #2498 will add doc comments as a special form of attribute, which will differentiate 'inner' doc comments using doxygen's /**< */
syntax. To make inner attribute syntax more consistent with doc comments and more visually distinct I would like to change the inner attribute syntax to:
#<attribute>
The meaning would still be the same - it's an inner attribute - but in practice you would probably think of them as 'crate attributes' or 'module attributes' since they typically would appear at the top of files and apply to whatever the file represents.
No attribute is followed by a semicolon.
Added clarification for people visiting this bug in the future (e.g. for triage), mostly to explain the "inner" vs "outer" distinction, because that terminology is not used in the Rust manual: Currently attributes in Rust can either be terminated by a semi-colon, or they can leave out the semi-colon; the former denotes an "inner attribute", which applies to the (entire) entity that the attribute is declared within, and the latter denotes an "outer attribute", which must be followed by an entity (and applies solely to that entity).
This bug is discussing a number of alternatives to that syntax. Lets see if we can enumerate the proposals and how much interest they have garnered. (Most of the proposals keep the existing outer attribute syntax unchanged, but there is one exception, so I include it in my examples below.)
- (current) semi-colon inner:
mod foo { #[outer(attr)] mod bar { #[inner(attr)]; } }
- brson's orginal angle-bracketed inner:
mod foo { #[outer(attr)] mod bar { #<inner(attr)> } }
- bstrie leading exclamation inner:
mod foo { #[outer(attr)] mod bar { #![inner(attr)] } }
- graydon nested exclamation inner:
mod foo { #[outer(attr)] mod bar { #[!inner(attr)] } }
- brson bracket-less for both, leading exclamation inner:
mod foo { #outer(attr) mod bar { #! inner(attr) } }
- bstrie bracketed-inner, bracket-less outer:
mod foo { #outer(attr) mod bar { #[inner(attr)] } }
- pnkfelix semi-colon terminated bracket-less inner, bracketed outer:
mod foo { #[outer(attr)] mod bar { #inner(attr); } }
Note also of course that we have indeed now switched to denoting macros with a trailing !
as discussed in the comments, which paves the way for the bracket-less forms.