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: Trait implementors could show associated types as well #24200

Closed
alexcrichton opened this issue Apr 8, 2015 · 6 comments
Closed

rustdoc: Trait implementors could show associated types as well #24200

alexcrichton opened this issue Apr 8, 2015 · 6 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

For example there are many implementors of the Deref trait, but you have to follow through on the Self type to see what the associated types are.

Rustdoc may want to show associated type bindings there as well (but the clutter should be evaluated).

cc #21092, the original issue

@alexcrichton alexcrichton added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Apr 8, 2015
@lilyball
Copy link
Contributor

lilyball commented Apr 8, 2015

I'm strongly in favor of this. I didn't actually realize rustdoc was showing associated types in the list of traits for a concrete type, since I often look at the list of implementors for a specific trait instead.

A simple suggestion would be to use the inline shorthand notation, so e.g. core::ops::Index would say something like

impl<T> Index<usize, Output=T> for [T]
impl Index<Range<usize>, Output=str> for String

@Diggsey
Copy link
Contributor

Diggsey commented Jul 13, 2015

Additionally, with generic implementations there may not even be a Self type which can be viewed to see the associated types, eg.

impl<T> ToOwned for [T] where T: Clone

Presumably <[T] as ToOwned>::Owned == Vec<T>, but there's no way to tell that from the documentation, and it could just as well be Box<[T]>.

@jethrogb
Copy link
Contributor

There's another problem similar to the one @Diggsey describes that this would resolve. If crate CA implements a trait with an associated type for a type TB from crate CB, you can't find out the associated type from the docs. The normal way would be to look at the documentation for TB, but that is not necessarily included with the CA documentation.

Example: impl Num for f64 etc.

@mitaa
Copy link
Contributor

mitaa commented Apr 14, 2016

I guess a src-link for all-the-things impls would help here too. (#12932)

@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@jplatte
Copy link
Contributor

jplatte commented Jun 5, 2017

This is also a problem in the futures crate, where there are IntoFuture impl's for tuples, e.g.

impl<A, B> IntoFuture for (A, B) where
    A: IntoFuture,
    B: IntoFuture<Error = A::Error>, 

In that case it would also be very helpful to show the impl blocks documentation on the trait page, which I didn't find an existing issue for. Without either piece of information, it is impossible to know whether this IntoFuture implementation will wait for both Futures to complete before completing itself, or have them race (except maybe that racing would be implemented for Future rather than IntoFuture, but that's far from obvious).

About the extra output potentially cluttering the doc page: What about having the extra information hidden by default, with one of those [+] expanders that we have all over rustdoc pages already?

@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 22, 2017
@QuietMisdreavus
Copy link
Member

I opened #43515 to fix this.

bors added a commit that referenced this issue Jul 30, 2017
…omez

rustdoc: print associated types in traits "implementors" section

When viewing a trait's implementors, they won't show anything about the implementation other than any bounds on the generics. You can see the full implementation details on the page for the type, but if the type is external (e.g. it's an extension trait being implemented for primitives), then you'll never be able to see the details of the implementation without opening the source code. This doesn't solve everything about that, but it does still show an incredibly useful piece of information: the associated types. This can help immensely for traits like `Deref` or `IntoIterator` in libstd, and also for traits like `IntoFuture` outside the standard library.

Fixes #24200

🚨 BIKESHED ALERT 🚨 The indentation and sizing of the types is suspect. I put it in the small text so it wouldn't blend in with the next impl line. (It shares a CSS class with the where clauses, as you can see in the following image.) However, the indentation is nonstandard. I initially tried with no indentation (looked awkward and blended too well with the surrounding impls) and with 4-space indentation (too easy to confuse with where clauses), before settling on the 2-space indentation seen below. It's... okay, i guess. Open to suggestions.

![snippet of the implementors of IntoIterator, showing the associated types](https://user-images.githubusercontent.com/5217170/28697456-a4e01a12-7301-11e7-868e-2a6441d6c9e0.png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants