Skip to content

Include default-stability info in rustdoc JSON.#158468

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
obi1kenobi:pg/default-body-stability
Jun 30, 2026
Merged

Include default-stability info in rustdoc JSON.#158468
rust-bors[bot] merged 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

obi1kenobi commented Jun 27, 2026

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. EDIT: Now done.

@rust-log-analyzer

This comment has been minimized.

@obi1kenobi obi1kenobi force-pushed the pg/default-body-stability branch from 2e055e1 to bd938c5 Compare June 28, 2026 13:21
@rustbot

rustbot commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez GuillaumeGomez left a comment

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.

Code changes look good to me. Please add a rustdoc-ui test for the bug! case you added.

View changes since this review

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

Copy link
Copy Markdown
Member Author

That path is currently unreachable. Perhaps bug! isn't the right way to signal that? I don't think there's a way to cover the bug! with a test.

Hittng that path today would require that Rust add an explicitly-stable equivalent of #[rustc_default_body_unstable]. Right now that attribute only produces unstable HIR elements. There's no way to produce the stable level equivalent there.

Is there some other way I can use to signal the unreachability of that path? I used bug! over unreachable! because bug!'s comment says that will include a nicer error message, even though both will trigger an ICE. If there's something even more idiomatic, I'm happy to use it.

@GuillaumeGomez

Copy link
Copy Markdown
Member

No it's fine as is. Just curious if it could be triggered. If it's not supposed to, then all good!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bd938c5 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
…ty, r=GuillaumeGomez

Include default-stability info in rustdoc JSON.

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.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
…ty, r=GuillaumeGomez

Include default-stability info in rustdoc JSON.

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.
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 6 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158323 (rustc: improve diagnostics for file-open failures)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
…ty, r=GuillaumeGomez

Include default-stability info in rustdoc JSON.

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.
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 12 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158417 (Avoid ICE when cfg_eval recovers no item from derive input)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…ty, r=GuillaumeGomez

Include default-stability info in rustdoc JSON.

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.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…ty, r=GuillaumeGomez

Include default-stability info in rustdoc JSON.

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.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
…ty, r=GuillaumeGomez

Include default-stability info in rustdoc JSON.

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.
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try jobs=dist-x86_64-msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
Include default-stability info in rustdoc JSON.


try-job: dist-x86_64-msvc
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #156295 (Pass the whole `GenericArgs` to `Interner::for_each_relevant_impl()`)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158543 (Note usage of documentation hard links in `core::io`)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
@rust-bors

rust-bors Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ad15860 (ad158606065036778d7aed7329488f6b884b4621)
Base parent: 0966944 (096694416a41840709140eb0fd0ca193d1a3e6ba)

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #156295 (Pass the whole `GenericArgs` to `Interner::for_each_relevant_impl()`)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158543 (Note usage of documentation hard links in `core::io`)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #156295 (Pass the whole `GenericArgs` to `Interner::for_each_relevant_impl()`)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158543 (Note usage of documentation hard links in `core::io`)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
@rust-bors rust-bors Bot merged commit 244d5c2 into rust-lang:main Jun 30, 2026
14 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 30, 2026
rust-timer added a commit that referenced this pull request Jun 30, 2026
Rollup merge of #158468 - obi1kenobi:pg/default-body-stability, r=GuillaumeGomez

Include default-stability info in rustdoc JSON.

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.
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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