Skip to content

cargo doc does not show impls inside of a const item #109320

@nicholasbishop

Description

@nicholasbishop
Contributor

I noticed in the new bitflags v2 release that the flags are no longer showing up cargo doc output. I filed a bug in the bitflags project for that, but it seems like potentially incorrect behavior on the part of cargo doc as well. Example code:

pub struct S;

trait T {}

const _: () = {
    impl S {
        // Does not show in docs.
        pub const VAL: u32 = 0;

        // Does not show in docs.
        const fn f() {}
    }

    // Does not show in docs.
    impl T for S {}
};

// Demonstrate that S::VAL and S::f are accessible.
pub const C1: u32 = S::VAL;
pub const C2: () = S::f();
// Demonstrate that S impls T
pub fn x() {
    let _t: &dyn T = &S;
}

Since S::VAL and S::f are visible outside the empty const _: () item, I would expect them to show up in the cargo doc output, but they don't. Similar for the impl T for S.

This is not a regression as far as I can tell from checking a few versions of Rust at random.

Meta

rustc --version --verbose:

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6

Activity

GuillaumeGomez

GuillaumeGomez commented on Mar 19, 2023

@GuillaumeGomez
Member

It was fixed in #107000:

Screenshot from 2023-03-19 14-14-44

Since S::VAL and S::f are visible outside the empty const _: () item, I would expect them to show up in the cargo doc output, but they don't. Similar for the impl T for S.

S::f is private, same as T, so unless you use --document-private-items, they won't appear in the documentation since they're only public inside the current crate.

nicholasbishop

nicholasbishop commented on Mar 19, 2023

@nicholasbishop
ContributorAuthor

Thanks!

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

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nicholasbishop@GuillaumeGomez

        Issue actions

          cargo doc does not show impls inside of a const item · Issue #109320 · rust-lang/rust