Skip to content

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

Closed
@melaquin

Description

@melaquin

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.

Activity

added
A-associated-itemsArea: Associated items (types, constants & functions)
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Mar 27, 2020
MattX

MattX commented on Apr 2, 2020

@MattX
Contributor

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

melaquin commented on Apr 2, 2020

@melaquin
Author

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

added a commit that references this issue on May 6, 2020

Rollup merge of rust-lang#71918 - GuillaumeGomez:rename-methods-secti…

d33180e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @MattX@jonas-schievink@melaquin

      Issue actions

        Rustdoc shouldn't document a struct's associated constants as methods · Issue #70475 · rust-lang/rust