Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc generates <div> in <h4> when implementing things with #[must_use] and other attributes #60865

Closed
kentfredric opened this issue May 15, 2019 · 3 comments · Fixed by #61263
Assignees
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@kentfredric
Copy link

Similar to #60403

For example, when one generates rustdoc for something that implements Iterator, the generated HTML is (with manual pretty-printing)

<h4 id='method.collect' class="method">
  <code id='collect.v'>
    <div class="docblock attributes">
      #[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
    </div>
    fn
    <a href='https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#method.collect' 
      class='fnname'>collect</a>
      &lt;B&gt;(self) -&gt; B 
     <span class="where fmt-newline">
       where<br>&nbsp;&nbsp;&nbsp;&nbsp;B: 
       <a class="trait" 
            href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.FromIterator.html" 
            title="trait core::iter::traits::collect::FromIterator">FromIterator</a>
       &lt;Self::
       <a class="type"
            href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" 
            title="type core::iter::traits::iterator::Iterator::Item">Item</a>
        &gt;,&nbsp;
     </span>
   </code>
   <span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span>
   <a class='srclink' 
         href='https://doc.rust-lang.org/nightly/src/core/iter/traits/iterator.rs.html#1464-1466' 
         title='goto source code'>[src]</a>
</h4>

This HTML contradicts HTML spec, and causes problems when parsed by a strict parser ( such as html-tidy )

Additionally, this renders very oddly:

snapshot_20190516_100607
snapshot_20190516_100626

rustc --version
#rustc 1.36.0-nightly (372be4f36 2019-05-14)
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 15, 2019
@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented May 17, 2019

What alternative do you suggest? We can just replace it with another tag (like span since it's listed in the allowed one: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content).

@GuillaumeGomez GuillaumeGomez self-assigned this May 17, 2019
@kentfredric
Copy link
Author

The solution of using a <span> instead of <div> worked satisfactorily for the other example.

( The side issue with the weird rendering is more about the weird double-"+", there's probably a better way of doing this, but I'm a bit short of ideas how )

@GuillaumeGomez
Copy link
Member

It's complicated indeed. I'll send a PR to change this soon.

Centril added a commit to Centril/rust that referenced this issue Jun 1, 2019
…earth

Don't generate div inside header (h4/h3/h...) elements

Fixes rust-lang#60865.

According to the HTML spec, we're not supposed to put `div` elements inside heading elements (h4/h3/h...). It doesn't change the display as far as I could tell.

r? @QuietMisdreavus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants