21
21
>   ;  ; | _ MetaItem_
22
22
>   ;  ; | _ MetaItem_ ` , ` _ MetaSeq_
23
23
24
- Any item declaration may have an _ attribute _ applied to it. Attributes in Rust
25
- are modeled on Attributes in ECMA-335, with the syntax coming from ECMA-334
26
- (C#). An attribute is a general, free-form metadatum that is interpreted
27
- according to name, convention, and language and compiler version. Attributes
28
- may appear as any of:
24
+ Any [ item declaration] or [ generic lifetime or type parameter ] [ generics ] may
25
+ have an attribute applied to it. Attributes are modeled on Attributes in
26
+ [ ECMA-335 ] , with the syntax coming from [ ECMA-334 ] \( C#). An _ attribute _ is a
27
+ general, free-form metadatum that is interpreted according to name, convention,
28
+ and language and compiler version. Attributes may appear as any of:
29
29
30
30
* A single identifier, the attribute name
31
31
* An identifier followed by the equals sign '=' and a literal, providing a
@@ -34,9 +34,10 @@ may appear as any of:
34
34
key/value pair
35
35
* An identifier followed by a parenthesized list of sub-attribute arguments
36
36
37
- Attributes with a bang ("!") after the hash ("#") apply to the item that the
38
- attribute is declared within. Attributes that do not have a bang after the hash
39
- apply to the item that follows the attribute.
37
+ _ Inner attributes_ , written with a bang ("!") after the hash ("#"), apply to the
38
+ item that the attribute is declared within. _ Outer attributes_ , written without
39
+ the bang after the hash, apply to the item or generic parameter that follow the
40
+ attribute.
40
41
41
42
An example of attributes:
42
43
@@ -101,7 +102,8 @@ type int8_t = i8;
101
102
- ` test ` - indicates that this function is a test function, to only be compiled
102
103
in case of ` --test ` .
103
104
- ` ignore ` - indicates that this test function is disabled.
104
- - ` should_panic ` - indicates that this test function should panic, inverting the success condition.
105
+ - ` should_panic ` - indicates that this test function should panic, inverting the
106
+ success condition.
105
107
- ` cold ` - The function is unlikely to be executed, so optimize it (and calls
106
108
to it) differently.
107
109
@@ -153,9 +155,9 @@ which can be used to control type layout.
153
155
- ` no_link ` on an ` extern crate ` — even if we load this crate for macros, don't
154
156
link it into the output.
155
157
156
- See the [ macros section of the
157
- book] ( ../book/first-edition/macros.html#scoping-and-macro-importexport ) for more information on
158
- macro scope.
158
+ See the [ macros section of the first edition of the
159
+ book] ( ../book/first-edition/macros.html#scoping-and-macro-importexport ) for more
160
+ information on macro scope.
159
161
160
162
## Miscellaneous attributes
161
163
@@ -213,8 +215,8 @@ release builds.
213
215
Configuration options are boolean (on or off) and are named either with a
214
216
single identifier (e.g. ` foo ` ) or an identifier and a string (e.g. ` foo = "bar" ` ;
215
217
the quotes are required and spaces around the ` = ` are unimportant). Note that
216
- similarly-named options, such as ` foo ` , ` foo="bar" ` and ` foo="baz" ` may each be set
217
- or unset independently.
218
+ similarly-named options, such as ` foo ` , ` foo="bar" ` and ` foo="baz" ` may each be
219
+ set or unset independently.
218
220
219
221
Configuration options are either provided by the compiler or passed in on the
220
222
command line using ` --cfg ` (e.g. ` rustc main.rs --cfg foo --cfg 'bar="baz"' ` ).
@@ -537,3 +539,7 @@ You can implement `derive` for your own type through [procedural macros].
537
539
[ let statement ] : statements.html#let-statements
538
540
[ unstable book plugin ] : ../unstable-book/language-features/plugin.html#lint-plugins
539
541
[ zero-variant enum ] : items/enumerations.html#zero-variant-enums
542
+ [ ECMA-334 ] : https://www.ecma-international.org/publications/standards/Ecma-334.htm
543
+ [ ECMA-335 ] : https://www.ecma-international.org/publications/standards/Ecma-335.htm
544
+ [ item declaration ] : items.html
545
+ [ generics ] : generics.html
0 commit comments