@@ -35,8 +35,7 @@ Attributes may appear as any of:
35
35
36
36
_ Inner attributes_ , written with a bang ("!") after the hash ("#"), apply to the
37
37
item that the attribute is declared within. _ Outer attributes_ , written without
38
- the bang after the hash, apply to the item or generic parameter that follow the
39
- attribute.
38
+ the bang after the hash, apply to the thing that follows the attribute.
40
39
41
40
Attributes may be applied to many things in the language:
42
41
@@ -82,6 +81,47 @@ fn some_unused_variables() {
82
81
}
83
82
```
84
83
84
+ There are three kinds of attributes:
85
+
86
+ * Built-in attributes
87
+ * Macro attributes
88
+ * Derive mode helper attributes
89
+
90
+ ## Dynamic and inert attributes
91
+
92
+ An attribute is either dynamic or inert. During attribute processing, * dynamic
93
+ attributes* remove themselves from the thing they are on while * inert attriutes*
94
+ stay on.
95
+
96
+ The ` cfg ` and ` cfg_attr ` attributes are dynamic. The ` test ` attribute is inert
97
+ when compiling for tests and dynamic otherwise. Attribute macros are dynamic.
98
+ All other attributes are inert.
99
+
100
+ ## Attribute resolution
101
+
102
+ On all things except for items, attribute resolution is straightforward. The
103
+ ` cfg ` and ` cfg_attr ` attributes are applied and only inert attributes are
104
+ allowed. Each of those inert attributes then resolve to either a built-in
105
+ attribute or a derive mode helper attribute. If the attribute cannot resolve to
106
+ either, it is an error.
107
+
108
+ For items, attribute resolution is a bit more involved. First off, if there are
109
+ any ` cfg ` , ` cfg_attr ` , or ` test ` attributes when not compiling tests, they are
110
+ resolved first, and removed from the item. Then, each attribute is checked in
111
+ the order they are written. If the attribute resolves to an inert attribute,
112
+ check the next attribute. If the attribute resolves to a dynamic attribute, then
113
+ perform its dynamic behavior. This will effectively replace the item with a new
114
+ set of items that must go through attribute resolution from the beginning. If
115
+ the attribute resolves to a macro that is not an attribute macro, it is an
116
+ error. Otherwise, the attriute is not current resolveable. In this case, wait
117
+ until another item brings the attribute into scope, and then recheck it. If all
118
+ other items have their attributes resolved or are also waiting for attribute or
119
+ derive mode resolution, it is an error. If all of the attributes are inert, then
120
+ the item is finalized. If the item defines a new path for a macro, it is now
121
+ available for other items.
122
+
123
+ ---
124
+
85
125
The rest of this page describes or links to descriptions of which attribute
86
126
names have meaning.
87
127
0 commit comments