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: add new "Implementations on Foreign Types" section to traits #43849

Merged
merged 3 commits into from
Sep 6, 2017

Conversation

QuietMisdreavus
Copy link
Member

@QuietMisdreavus QuietMisdreavus commented Aug 13, 2017

Demo screenshot:

image

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 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)

@rust-highfive
Copy link
Collaborator

r? @steveklabnik

(rust_highfive has picked a reviewer for you, use r? to override)

@QuietMisdreavus
Copy link
Member Author

r? @GuillaumeGomez

cc @rust-lang/docs @rust-lang/dev-tools

@kennytm
Copy link
Member

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 [-] the whole impl to hide every associated thing in it. Imagine the repetition when reading num_traits::PrimInt...

@GuillaumeGomez
Copy link
Member

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() {
Copy link
Member

@frewsxcv frewsxcv Aug 13, 2017

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
    )?;
}

Copy link
Member Author

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)?;
        }
    }
}

@QuietMisdreavus
Copy link
Member Author

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.

@QuietMisdreavus QuietMisdreavus force-pushed the foreign-impls branch 2 times, most recently from d616e36 to 6406c92 Compare August 13, 2017 23:24
@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 14, 2017
@QuietMisdreavus
Copy link
Member Author

QuietMisdreavus commented Aug 14, 2017

@kennytm I just added a change to auto-hide impl items when printing in this manner.

Demo screenshot:

image

Full demo available at https://tonberry.quietmisdreavus.net/foreign-test/foreign_test/trait.CheckIt.html

@arielb1
Copy link
Contributor

arielb1 commented Aug 22, 2017

Does this look ready for landing @GuillaumeGomez ?

@kennytm
Copy link
Member

kennytm commented Aug 23, 2017

@QuietMisdreavus The placement of "Expand description" seems strange on Firefox 54.0.1. Otherwise LGTM.

aug-23-2017 14-49-55

@GuillaumeGomez
Copy link
Member

@arielb1: Remains some ui issues now. :)

@QuietMisdreavus
Copy link
Member Author

@kennytm That's what I opened #43862 for. When this is merged in with that, it'll look fine. Would you like me to merge my fork forward so i can include that change?

@kennytm
Copy link
Member

kennytm commented Aug 23, 2017

@QuietMisdreavus I see. Either way is fine.

@QuietMisdreavus
Copy link
Member Author

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 >_>) and were generally positive, but wanted some time to consider the utility of the change.

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! :3

@carols10cents
Copy link
Member

carols10cents commented Aug 28, 2017

but wanted some time to consider the utility of the change.

@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
Copy link
Member Author

@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
Copy link
Member

Sounds good! let's make it official then :)

r? @steveklabnik

@bors
Copy link
Contributor

bors commented Sep 1, 2017

☔ The latest upstream changes (presumably #44238) made this pull request unmergeable. Please resolve the merge conflicts.

@steveklabnik
Copy link
Member

Seems good to me, though it's now out of date.

@QuietMisdreavus
Copy link
Member Author

I've rebased to fix the merge conflict.

@steveklabnik
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 5, 2017

📌 Commit a9f0f6d has been approved by steveklabnik

@bors
Copy link
Contributor

bors commented Sep 5, 2017

⌛ Testing commit a9f0f6d with merge f2cdf2fb4df529d6eea7aa607eb6de0eff7c5891...

@bors
Copy link
Contributor

bors commented Sep 5, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

@bors: retry

  • good ol' network troubles

@bors
Copy link
Contributor

bors commented Sep 6, 2017

⌛ Testing commit a9f0f6d with merge fc76d3ac85265db732ebe2bbfe5ed1b84c7209bc...

@bors
Copy link
Contributor

bors commented Sep 6, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

@bors: retry

  • network travis issues

@bors
Copy link
Contributor

bors commented Sep 6, 2017

⌛ Testing commit a9f0f6d with merge 09b101b4a490ed430aa01361c2da20655e4b3a71...

@bors
Copy link
Contributor

bors commented Sep 6, 2017

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Sep 6, 2017

@bors retry

check x86_64-apple-darwin no output in 30 minutes etc 😴.

@bors
Copy link
Contributor

bors commented Sep 6, 2017

⌛ Testing commit a9f0f6d with merge a209539...

bors added a commit that referenced this pull request Sep 6, 2017
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)
@bors
Copy link
Contributor

bors commented Sep 6, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: steveklabnik
Pushing a209539 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants