Skip to content

Rustdoc generates illegal "<div>" inside "<pre>" with traits #64371

Closed
@kentfredric

Description

@kentfredric

Similar to the previous bugs I've filed in this regard with illegal html:

In: 1.39.0-nightly (34e82a7 2019-09-10)

The following trait definition:

#[cfg_attr(
    feature = "external_doc",
    doc(include = "CacheFieldCollection.md")
)]
#[cfg_attr(
    not(feature = "external_doc"),
    doc = "An abstact representation of 'a thing' that can expose data \
           about its unit."
)]
pub trait CacheFieldCollection {
    /// Returns a struct containing data recorded for this thing
    fn fields(&self) -> &CacheFieldData;
    /// Returns a timestamp indicating time of last modification/update
    fn mtime(&self) -> &chrono::DateTime<Utc>;
}

Emits invalid html ( hand formatted ):

<div class="docblock type-decl hidden-by-usual-hider">
<pre class='rust trait'>pub trait CacheFieldCollection {
    fn <a href='#tymethod.fields' class='fnname'>fields</a>(&amp;self) -&gt; &amp;<a class="struct" href="../ccache_stats_reader/struct.CacheFieldData.html" title="struct ccache_stats_reader::CacheFieldData">CacheFieldData</a>;
<div class='item-spacer'></div>    fn <a href='#tymethod.mtime' class='fnname'>mtime</a>(&amp;self) -&gt; &amp;<a class="struct" href="https://docs.rs/chrono/latest/chrono/datetime/struct.DateTime.html" title="struct chrono::datetime::DateTime">DateTime</a>&lt;<a class="struct" href="https://docs.rs/chrono/latest/chrono/offset/utc/struct.Utc.html" title="struct chrono::offset::utc::Utc">Utc</a>&gt;;
}</pre></div>

"pre", like headers, only permits child nodes that are "phrasing content", of which, div is excluded.

So the error is from <div class='item-spacer'></div>

htmltidy handles this by prematurely ending the <pre> before the <div>, and then reinserting a <pre> afterwards, breaking layout:

snapshot_20190911_160411

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