-
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: remove redundant toggles for "undocumented items" #84326
Comments
Also worth noting that the "Show hidden undocumented items" don't respond to the "show all / collapse all" toggle in the upper right, and don't have a corresponding settings.html entry to show or hide them by default. Part of #83332 |
Done in #84754. Don't hesitate to re-open if I missed something but from what I read, it's now done. |
In #84754, we migrated the existing toggles to |
I think we should split this into two cases: Implementations on struct and enum pagesThis demonstrates that the wording "Show hidden undocumented items" is incorrect - these items actually are documented, on the trait itself. That documentation gets copied to the struct or enum page. We're paying the cost in bytes and DOM size for these docs; we should show them by default. And that default can be modified by the "Auto-hide trait implementations" setting. Or, another way of looking at it: If you are looking at some code that calls a method on ErrorKind, and you want to know what that method does, you'll go to the ErrorKind page and Ctrl-F for it. You should be able to find the method regardless of whether it was implemented as part of a trait or not. This is a use case I definitely had early in my Rust journey, and still occasionally do. Implementors on trait pagesWhen you're on a trait page, the thing that's most useful to know is that type T implements the trait. The "undocumented methods" really are repetitive on a trait page and should be hidden. But I think, more than hidden, they should actually be entirely unrendered, since they duplicate information already on the page in the trait definition. There are two things that should potentially be shown under each implementation in the Implementors section of a trait page:
ProposalI propose to remove the toggle for "undocumented items" on struct and enum pages, making the contents always visible. I propose to remove the method documentation for Implementors on trait pages, leaving that information to the implementor's own doc page. |
That would simplify the code a bit. I don't have a strong opinion on this topic though. What do you think @rust-lang/rustdoc? |
I really like both those ideas :) although maybe it makes sense to collapse the method descriptions by default on type pages, since they're always the same and can be long? I don't feel strongly about that though. |
One thing I'm unsure about is how this will feel on pages like I somewhat commonly skim through the trait list looking for specific traits I care about, but I could just turn "Auto-hide trait implementation documentation" back on (sidenote, it appears to be broken on nightly). |
Please open an issue for the broken part. ;) |
Strong +1
Should we show it only if there are explicit method docs on the implementors? |
Currently it's kinda done, but badly. If there is no doc on the implementor method, we put it under "undocumented item" (which is really not clear). So any improvement would be nice. I think that if there is implementor doc, we should show it, otherwise just display something like "read more" and that's it. |
@Nemo157 this is a good point. As an example, Box has 5 implementations of This can be repetitive, and also potentially confusing for a new user. If I see One potential approach would be to "group" these implementations. So we would have one sub-heading for the Default
I think to keep things simpler, on |
Not sure to understand your comment so instead, code: trait Foo {
/// default doc
fn default_fn();
fn another_one();
}
struct Bar;
impl Foo for Bar {
fn default_fn() {}
/// item doc!
fn another_one() {}
} So on |
On On |
Agreed, that'd be duplicated (I actually thought we already did but I guess not so nice idea!).
However I'm not sure to agree on that point: that'd make a lot of duplicated content in all pages... |
This is how we currently do it. For example https://doc.rust-lang.org/nightly/std/fs/struct.File.html#impl-Read: So I was proposing this way to be conservative with regards to what we currently do. You're right that there's a lot of duplicated content across many pages! Is your proposal that we would show no documentation for |
Currently we display the first line/paragraph on "default docs". I'm not sure it's very useful so I would only keep the "read more" part.
The second one: it would show the method signature (very important to keep that part!) but no documentation unless it's this implementation which added it. |
Great. I like this approach. |
Hmm, that seems like it might confuse people into thinking the trait method has no description - maybe instead we could collapse the description by default? |
That's what we currently do. :p Also, there will still be a "read more" link. |
(also, I'm not fully following all the proposed changes, maybe someone could write up the current proposal in the issue description? Presumably it will be in the PR too which seems fine) |
I *think* we just agreed on all details, so I guess we'll have the sum up written shortly. |
Current proposal, which I think should be a few separate PRs:
|
But note that the default setting of "Auto-hide trait implementation documentation" is on, so you still won't see this content by default. |
Ok yes, this still seems confusing to me: #84326 (comment) |
I'd like to avoid adding more things that we collapse by default. It adds page weight for stuff that is usually never seen, and it feels like a way of not addressing head-on the questions of what information needs to be visible where. We could add a link for those trait methods to the trait page, e.g. "Read documentation at Foo." I'm also not particularly opposed to keeping doccomments that came from the trait (as we currently do). |
We don't, we just have the first line. ;)
As long as the trait's items are listed, I'm ok with it.
I'm not too sure about this. It's actually quite useful in some cases like wrapping types where the generic wrapped type can implement (or not) some traits based on what they implement themselves.
Just listing the implementors and not their documentation sounds like a good idea! |
Per discussion in rust-lang#84326. For trait implementations, this was misleading: the items actually do have documentation (but it comes from the trait definition). For both trait implementations and trait implementors, this was redundant: in both of those cases, the items are default-hidden by different toggle at the level above. Update tests: Remove XPath selectors that over-specified on details tag, in cases that weren't testing toggles. Add an explicit test for toggles on methods. Rename item-hide-threshold to toggle-item-contents for consistency.
…aumeGomez Remove toggle for "undocumented items." Per discussion in rust-lang#84326. For trait implementations, this was misleading: the items actually do have documentation (but it comes from the trait definition). For both trait implementations and trait implementors, this was redundant: in both of those cases, the items are default-hidden by different toggle at the level above. Update tests: Remove XPath selectors that over-specified on details tag, in cases that weren't testing toggles. Add an explicit test for toggles on methods. Rename item-hide-threshold to toggle-item-contents for consistency. Demo: https://hoffman-andrews.com/rust/untoggle-undocumented/std/string/struct.String.html https://hoffman-andrews.com/rust/untoggle-undocumented/std/io/trait.Read.html
…=GuillaumeGomez Remove methods under Implementors on trait pages As discussed at rust-lang#84326 (comment). On a trait page, the "Implementors" section currently lists all methods of each implementor. That duplicates the method definitions on the trait itself, and is usually not very useful. So the implementors are collapsed by default. This PR changes rustdoc to just not render them at all. Any documentation specific to an implementor can be found by clicking through to the implementor's page. This moves the "portability" info inside the `<summary>` tags so it is still visible on trait pages (as originally implemented in rust-lang#79201). That also means it will be visible on struct/enum pages when methods are collapsed. Add `#[doc(hidden)]` to all implementations of `Iterator::__iterator_get_unchecked` that didn't already have it. Otherwise, due to rust-lang#86145, the structs/enums with those implementations would generate documentation for them, and that documentation would have a broken link into the Iterator page. Those links were already "broken" but not detected by the link-checker, because they pointed to one of the Implementors on the Iterator page, which happened to have the right anchor name. This reduces the Read trait's page size from 128kB to 68kB (uncompressed) and from 12,125 bytes to 9,989 bytes (gzipped Demo: https://hoffman-andrews.com/rust/remove-methods-implementors/std/string/struct.String.html#trait-implementations https://hoffman-andrews.com/rust/remove-methods-implementors/std/io/trait.Read.html#implementors r? `@GuillaumeGomez`
Yes. Note that these two items are unimplemented:
But it seems from subsequent comments that these were not particularly popular, so I'm going to close this without doing them. |
Oh hmm I really liked the idea of grouping by trait, I forgot that was suggested.
@GuillaumeGomez I'm not sure what you mean by this. Rustdoc will still show just as many impl blocks and they'll have generic parameters, it will just be grouped by the trait. |
Then all good. I thought it meant having one impl displayed if the same trait was implemented multiple times. |
Instead of completely removing the methods from the implementors pages. Can we just show their signature without docs? That would certainly help with navigation and seeing what kind of methods are implemented (excluding default methods), the same way it does with the associate types (which #88490 adds back). cc #88490 |
I was searching a way to remove the "read more" link from the doc-comments in the automatically implemented methods and constants from the trait, and be able to show instead the full doc-comment. But it seems there's not currently a way to customize this behaviour, right? For certain APIS, specially those having a lot of default methods, I find it very inconvenient to have to navigate back and forth between the trait page documentation and the implementation type documentation in order to read more than 1 line of information for many of the methods, and it would be a much better experience if the complete doc-comment was shown for every method in the type page, independently of whether it's a default implementation or not. |
We removed the complete doc comment and replaced it with "read more" because the size of some trait pages was just completely out of control. |
I see. Fortunately I could make a workaround for my usecase, with a macro that duplicates the items in both the trait definition and the implementation. This way the doc-comments can be seen fully both in the trait and in the type doc pages: macro_rules! impl_api {
($type:ident, $trait:ident, $($i:item),*) => {
#[doc = concat!("Associates methods and constants to the [`", stringify!($type), "`] type.")]
pub trait $trait {
$($i)*
}
impl $trait for $type {
$($i)*
}
};
}
// usage:
struct MyType;
impl_api![MyType, MyTrait,
/// `BAR` is 0
const BAR: u8 = 0;,
/// `foo` returns 1
fn foo() -> u8 { 1 }
]; |
Rustdoc has some code to hide "undocumented items." As far as I can tell, that applies to trait implementors (on trait pages) and trait implementations (on struct pages). However, there's already an outer layer of toggles for both the implementors and implementations. For instance, this is what the "implementations" section looks like for the Read trait, if your settings expand implementations by default:
The toggle for each implementation is redundant with the inner toggle for the undocumented items. I think we should remove either the outer toggle or the inner. I'm not sure which is better. One argument in favor of removing the outer toggles: If someone has gone to the trouble of documenting a trait implementation, we should try to display that by default. For instance, here's what the implementations section looks like for String, by default:
However, if you know to expand it, there's actually some really nice documentation there:
There's a similar situation in
rustls
: ItsRead
implementation has important documentation on how to use it properly, but you wouldn't know that documentation was there because it's toggled closed by default.The text was updated successfully, but these errors were encountered: