Skip to content

rustdoc-json: Expose Item stability#154603

Draft
aDotInTheVoid wants to merge 1 commit intorust-lang:mainfrom
aDotInTheVoid:chaos-with-ed-miliband
Draft

rustdoc-json: Expose Item stability#154603
aDotInTheVoid wants to merge 1 commit intorust-lang:mainfrom
aDotInTheVoid:chaos-with-ed-miliband

Conversation

@aDotInTheVoid
Copy link
Copy Markdown
Member

This is motivated by cargo-semver-checks wanting to work on the standard library, but that requires being able to filter out breaking changes to unstable items, so it can only flag breaking changes to stable items. This in turn is motivated by
#153486.

TODO

  • Decide if this should be a field on Item, or a variant on Attributes
  • Decide what additional information is needed on StabilityLevel
  • Docs
  • Tests around stability propagation and re-exports

CC @obi1kenobi

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 30, 2026

These commits modify tests/rustdoc-json.
rustdoc-json is a public (but unstable) interface.

Please ensure that if you've changed the output:

  • It's intentional.
  • The FORMAT_VERSION in src/librustdoc-json-types is bumped if necessary.

cc @obi1kenobi

rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing src/librustdoc/json/conversions.rs; otherwise, make sure you bump the FORMAT_VERSION constant.

cc @CraftSpider, @Enselic, @obi1kenobi

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 30, 2026

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: rustdoc
  • rustdoc expanded to 9 candidates
  • Random selection from GuillaumeGomez, camelid, fmease, lolbinarycat, notriddle

@rust-cloud-vms rust-cloud-vms bot force-pushed the chaos-with-ed-miliband branch from 759a6df to af8204e Compare March 30, 2026 20:05
/// Information about the item’s deprecation, if present.
pub deprecation: Option<Deprecation>,

pub stability: Option<Stability>,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this should go here, or as a new variant in Attribute. Thoughts appreciated.

#[cfg_attr(feature = "rkyv_0_8", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[cfg_attr(feature = "rkyv_0_8", rkyv(derive(Debug)))]
#[serde(rename_all = "snake_case")]
pub enum StabilityLevel {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to expose more stuff here. Rustc has all of https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.StabilityLevel.html. I'm not sure how much of that anyone other than rustc cares about.

Thoughts appreciated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably interesting tooling that can be built on top of querying that info, but we can save that for rustdoc JSON v59+ if it's a hassle to add here. It's very nice to have but I wouldn't block this PR over it.

@aDotInTheVoid aDotInTheVoid marked this pull request as draft March 30, 2026 20:06
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the chaos-with-ed-miliband branch from af8204e to 5f09a58 Compare March 30, 2026 20:12
Copy link
Copy Markdown
Member

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents: in favor of this approach, and also in favor of not making perfect be the enemy of good.

Stability is a property of the item as a whole, while a stability attribute tells us what's happening syntactically. This is similar to #[deprecated] in my mind: applying #[deprecated] to an enum also implicitly marks its variants as deprecated, so the variants' item-level deprecation status is deprecated but only the enum shows up with a #[deprecated] attribute.

The item-level stability is more valuable than the attribute, because it's authoritative. Syntactic information at the attribute level is nice to have too, but not a blocker. Same with item-level / attribute-level info like since.

View changes since this review

pub level: StabilityLevel,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider Copy too? it's a breaking change to add it later :)

//@ is "$.index[?(@.name=='foo')].stability.level" '"stable"'
//@ is "$.index[?(@.name=='foo')].stability.feature" '"eeeee"'
//@ is "$.index[?(@.name=='foo')].attrs" []
#[stable(since = "2.71.8", feature = "eeeee")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having the since data available would be a neat nice-to-have, but we don't need to block this PR on a nice-to-have

@rust-log-analyzer

This comment has been minimized.

This is motivated by cargo-semver-checks wanting to work on the standard
library, but that requires being able to filter out breaking changes to
unstable items, so it can only flag breaking changes to stable items.
This in turn is motivated by
https://www.github.com/rust-lang/rust/issues/153486.
@rust-cloud-vms rust-cloud-vms bot force-pushed the chaos-with-ed-miliband branch from 5f09a58 to 5245648 Compare March 30, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants