@@ -130,24 +130,54 @@ impl Deprecation {
130
130
}
131
131
}
132
132
133
- /// Represent parsed, *built in*, inert attributes.
133
+ /// Represents parsed *built- in* inert attributes.
134
134
///
135
- /// That means attributes that are not actually ever expanded.
136
- /// For more information on this, see the module docs on the [`rustc_attr_parsing`] crate.
137
- /// They're instead used as markers, to guide the compilation process in various way in most every stage of the compiler.
138
- /// These are kept around after the AST, into the HIR and further on.
135
+ /// ## Overview
136
+ /// These attributes are markers that guide the compilation process and are never expanded into other code.
137
+ /// They persist throughout the compilation phases, from AST to HIR and beyond.
139
138
///
140
- /// The word "parsed" could be a little misleading here, because the parser already parses
141
- /// attributes early on. However, the result, an [`ast::Attribute`]
142
- /// is only parsed at a high level, still containing a token stream in many cases. That is
143
- /// because the structure of the contents varies from attribute to attribute.
144
- /// With a parsed attribute I mean that each attribute is processed individually into a
145
- /// final structure, which on-site (the place where the attribute is useful for, think the
146
- /// the place where `must_use` is checked) little to no extra parsing or validating needs to
147
- /// happen.
139
+ /// ## Attribute Processing
140
+ /// While attributes are initially parsed by [`rustc_parse`] into [`ast::Attribute`], they still contain raw token streams
141
+ /// because different attributes have different internal structures. This enum represents the final,
142
+ /// fully parsed form of these attributes, where each variant contains contains all the information and
143
+ /// structure relevant for the specific attribute.
148
144
///
149
- /// For more docs, look in [`rustc_attr_parsing`].
145
+ /// Some attributes can be applied multiple times to the same item, and they are "collapsed" into a single
146
+ /// semantic attribute. For example:
147
+ /// ```rust
148
+ /// #[repr(C)]
149
+ /// #[repr(packed)]
150
+ /// struct S { }
151
+ /// ```
152
+ /// This is equivalent to `#[repr(C, packed)]` and results in a single [`AttributeKind::Repr`] containing
153
+ /// both `C` and `packed` annotations. This collapsing happens during parsing and is reflected in the
154
+ /// data structures defined in this enum.
150
155
///
156
+ /// ## Usage
157
+ /// These parsed attributes are used throughout the compiler to:
158
+ /// - Control code generation (e.g., `#[repr]`)
159
+ /// - Mark API stability (`#[stable]`, `#[unstable]`)
160
+ /// - Provide documentation (`#[doc]`)
161
+ /// - Guide compiler behavior (e.g., `#[allow_internal_unstable]`)
162
+ ///
163
+ /// ## Note on Attribute Organization
164
+ /// Some attributes like `InlineAttr`, `OptimizeAttr`, and `InstructionSetAttr` are defined separately
165
+ /// from this enum because they are used in specific compiler phases (like code generation) and don't
166
+ /// need to persist throughout the entire compilation process. They are typically processed and
167
+ /// converted into their final form earlier in the compilation pipeline.
168
+ ///
169
+ /// For example:
170
+ /// - `InlineAttr` is used during code generation to control function inlining
171
+ /// - `OptimizeAttr` is used to control optimization levels
172
+ /// - `InstructionSetAttr` is used for target-specific code generation
173
+ ///
174
+ /// These attributes are handled by their respective compiler passes in the [`rustc_codegen_ssa`] crate
175
+ /// and don't need to be preserved in the same way as the attributes in this enum.
176
+ ///
177
+ /// For more details on attribute parsing, see the [`rustc_attr_parsing`] crate.
178
+ ///
179
+ /// [`rustc_parse`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/index.html
180
+ /// [`rustc_codegen_ssa`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/index.html
151
181
/// [`rustc_attr_parsing`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html
152
182
#[ derive( Clone , Debug , HashStable_Generic , Encodable , Decodable , PrintAttribute ) ]
153
183
pub enum AttributeKind {
0 commit comments