Skip to content

rustdoc: Methods on type aliases are not documented if the target type is not publicly reachable #119015

Closed
@sgued

Description

@sgued

I tried this code:

mod foo {
    pub struct S;
}

use foo::S;

pub type A = S;

impl Default for A {
    fn default() -> Self {
        S
    }
}

impl A {
    pub fn a(&self) {}
}

I expected the documentation for the type alias A to show the method fn a(&self) and the implementation of Default.

Instead, the type alias does not show the method fn a(&self). It does however show the implementation of Default.

image

Workarounds

By publicly exposing foo::S through pub use foo::S, the documentation of fn a(&self) on the alias is documented as I expected, but then foo:S is publicly reachable, which in my case is unwanted due to being an internal implementation detail.

This also works when making the use statement #[doc(hidden)], which gets the docs to look like I expected them to.

mod foo {
    pub struct S;
}

#[doc(hidden)]
pub use foo::S;

pub type A = S;

impl Default for A {
    fn default() -> Self {
        S
    }
}

impl A {
    pub fn a(&self) {}
}

image

Meta

rustc --version --verbose:

cargo 1.74.1 (ecb9851af 2023-10-18)
release: 1.74.1
commit-hash: ecb9851afd3095e988daaa35a48bc7f3cb748e04
commit-date: 2023-10-18
host: x86_64-unknown-linux-gnu
libgit2: 1.7.1 (sys:0.18.0 vendored)
libcurl: 8.4.0-DEV (sys:0.4.68+curl-8.4.0 vendored ssl:OpenSSL/1.1.1u)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Arch Linux [64-bit]

Thanks @GuillaumeGomez for helping me figure out why what I was expecting wasn't happening though it looked like it should.

Metadata

Metadata

Labels

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

No branches or pull requests

Issue actions