Uh oh!
There was an error while loading. Please reload this page.
rustdoc: add new "Implementations on Foreign Types" section to traits - #43849
Conversation
rust-highfive
commented
Aug 13, 2017
(rust_highfive has picked a reviewer for you, use r? to override) |
QuietMisdreavus
commented
Aug 13, 2017
cc @rust-lang/docs @rust-lang/dev-tools |
kennytm
commented
Aug 13, 2017
I don't see why impl for foreign types needs to have a separate section. The new style can be applied to local types as well. If the methods of the traits are also shown, please add the ability to |
GuillaumeGomez
commented
Aug 13, 2017
I'm not sure to understand as well. So I'm not against it, but a great big explanation would be appreciated. |
There was a problem hiding this comment.
alternatively, i think the body of this block could be something like:
ifletSome(impl_item) = impls
.find(|i| i.impl_item.def_id == implementor.def_id).next(){let i = &implementor.impl_;let impl_ = Impl{impl_item: impl_item.clone()};let assoc_link = AssocItemLink::GotoSource(
impl_item.def_id,&i.provided_trait_methods);render_impl(
w, cx,&impl_, assoc_link,RenderMode::Normal,
impl_item.stable_since(),false)?;}There was a problem hiding this comment.
Ah right, i guess i did manually rewrite find there. Here's what i got:
for implementor in foreign {// need to get from a clean::Impl to a clean::Item so i can use render_implifletSome(t_did) = implementor.impl_.for_.def_id(){ifletSome(impl_item) = cache.impls.get(&t_did).and_then(|i| i.iter().find(|i| i.impl_item.def_id == implementor.def_id)){let i = &impl_item.impl_item;let impl_ = Impl{impl_item: i.clone()};let assoc_link = AssocItemLink::GotoSource(
i.def_id,&implementor.impl_.provided_trait_methods);render_impl(w, cx,&impl_, assoc_link,RenderMode::Normal, i.stable_since(),false)?;}}}QuietMisdreavus
commented
Aug 13, 2017
The main reason behind this is what's sketched out in the opening screenshot: If you want to apply doc comments to an impl or to a method in an impl, it will only show up if the type being impl'd is a local type. This PR is an attempt to surface doc comments from impls on non-local types, by printing the full impl (sans "default" comments from the trait itself) for those types that aren't part of the local crate. It allows more documentation to be written and surfaced. |
d616e36 to
6406c92Compare@kennytm I just added a change to auto-hide impl items when printing in this manner. Demo screenshot: Full demo available at https://tonberry.quietmisdreavus.net/foreign-test/foreign_test/trait.CheckIt.html |
Does this look ready for landing @GuillaumeGomez ? |
kennytm
commented
Aug 23, 2017
@QuietMisdreavus The placement of "Expand description" seems strange on Firefox 54.0.1. Otherwise LGTM. |
GuillaumeGomez
commented
Aug 23, 2017
@arielb1: Remains some ui issues now. :) |
QuietMisdreavus
commented
Aug 23, 2017
kennytm
commented
Aug 23, 2017
@QuietMisdreavus I see. Either way is fine. |
QuietMisdreavus
commented
Aug 23, 2017
We took a look at this in the docs team meeting today (since three of the four members are also dev-tool peers for rustdoc To restate the intent of this PR: Currently, you can apply doc comments to impl blocks or individual impl items, and the comments will appear when the full impl is rendered on the type's page. However, when you implement a trait on a type that's not part of the crate, that impl is never fully rendered. Thus, those doc comments are lost. This PR aims to fix this, by rendering the "full" trait impls when the type in question isn't part of the crate. This way, these doc comments have a place where they can be visible, and we have an opportunity to write even more docs! |
@QuietMisdreavus how much time? what considerations are being made? What I'm really asking is, what should the infra team PR triagers do with this PR? :) |
QuietMisdreavus
commented
Aug 28, 2017
@carols10cents I guess the most blunt thing to do would be to ping @steveklabnik and get this on his queue since he was the only one to express hesitation on it. Looking back at the log it seemed more like he wanted time to properly review it more than anything. |
carols10cents
commented
Aug 28, 2017
Sounds good! let's make it official then :) |
bors
commented
Sep 1, 2017
☔ The latest upstream changes (presumably #44238) made this pull request unmergeable. Please resolve the merge conflicts. |
steveklabnik
commented
Sep 5, 2017
Seems good to me, though it's now out of date. |
fb15ef5 to
a9f0f6dCompareQuietMisdreavus
commented
Sep 5, 2017
I've rebased to fix the merge conflict. |
steveklabnik
commented
Sep 5, 2017
@bors: r+ |
bors
commented
Sep 5, 2017
📌 Commit a9f0f6d has been approved by |
bors
commented
Sep 5, 2017
⌛ Testing commit a9f0f6d with merge f2cdf2fb4df529d6eea7aa607eb6de0eff7c5891... |
bors
commented
Sep 5, 2017
💔 Test failed - status-travis |
alexcrichton
commented
Sep 5, 2017
@bors: retry
|
bors
commented
Sep 6, 2017
⌛ Testing commit a9f0f6d with merge fc76d3ac85265db732ebe2bbfe5ed1b84c7209bc... |
bors
commented
Sep 6, 2017
💔 Test failed - status-travis |
alexcrichton
commented
Sep 6, 2017
@bors: retry
|
bors
commented
Sep 6, 2017
⌛ Testing commit a9f0f6d with merge 09b101b4a490ed430aa01361c2da20655e4b3a71... |
bors
commented
Sep 6, 2017
💔 Test failed - status-travis |
kennytm
commented
Sep 6, 2017
@bors retry
|
bors
commented
Sep 6, 2017
rustdoc: add new "Implementations on Foreign Types" section to traits Demo screenshot:  Full demo available at https://tonberry.quietmisdreavus.net/foreign-test/foreign_test/trait.CheckIt.html This PR splits the "Implementors" section on trait pages into two: First, for impls on types local to the crate, their impls are kept as-is, printing one line for the impl line, and any additional lines for associated types. However, for types external to the crate, they are now pulled up over the others and are printed (almost) like the summary impl on the type page itself. This gives any doc comments on these impls or methods to be exposed in the documentation. There's just one small problem, though: [libstd docs apparently surface impls for libc and rand, possibly among others](https://tonberry.quietmisdreavus.net/foreign-std/std/marker/trait.Copy.html#foreign-impls). This adds this section to pages in the std docs where we might not want them to show up in the first place. I think this is a bug distinct from this PR, but it does make it drastically apparent. ~~My question, then, is this: Do we want this here? Taking it out involves fixing which impls are visible to rustdoc, possibly specifically when rendering the std facade. I'm convinced this is fine to land as-is, since it adds a feature specifically for non-std crates (i'm thinking of things like `num` or related crates that implement things on primitives or std types as part of their functionality).~~ (EDIT: I have an open PR to fix this: #44026)
bors
commented
Sep 6, 2017
☀️ Test successful - status-appveyor, status-travis |


Demo screenshot:
Full demo available at https://tonberry.quietmisdreavus.net/foreign-test/foreign_test/trait.CheckIt.html
This PR splits the "Implementors" section on trait pages into two: First, for impls on types local to the crate, their impls are kept as-is, printing one line for the impl line, and any additional lines for associated types. However, for types external to the crate, they are now pulled up over the others and are printed (almost) like the summary impl on the type page itself. This gives any doc comments on these impls or methods to be exposed in the documentation.
There's just one small problem, though: libstd docs apparently surface impls for libc and rand, possibly among others. This adds this section to pages in the std docs where we might not want them to show up in the first place. I think this is a bug distinct from this PR, but it does make it drastically apparent.
My question, then, is this: Do we want this here? Taking it out involves fixing which impls are visible to rustdoc, possibly specifically when rendering the std facade. I'm convinced this is fine to land as-is, since it adds a feature specifically for non-std crates (i'm thinking of things like(EDIT: I have an open PR to fix this: #44026)numor related crates that implement things on primitives or std types as part of their functionality).