@@ -113,8 +113,8 @@ use serde_derive::{Deserialize, Serialize};
113113// will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line
114114// are deliberately not in a doc comment, because they need not be in public docs.)
115115//
116- // Latest feature: Add `ExternCrate::path `.
117- pub const FORMAT_VERSION : u32 = 57 ;
116+ // Latest feature: Add `Item::stability `.
117+ pub const FORMAT_VERSION : u32 = 58 ;
118118
119119/// The root of the emitted JSON blob.
120120///
@@ -281,7 +281,10 @@ pub struct Item {
281281 pub links : HashMap < String , Id > ,
282282 /// Attributes on this item.
283283 ///
284- /// Does not include `#[deprecated]` attributes: see the [`Self::deprecation`] field instead.
284+ /// Does not include:
285+ /// - `#[doc = "Doc Comment"]` or `/// Doc comment`: see [`Self::docs`] instead.
286+ /// - `#[deprecated]` attributes: see the [`Self::deprecation`] field instead.
287+ /// - `#[stable]` and `#[unstable]` attributes: see the [`Self::stability`] field instead.
285288 ///
286289 /// Attributes appear in pretty-printed Rust form, regardless of their formatting
287290 /// in the original source code. For example:
@@ -293,10 +296,64 @@ pub struct Item {
293296 pub attrs : Vec < Attribute > ,
294297 /// Information about the item’s deprecation, if present.
295298 pub deprecation : Option < Deprecation > ,
299+
300+ /// Stability information for this item, if any.
301+ ///
302+ /// This describes whether the item itself is stable or unstable, as noted by a `#[stable]` or
303+ /// `#[unstable]` attribute. It does not capture const stability, default-body stability, etc.
304+ ///
305+ /// Whether a path to an item is stable depends on the stability of containing modules
306+ /// or re-exports along that path. For example, a stable item can be reachable through both an
307+ /// unstable module and a stable re-export.
308+ ///
309+ /// For items whose inner kind is [`ItemEnum::Use`], this is the stability of the import itself,
310+ /// not the item being imported. This allows users to determine the stability of paths
311+ /// that involve re-exports.
312+ ///
313+ /// Associated items can inherit instability from their enclosing unstable trait or impl.
314+ /// Unannotated associated items in stable traits or impls may have no separate stability value.
315+ ///
316+ /// Currently, Rust's `#[stable]` and `#[unstable]` attributes are themselves not stable.
317+ /// As a result, this field is primarily populated for standard-library items;
318+ /// most ordinary third-party crates usually have no data here.
319+ pub stability : Option < Box < Stability > > ,
320+
296321 /// The type-specific fields describing this item.
297322 pub inner : ItemEnum ,
298323}
299324
325+ /// Stability information for an item.
326+ ///
327+ /// This only refers to regular item stability: whether the item is stable or unstable
328+ /// as represented by the `#[stable]` or `#[unstable]` attributes.
329+ /// Const stability and default-body stability are different things and not captured here.
330+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
331+ #[ cfg_attr( feature = "rkyv_0_8" , derive( rkyv:: Archive , rkyv:: Serialize , rkyv:: Deserialize ) ) ]
332+ #[ cfg_attr( feature = "rkyv_0_8" , rkyv( derive( Debug ) ) ) ]
333+ pub struct Stability {
334+ /// The stability feature associated with this item.
335+ ///
336+ /// For unstable items, this is the feature gate associated with the item.
337+ /// For stable items, this is the historical label recorded when the item was stabilized.
338+ pub feature : String ,
339+
340+ #[ serde( flatten) ]
341+ pub level : StabilityLevel ,
342+ }
343+
344+ /// Whether an item is stable or unstable as regular public API.
345+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
346+ #[ cfg_attr( feature = "rkyv_0_8" , derive( rkyv:: Archive , rkyv:: Serialize , rkyv:: Deserialize ) ) ]
347+ #[ cfg_attr( feature = "rkyv_0_8" , rkyv( derive( Debug ) ) ) ]
348+ #[ serde( tag = "level" , rename_all = "snake_case" ) ]
349+ pub enum StabilityLevel {
350+ Stable {
351+ /// The Rust version in which this item became stable, if available.
352+ since : Option < String > ,
353+ } ,
354+ Unstable ,
355+ }
356+
300357#[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
301358#[ cfg_attr( feature = "rkyv_0_8" , derive( rkyv:: Archive , rkyv:: Serialize , rkyv:: Deserialize ) ) ]
302359#[ cfg_attr( feature = "rkyv_0_8" , rkyv( derive( Debug ) ) ) ]
@@ -306,6 +363,7 @@ pub struct Item {
306363/// This doesn't include:
307364/// - `#[doc = "Doc Comment"]` or `/// Doc comment`. These are in [`Item::docs`] instead.
308365/// - `#[deprecated]`. These are in [`Item::deprecation`] instead.
366+ /// - `#[stable]` and `#[unstable]`. These are in [`Item::stability`] instead.
309367pub enum Attribute {
310368 /// `#[non_exhaustive]`
311369 NonExhaustive ,
0 commit comments