Skip to content

rustdoc: parse item and reexport markdown separate - #163058

Open
notriddle wants to merge 2 commits into
rust-lang:mainfrom
notriddle:rustdoc/separate-parsing
Open

notriddle wants to merge 2 commits into
rust-lang:mainfrom
notriddle:rustdoc/separate-parsing

Conversation

@notriddle

@notriddle notriddle commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

This change is a pre-requisite for LaTeX support, because the markdown parser doesn't support enabling and disabling extensions in the middle of a document, and there's no way to add that. This means string concatenating a document that has LaTeX Math disabled with a document that has it enabled can't be done.

As part of this change, a bug related to intra-doc links is 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.

This change is a pre-requisite for LaTeX support, because the markdown
parser doesn't support enabling and disabling extensions in the middle
of a document, and there's no way to add that. This means string
concatenating a document that has LaTeX Math disabled with a document
that has it enabled can't be done.

As part of this change, a bug related to intra-doc links is 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.
@notriddle
notriddle force-pushed the rustdoc/separate-parsing branch from 97e368b to e1cc402 Compare September 21, 2026 03:15
pub links: HashMap<String, Id>,
/// The full markdown docstring of this item. Empty if there is no documentation at all,
/// `vec![Doc { text: "" }]` if there is some documentation but it is empty (EG `#[doc = ""]`).
pub docs: Vec<Doc>,

@obi1kenobi obi1kenobi Sep 21, 2026

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.

I'm curious, when might this Vec have more than one element?

It might be useful to include an example in the doc comment, for ease of use.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call. I've added an example and some description to the docs.

The full markdown docstring of this item. Empty if there is no documentation at all,
vec![Doc { text: "" }] if there is some documentation but it is empty (EG #[doc = ""]),
and multiple items if a reexport and the original both have docstrings.

/// Reexport docs
pub use Thing1 as Thing2;

/// Original docs
pub struct Thing1;
{
    "name": "Thing2",
    "docs": [
        { "text": "Reexport docs", "links": [] },
        { "text": "Original docs", "links": [] },
    ],
    ...
}

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.

Ah interesting! Nice, thank you.

Is any particular order of elements guaranteed? That's the only remaining thing I'd consider adding.

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