Skip to content

Include default-stability info in rustdoc JSON.#158468

Open
obi1kenobi wants to merge 1 commit into
rust-lang:mainfrom
obi1kenobi:pg/default-body-stability
Open

Include default-stability info in rustdoc JSON.#158468
obi1kenobi wants to merge 1 commit into
rust-lang:mainfrom
obi1kenobi:pg/default-body-stability

Conversation

@obi1kenobi

@obi1kenobi obi1kenobi commented Jun 27, 2026

Copy link
Copy Markdown
Member

Add a default_unstable field on associated constants, associated types, and functions. The field is populated only when those items appear inside a trait, only when there's a default present, and when that default is not stable as designated by #[rustc_default_body_unstable]. In such a case, the field contains the name of the feature required to use the unstable default.

The purpose of this info is to allow cargo-semver-checks to lint the standard library for accidental breakage of stable APIs. Removing a stable default is an example of such breakage, while removing an unstable default is not.

The field is boxed to minimize the size impact on its enclosing type, since for regular crates it will always be None.

I also updated jsondoclint to assert that it's an error to have a populated default_unstable when there's no function body, no default const value, or no default associated type. In the process, I noticed that jsondoclint and jsondocck are both on edition 2021 — I plan to upgrade them to 2024 in separate PRs.

r? @GuillaumeGomez

AI disclosure: This PR is the product of a combination of manual work and AI tools. I secured approval in advance from the designated reviewer. I stand behind the quality of the code I'm submitting, and I vouch it's as good or better compared to if I had written every line by my own hand.

@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

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

@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 Jun 27, 2026
@obi1kenobi

Copy link
Copy Markdown
Member Author

CI failure because of edition 2021 in the tool. Upgrading to edition 2024 here: #158470

Will rebase this as soon as that PR merges.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
224 |             && let Some(default_unstable) = &x.default_unstable
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[RUSTC-TIMING] jsondoclint test:true 0.144
error: could not compile `jsondoclint` (bin "jsondoclint" test) due to 2 previous errors
Bootstrap failed while executing `--stage 2 test --skip tidy --skip src/tools/rust-analyzer --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Build completed unsuccessfully in 0:28:38
  local time: Sat Jun 27 05:54:46 UTC 2026
  network time: Sat, 27 Jun 2026 05:54:46 GMT
##[error]Process completed with exit code 1.

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-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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants