Skip to content

rustdoc ignores inherent impls made in non-module scope #53763

Description

@QuietMisdreavus

Similar to #52545, rustdoc doesn't see anything if it's not written into a module's scope. However, there are some things that can be written in function/expression scope that still make it out into the public API. While that issue was about trait impls, it seems that inherent impls work in a similar way. Consider the following snippet:

fn asdf() {
    impl SomeStruct {
        pub fn qwop(&self) {
            println!("hidden function");
        }
    }
}

fn main() {
    let asdf = SomeStruct;
    asdf.qwop(); // prints "hidden function"
}

Even though qwop() was written in function scope, it's still visible globally because it was defined with pub. Rustdoc should collect these impls and display them.

One thing i'm curious about is whether we should show non-pub functions defined in non-module scope when --document-private-items is set. I think we can get away with it, because it already displays private functions there regardless of where they're defined.

Activity

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.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.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

      No branches or pull requests

      Issue actions