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 shouldn't document a struct's associated constants as methods #70475

Closed
melaquin opened this issue Mar 27, 2020 · 2 comments · Fixed by #71918
Closed

Rustdoc shouldn't document a struct's associated constants as methods #70475

melaquin opened this issue Mar 27, 2020 · 2 comments · Fixed by #71918
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@melaquin
Copy link

When writing associated constants in a struct's implementation, those constants appear under the Methods section. Here's a minimal example:

struct Struc;

impl Struc {
    const S: u64 = 0;
}

$ cargo doc

For traits though, they appear under Associated Constants:

trait Tr {
    const S: u64 = 0;
}

There should also be an Associated Constants section for struct documentation.

@melaquin melaquin added the C-bug Category: This is a bug. label Mar 27, 2020
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 27, 2020
@MattX
Copy link
Contributor

MattX commented Apr 2, 2020

I've looked into this a little bit. It looks like for structs, rustdoc is grouping methods / associated types / associated constants / etc. per impl block. I agree this makes the "Methods" heading name a bit misleading. For instance,

struct Struc;

impl Struc {
    const MY_CONST: u64 = 0;
}

impl Struc {
    const MY_OTHER_CONST: u64 = 0;
}

Will produce two subheadings under "Methods", both called "impl Struc", and each with its own constant documented.

So if we want to keep doing it this way, we can't just add a toplevel "Associated constants headers". (As you mention, it does work for traits, since they don't have several sub-blocks in this way). We could do one of several things:

  • Add smaller headings under impl headings to separate methods from other associated things. This might get a little crufty.
  • Just rename the "Methods" header to "Implementation blocks" or something like that.
  • Merge all the impl blocks that don't implement a trait (is there a name for these?) together in the doc, and place their combined elements under correct toplevel headings.

Thoughts or other solutions?

@melaquin
Copy link
Author

melaquin commented Apr 2, 2020

I think renaming Methods to something else will be fine because it is a bit misleading. If I need to, I could put constants and methods in separate implblocks or group relevant items together or something, and get to document each impl block separately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants