@@ -36,8 +36,8 @@ use serde_derive::{Deserialize, Serialize};
3636// will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line
3737// are deliberately not in a doc comment, because they need not be in public docs.)
3838//
39- // Latest feature: Pretty printing of no_mangle attributes changed
40- pub const FORMAT_VERSION : u32 = 53 ;
39+ // Latest feature: Structured Attributes
40+ pub const FORMAT_VERSION : u32 = 54 ;
4141
4242/// The root of the emitted JSON blob.
4343///
@@ -194,13 +194,94 @@ pub struct Item {
194194 /// - `#[repr(C)]` and other reprs also appear as themselves,
195195 /// though potentially with a different order: e.g. `repr(i8, C)` may become `repr(C, i8)`.
196196 /// Multiple repr attributes on the same item may be combined into an equivalent single attr.
197- pub attrs : Vec < String > ,
197+ pub attrs : Vec < Attribute > ,
198198 /// Information about the item’s deprecation, if present.
199199 pub deprecation : Option < Deprecation > ,
200200 /// The type-specific fields describing this item.
201201 pub inner : ItemEnum ,
202202}
203203
204+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
205+ #[ serde( rename_all = "snake_case" ) ]
206+ /// An attribute, e.g. `#[repr(C)]`
207+ ///
208+ /// This doesn't include:
209+ /// - `#[doc = "Doc Comment"]` or `/// Doc comment`. These are in [`Item::docs`] instead.
210+ /// - `#[deprecated]`. These are in [`Item::deprecation`] instead.
211+ pub enum Attribute {
212+ /// `#[non_exhaustive]`
213+ NonExhaustive ,
214+
215+ /// `#[must_use]`
216+ MustUse { reason : Option < String > } ,
217+
218+ /// `#[export_name = "name"]`
219+ ExportName ( String ) ,
220+
221+ /// `#[link_section = "name"]`
222+ LinkSection ( String ) ,
223+
224+ /// `#[automatically_derived]`
225+ AutomaticallyDerived ,
226+
227+ /// `#[repr]`
228+ Repr ( AttributeRepr ) ,
229+
230+ /// `#[no_mangle]`
231+ NoMangle ,
232+
233+ /// #[target_feature(enable = "feature1", enable = "feature2")]
234+ TargetFeature { enable : Vec < String > } ,
235+
236+ /// Something else.
237+ ///
238+ /// Things here are explicitly *not* covered by the [`FORMAT_VERSION`]
239+ /// constant, and may change without bumping the format version.
240+ ///
241+ /// As an implementation detail, this is currently either:
242+ /// 1. A HIR debug printing, like `"#[attr = Optimize(Speed)]"`
243+ /// 2. The attribute as it appears in source form, like
244+ /// `"#[optimize(speed)]"`.
245+ Other ( String ) ,
246+ }
247+
248+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
249+ /// The contents of a `#[repr(...)]` attribute.
250+ ///
251+ /// Used in [`Attribute::Repr`].
252+ pub struct AttributeRepr {
253+ /// The representation, e.g. `#[repr(C)]`, `#[repr(transparent)]`
254+ pub kind : ReprKind ,
255+
256+ /// Alignment in bytes, if explicitly specified by `#[repr(align(...)]`.
257+ pub align : Option < u64 > ,
258+ /// Alignment in bytes, if explicitly specified by `#[repr(packed(...)]]`.
259+ pub packed : Option < u64 > ,
260+
261+ /// The integer type for an enum descriminant, if explicitly specified.
262+ ///
263+ /// e.g. `"i32"`, for `#[repr(C, i32)]`
264+ pub int : Option < String > ,
265+ }
266+
267+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
268+ #[ serde( rename_all = "snake_case" ) ]
269+ /// The kind of `#[repr]`.
270+ ///
271+ /// See [AttributeRepr::kind]`.
272+ pub enum ReprKind {
273+ /// `#[repr(Rust)]`
274+ ///
275+ /// Also the default.
276+ Rust ,
277+ /// `#[repr(C)]`
278+ C ,
279+ /// `#[repr(transparent)]
280+ Transparent ,
281+ /// `#[repr(simd)]`
282+ Simd ,
283+ }
284+
204285/// A range of source code.
205286#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
206287pub struct Span {
@@ -1342,7 +1423,7 @@ pub struct Static {
13421423
13431424 /// Is the static `unsafe`?
13441425 ///
1345- /// This is only true if it's in an `extern` block, and not explicity marked
1426+ /// This is only true if it's in an `extern` block, and not explicitly marked
13461427 /// as `safe`.
13471428 ///
13481429 /// ```rust
0 commit comments