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