Skip to content

rustdoc trims all digits except the last two in an ordered list #161144

Description

@zacknewman

I tried this code:

/// A.
pub enum A {
    /// 123.
    B,
}
/// 123.
pub struct B;

I expected to see this happen: rustdoc src/lib.rs to generate docs with the correct comments.

Instead, this happened: rustdoc src/lib.rs generates documentation trimming 1. Additionally it doesn't generate any summary docs for B in the mod.

Meta

rustc --version --verbose:

rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: x86_64-unknown-linux-gnu
release: 1.97.1
LLVM version: 22.1.6

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 15, 2026
  2. zacknewman commented on Aug 15, 2026

    @zacknewman
    Author

    I can supply the actual files under ./doc/ if needed. What gets rendered on the top-level crate HTML looks something like:

    Structs

    B

    Enums

    A                 A.

    Notice the lack of summary doc next to B unlike A. When on the page for B, it looks like:

    pub struct B;
    

    Notice that it shows "23" not "123".

    On the page for A, it looks like:

    pub enum A {
        B,
    }
    

    A.

    Variants

    B
              23.

    Again, notice the comment for variant B says "23" instead of "123".

    When a period is removed, the "1" is not trimmed.

  3. changed the title [-]`rustdoc` incorrectly trims integers[/-] [+]`rustdoc` incorrectly trims integers with a period at the end[/+] on Aug 15, 2026
  4. zacknewman commented on Aug 15, 2026

    @zacknewman
    Author

    While I haven't bothered testing all versions of rustdoc, I believe this is a regression introduced in 1.57.0 since the "1" doesn't get trimmed using 1.56.1. I tried a handful more between 1.57.0 and 1.97.1, and all of them trim the "1".

  5. changed the title [-]`rustdoc` incorrectly trims integers with a period at the end[/-] [+]`rustdoc` trims all digits except that last two when followed by a period[/+] on Aug 15, 2026
  6. Urgau commented on Aug 17, 2026

    @Urgau
    Member

    https://spec.commonmark.org/0.31.2/#ordered-list-marker:

    An ordered list marker is a sequence of 1–9 arabic digits (0-9), followed by either a . character or a ) character.

  7. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    C-discussionCategory: Discussion or questions that doesn't represent real issues.
    T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
    and removed
    C-bugCategory: This is a bug.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 17, 2026
  8. GuillaumeGomez commented on Aug 17, 2026

    @GuillaumeGomez
    Member

    As @Urgau underlined, it's as expected, following the markdown spec. I think there is nothing for us to do here.

  9. zacknewman commented on Aug 17, 2026

    @zacknewman
    Author

    While this doesn't matter for my specific case since the solution is for me to escape the period, why is rustdoc not displaying the entire value? The HTML does have it as an ordered list with "start" set to the correct value, but the CSS or something else is causing it to not be rendered correctly.

    As stated above, 1.56.1 renders it correctly.

    Another example:

    //! Ordered list starting at 123 per the spec:
    //!
    //! 123. Apple.
    //! 124. Orange.
    

    This should be rendered as:

    Ordered list starting at 123 per the spec:

    1. Apple.
    2. Orange.

    But rustdoc, despite generating the correct HTML as something like:

    <p>Ordered list starting at 123 per the spec:</p>
    <ol start="123">
    <li>Apple.</li>
    <li>Orange.</li>
    </ol>

    doesn't actually render the item numbers correctly since it trims all but the last two digits. What gets rendered looks like:

    Ordered list starting at 123 per the spec:

    1. Apple.
    2. Orange.
  10. changed the title [-]`rustdoc` trims all digits except that last two when followed by a period[/-] [+]`rustdoc` trims all digits except the last two in an ordered list[/+] on Aug 17, 2026
  11. GuillaumeGomez commented on Aug 17, 2026

    @GuillaumeGomez
    Member

    That's a fair point. I suspect a change in pulldown-cmark might be the reason. Do you have some extra context here @notriddle ?

  12. notriddle commented on Aug 17, 2026

    @notriddle
    Contributor

    If it’s generating the correct HTML, then it’s not pulldown-cmark. It might be the CSS?

  13. zacknewman commented on Aug 17, 2026

    @zacknewman
    Author

    I can try bisecting 1.57.0 to see what changes occurred from 1.56.1 since as stated the rendering is correct for that version; while 1.57.0, 1.60.0, 1.70.0, 1.80.0, 1.90.0, 1.97.1/stable, and nightly all render the list incorrectly which makes me believe that all versions since 1.57.0 inclusive have this likely-CSS bug.

  14. zacknewman commented on Aug 17, 2026

    @zacknewman
    Author

    Only removing <link rel="stylesheet" href="../static.files/rustdoc-17e0aaed.css"> from the HTML correctly renders all the digits.
    Only removing <div class="docblock"> and its associated end tag correctly renders all the digits.

  15. zacknewman commented on Aug 18, 2026

    @zacknewman
    Author

    Well my first foray with all this AI/LLM stuff proved successful I believe. According to Claude, this is the problem:

    Found it. The culprit is this rule from the CSS file:

    .docblock>:not(.more-examples-toggle):not(.example-wrap){max-width:100%;overflow-x:auto;}

    Your <ol start="123"> is a direct child of .docblock, so it matches and gets overflow-x:auto.

    Here's the chain of events:

    1. ol,ul{padding-left:24px;} reserves only 24px for markers — enough for a couple digits, not three.
    2. List markers are list-style-position: outside by default, so they render in that 24px padding area, to the left of the content box.
    3. Normally an overflowing outside marker is harmless — it just spills into the margin, unclipped.
    4. But once you set overflow-x:auto on the list itself (as this rule does), the browser establishes a scroll/clip container. Now that overflowing marker gets clipped at the edge of the scrollport instead of spilling freely — and since the scroll position starts at the left, the leading digits (the ones sticking furthest left) get cut off, leaving just the trailing digits like "23." instead of "123.".

    Fix: exclude lists from that overflow rule, e.g.:

    .docblock>:not(.more-examples-toggle):not(.example-wrap):not(ol):not(ul){max-width:100%;overflow-x:auto;}

    or simply add overflow-x:visible back for ol/ul inside .docblock, or switch to list-style-position:inside so markers sit inside the padded box instead of overflowing it.

    Following its advice about excluding lists from the overflow rule in rustdoc-17e0aaed.css renders the item numbers correctly.

    Note I'm not a CSS expert, so the above could very well be wrong. I know how "triggering" AI/LLM use can be, so I apologize if I broke any guidelines with its use. Feel free to hide this comment if it's harmful. I also realize that there is still work to do in terms of fixing the actual code that generated this CSS file.

  16. notriddle commented on Aug 18, 2026

    @notriddle
    Contributor

    It's okay, but we're going to need to decide what to do about this, because that rule, when it was introduced in #88742, fixed a different layout bug.

    I would think the solution would be to partially revert that PR, except on tables and code blocks, and add the z-index to the sidebar. That way, we don't need to worry about weird scrolling behavior on unexpected elements.

    The alternative is to make the list elements' padding bigger, so that numbered lists can grow into the triple digits without anything breaking.

  17. GuillaumeGomez commented on Aug 18, 2026

    @GuillaumeGomez
    Member

    Seems like you already have a plan in mind. Gonna assign the issue to you then.

  18. zacknewman commented on Aug 18, 2026

    @zacknewman
    Author
  19. added a commit that references this issue on Aug 21, 2026
  20. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-discussionCategory: Discussion or questions that doesn't represent real issues.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions