Skip to content

rustdoc: parse item and reexport markdown separate - #163058

Open
notriddle wants to merge 1 commit into
rust-lang:mainfrom
notriddle:rustdoc/separate-parsing
Open

notriddle wants to merge 1 commit into
rust-lang:mainfrom
notriddle:rustdoc/separate-parsing

Conversation

@notriddle

@notriddle notriddle commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Change the way Rustdoc behaves when a re-export and its original item both have doc comments.

In other words, code like this:

/// original
struct Foo;

/// re-export
pub use Foo as Bar;

In the current version of Rustdoc, the rendering is equivalent to:

/// re-export
/// original
pub use Bar;

Because there's no blank line between the comments, you get "re-export original" as a single paragraph.

The new version, introduced by this pull request, renders two paragraphs. It actually runs the Markdown parser separately for both items, so link refdefs, footnotes, and, in the future, syntax features are scoped separately.

This change is a pre-requisite for LaTeX support, because it introduces the notion of syntax features into Rustdoc's Markdown. It lets you turn tex_math_dollars support on and off.

As part of this change, a bug related to intra-doc links is also fixed. This shows up when the reexport and the item both have intra-doc links with the same visible path, but where they resolve to different items. The bug is demonstrated in
tests/rustdoc-html/reexport/link-with-same-name-but-different-destination.rs.

The other test case changes demonstrate that this is, technically, a breaking change. When I ran a Crater test for docs that rely on this behavior, though, it seemed most authors weren't relying on it.

@rustbot

rustbot commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Sep 20, 2026
@rustbot

rustbot commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
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 8 candidates
  • Random selection from GuillaumeGomez, lolbinarycat

@rust-log-analyzer

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from 9c1da60 to 2f5048f Compare September 20, 2026 06:51
@rust-log-analyzer

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from 2f5048f to fcbb219 Compare September 20, 2026 14:46
@rust-log-analyzer

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from fcbb219 to 605cfeb Compare September 20, 2026 15:33
@rust-log-analyzer

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from 605cfeb to 97e368b Compare September 21, 2026 02:31
@rust-log-analyzer

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from 97e368b to e1cc402 Compare September 21, 2026 03:15
Comment thread src/rustdoc-json-types/lib.rs
@rust-log-analyzer

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from 8f06097 to e13bbd3 Compare September 21, 2026 04:42
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from e13bbd3 to f672f66 Compare September 21, 2026 05:54
Comment thread src/librustdoc/clean/types.rs Outdated
Comment thread src/librustdoc/html/render/mod.rs Outdated
Comment thread src/librustdoc/html/render/mod.rs Outdated
@rust-bors

This comment has been minimized.

@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from a16baa4 to e1059f3 Compare September 30, 2026 02:15
@rustbot

This comment has been minimized.

Change the way Rustdoc behaves when a re-export and its original item both have doc comments.

In other words, code like this:

```rust
/// original
struct Foo;

/// re-export
pub use Foo as Bar;
```

In the current version of Rustdoc, the rendering is equivalent to:

```rust
/// re-export
/// original
pub use Bar;
```

Because there's no blank line between the comments, you get "re-export original" as a single paragraph.

The new version, introduced by this pull request, renders two paragraphs. It actually runs the Markdown parser separately for both items, so link refdefs, footnotes, and, in the future, syntax features are scoped separately.

This change is a pre-requisite for [LaTeX support](rust-lang#162365), because it introduces the notion of syntax features into Rustdoc's Markdown. It lets you turn tex_math_dollars support on and off.

As part of this change, a bug related to intra-doc links is also fixed. This shows up when the reexport and the item both have intra-doc links with the same visible path, but where they resolve to different items. The bug is demonstrated in
`tests/rustdoc-html/reexport/link-with-same-name-but-different-destination.rs`.

The other test case changes demonstrate that this is, technically, a breaking change. When I ran [a Crater test](rust-lang#162169) for docs that rely on this behavior, though, it seemed most authors weren't relying on it.
@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from e1059f3 to 4dd5eb4 Compare October 3, 2026 19:59
@rustbot

rustbot commented Oct 3, 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.

This branch has not been deployed

No deployments
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants