-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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: render problems for re-exported implementors #85418
Comments
@jsha does this also happen for re-exports in the same crate? or only across crates? |
I'm not sure, sorry! |
It turns out the implementors that are rendered differently are inserted by JavaScript here: rust/src/librustdoc/html/static/main.js Lines 661 to 725 in 3f9646d
That pulls in a list of implementors from a .js file, which is generated by the Rust code here: rust/src/librustdoc/html/render/write_shared.rs Lines 541 to 552 in 3f9646d
I haven't figured out what triggers the HTML page to load that extra JS. |
Here's the code that adds the script tag to load the extra JS: rust/src/librustdoc/html/render/print_item.rs Lines 755 to 769 in 3f9646d
|
So, a summary of the problem here: For in-crate implementors, rustdoc renders HTML directly. For out-of-crate implementors, rustdoc renders HTML into a string in a JS file. That means we have two different code paths putting the implementors into the HTML page so they're likely to drift apart. This also means that out-of-crate implementors can't be sorted alongside the in-crate implementors. The ideal would be for the out-of-crate implementors to be rendered directly into the HTML (and sorted along with all the in-crate implementors). I think that's not really practical, because as I understand it, the out-of-crate implementors can be generated by separate invocations of rustdoc. One hack to improve the incorrect sorting would be to have a separate heading for out-of-crate implementors. But that doesn't address the "likely to drift apart" problem. |
Relatedly, there is sometimes a section for "Implementations on Foreign Types" (e.g. https://doc.rust-lang.org/nightly/std/cmp/trait.Eq.html#foreign-impls). It's not clear to me what causes an impl to wind up in "Implementations on Foreign Types" vs appended to the Implementors section by way of JS. Maybe it makes sense for the JS-provided impls to wind up under that section? Also we should probably define "Foreign Types." AFAICT by searching Google and The Book, this is not defined in commonly used Rust materials. |
"foreign types" is common in the compiler, but maybe not in the documentation. It means types from another crate; I see it used a lot in explanations of the orphan rules. Yes, I agree putting everything in "Foreign Types" instead of JS is a better approach. I don't know enough about the code to help, sorry. |
Unfortunately, this isn't an alternative to loading the implementations from JS, it's just an informational-organization thing. For a trait in crate
|
I don't think those are the same case. "Implementation on Foreign Types" is an implementation by the trait author on types from other crates". "Implementations" is an implementation on a new downstream crate in the same crate that the type is defined. "Foreign" here is foreign from the perspective of the impl, not the trait - it matters for coherence. |
Right, they're not the same case from the trait author's perspective (or the struct/enum author's perspective). But from the perspective of a user reading the docs for trait Foo, is it different? As a concrete example, say trait |
That said, the problem of sorting would actually be much easier to solve by further subdividing things, so we'd have: Implementations in this Crate on Types in this Crate Then each section could be sorted individually. The "Implementations in Other Crates" section would come purely from JS (/JSON) and could be sorted in JS. |
Related: #86632 |
On both stable and nightly, the "Implementors" section of a trait page incorrectly renders re-exported types. For instance, on https://doc.rust-lang.org/std/marker/trait.Sync.html, there are two entries for
LinkedList
.std::collections::LinkedList
alloc::collections::LinkedList
These are different in the way they are displayed: for instance, the
where
clause is displayed differently even though these are the same type. Also, thealloc
version is missing its[src]
link.Looking at the HTML, the
alloc
version looks like this (I included some of the HTML of the previous, correct element for comparison):Some issues here:
id=impl-Sync-51
<code>
tag inside another<code>
tag, which is unnecessary.The text was updated successfully, but these errors were encountered: