Skip to content

Rustdoc: unify impl blocks where possible. #52563

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

Open
richard-uk1 opened this issue Jul 20, 2018 · 8 comments
Open

Rustdoc: unify impl blocks where possible. #52563

richard-uk1 opened this issue Jul 20, 2018 · 8 comments
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@richard-uk1
Copy link
Contributor

From #32631:

We'll have to be sure to update rustdoc, however, to provide one unified view to the API surface area rather than multiple impl blocks.

I have run into a similar problem when using codegen (specifically, in web-sys), where currently each function/value is inside its own impl block, e.g.

impl Event {
    pub const CAPTURING_PHASE: u16 = 1;
}
impl Event {
    pub const AT_TARGET: u16 = 2;
}
impl Event {
    pub const BUBBLING_PHASE: u16 = 3;
}
impl Event {
    pub const ALT_MASK: i32 = 1;
}

Presently all these appear as separate impl blocks in rustdoc. It would be easier to read if they were in a single block.

@richard-uk1
Copy link
Contributor Author

I'd like to help implement this, but I've not hacked on rustdoc before.

@ExpHP
Copy link
Contributor

ExpHP commented Jul 22, 2018

Sometimes this might be done deliberately, e.g. breaking impls into sets of 2-4 methods to keep where clauses closer to methods, or to write docstrings on the impl blocks.

@richard-uk1
Copy link
Contributor Author

richard-uk1 commented Jul 22, 2018

Hmm, I'm not sure how to reconcile the two things. I didn't know you could write docs on impl blocks. I'm not proposing unifying impl blocks with different where clauses, they should stay separate. So these would have 2 blocks in the docs

impl<T> Vec<T> {
    // ...
}

impl<T> Vec<T>
where T: Clone
{
    // ...
}

whereas these would be unified

impl<T> Vec<T> {
    // ...
}

impl<T> Vec<T> {
    // ...
}

EDIT I guess I'm arguing that which impl block a function is in (with the same generic constraints) is an implementation detail that shouldn't leak. There is the orthogonal issue that rustdoc doesn't necessarily order the fns/structs/etc. in the most logical order, compared to something like documentation in elm, where the user must specify the layout of the items.

@memoryruins memoryruins added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 15, 2018
@steveklabnik
Copy link
Member

Triage: don't believe there's any change here

@richard-uk1
Copy link
Contributor Author

It would be great to be able to do this even if behind a flag or similar - the web-sys docs would benefit greatly from this.

@tczajka
Copy link

tczajka commented Sep 19, 2021

Sometimes this might be done deliberately, e.g. breaking impls into sets of 2-4 methods to keep where clauses closer to methods, or to write docstrings on the impl blocks.

A solution to this is to unify those impl blocks with the same docstrings and where clauses.

@richard-uk1
Copy link
Contributor Author

richard-uk1 commented Sep 19, 2021 via email

@dylni
Copy link
Contributor

dylni commented Feb 5, 2022

Related: #82408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

6 participants