Skip to content

rustdoc generates illegal <h3> in <span> for struct-like enums #64146

Closed
@kentfredric

Description

@kentfredric

See also #7529, #60403 and #60865

When using a struct-like enum, rustdoc generates the following code for the enums fields:

(hand formatted)

<span class='autohide sub-variant' id='variant.ParseU64Error.fields'>
  <h3>Fields of <b>ParseU64Error</b></h3>
  <div>
    <span id="variant.ParseU64Error.field.input_value" class="variant small-section-header"><a href="#variant.ParseU64Error.field.input_value" class="anchor field"></a><code id='ParseU64Error.v.input_value.v'>input_value:&nbsp;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code></span>
    <div class='docblock'><p>The string that was attempted to be parsed</p></div>
    <span id="variant.ParseU64Error.field.input_line" class="variant small-section-header"><a href="#variant.ParseU64Error.field.input_line" class="anchor field"></a><code id='ParseU64Error.v.input_line.v'>input_line:&nbsp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code></span>
    <div class='docblock'><p>The line of the file that was trying to be decoded</p></div>
    <span id="variant.ParseU64Error.field.input_file" class="variant small-section-header"><a href="#variant.ParseU64Error.field.input_file" class="anchor field"></a><code id='ParseU64Error.v.input_file.v'>input_file:&nbsp;<a class="struct" href="https://doc.rust-lang.org/nightly/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a></code></span>
    <div class='docblock'><p>The file that was being read</p></div>
  </div>
</span>

htmltidy hates this.

line 18 column 7 - Warning: missing </span> before <h3>
line 18 column 80 - Warning: inserting implicit <span>
line 18 column 120 - Warning: inserting implicit <span>
line 18 column 120 - Warning: missing </span> before <div>
line 21 column 13 - Warning: discarding unexpected </span>
line 1 column 3935 - Warning: <a> attribute "href" lacks value

Spans may only contain Phrasing Content but h1 et. al is only "Heading Content".

So what htmltidy ends up doing is closing the first <span> before the <h3>, and this breaks the layout substantially :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions