rustdoc: types used in exported type definitions are not documented.

0610fe8
Opened by Sean Olson at 2024-11-15 23:32:43

When I generate docs via cargo doc, types used in type definitions are not documented. This is a problem when a module exports a type definition but not the types on which it is based, because even though the type definition is documented, it is entirely opaque.

For example:

pub mod foo {
    mod bar {
        pub struct Foo<T> { ... }
        impl<T> Foo<T> { ... }
    }
    pub type Foo = bar::Foo<i32>;
}

None of the methods on foo::bar::Foo<T> will be documented, and the documentation for foo::Foo will be nothing more than its type definition (and any documentation on the type definition itself).

I've tried removing the skip-private pass using the following command, and that still does not document the types used in the type definitions:

cargo rustdoc -- --passes=strip-hidden --passes=collapse-docs --passes=unindent-comments

Is this the expected behavior? Is there some way to document these types without exporting them?

  1. There is a related problem as well (please let me know if I should open a separate issue). impls for type definitions as described above are also not documented even though the type is exported.

    pub mod foo {
        mod bar { ... }
        pub type Foo = bar::Foo<i32>;
        impl Foo {
            pub fn baz() { ... }
        }
    }
    

    The baz method is not documented on the page for the foo::Foo type. The baz method can be found with a search query, but the link directs to the page for the foo::Foo type, where no documentation for baz is shown.

    Sean Olson at 2017-02-01 22:21:33

  2. I think this has the same cause as https://github.com/rust-lang/rust/issues/60686 - rustdoc should find somewhere to put the docs for reachable public items that are in private modules.

    jyn at 2021-04-08 18:24:02