-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: add new "Implementations on Foreign Types" section to traits #43849
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
cc @rust-lang/docs @rust-lang/dev-tools |
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 |
I'm not sure to understand as well. So I'm not against it, but a great big explanation would be appreciated. |
|
||
for implementor in foreign { | ||
// need to get from a clean::Impl to a clean::Item so i can use render_impl | ||
if let Some(t_did) = implementor.impl_.for_.def_id() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, i think the body of this block could be something like:
if let Some(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_impl
if let Some(t_did) = implementor.impl_.for_.def_id() {
if let Some(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)?;
}
}
}
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
6406c92
Compare
@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 ? |
@QuietMisdreavus The placement of "Expand description" seems strange on Firefox 54.0.1. Otherwise LGTM. |
@arielb1: Remains some ui issues now. :) |
@QuietMisdreavus I see. Either way is fine. |
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? :) |
@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. |
Sounds good! let's make it official then :) |
☔ The latest upstream changes (presumably #44238) made this pull request unmergeable. Please resolve the merge conflicts. |
Seems good to me, though it's now out of date. |
fb15ef5
to
a9f0f6d
Compare
I've rebased to fix the merge conflict. |
@bors: r+ |
📌 Commit a9f0f6d has been approved by |
⌛ Testing commit a9f0f6d with merge f2cdf2fb4df529d6eea7aa607eb6de0eff7c5891... |
💔 Test failed - status-travis |
@bors: retry
|
⌛ Testing commit a9f0f6d with merge fc76d3ac85265db732ebe2bbfe5ed1b84c7209bc... |
💔 Test failed - status-travis |
@bors: retry
|
⌛ Testing commit a9f0f6d with merge 09b101b4a490ed430aa01361c2da20655e4b3a71... |
💔 Test failed - status-travis |
@bors retry
|
rustdoc: add new "Implementations on Foreign Types" section to traits Demo screenshot: ![image](https://user-images.githubusercontent.com/5217170/29281219-c547f758-80e3-11e7-808f-49f592c65c5b.png) 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)
☀️ 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)num
or related crates that implement things on primitives or std types as part of their functionality).