Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc does not document Deref impls more than one level deep #53038

Closed
QuietMisdreavus opened this issue Aug 3, 2018 · 3 comments · Fixed by #80653
Closed

rustdoc does not document Deref impls more than one level deep #53038

QuietMisdreavus opened this issue Aug 3, 2018 · 3 comments · Fixed by #80653
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@QuietMisdreavus
Copy link
Member

use std::ops::Deref;

pub struct Base;

impl Base {
    pub fn asdf(&self) {}
}

pub struct LevelOne {
    pub base: Base,
}

impl Deref for LevelOne {
    type Target = Base;

    fn deref(&self) -> &Base {
        &self.base
    }
}

impl LevelOne {
    pub fn qwop(&self) {}
}

pub struct LevelTwo {
    pub base: LevelOne,
}

impl Deref for LevelTwo {
    type Target = LevelOne;

    fn deref(&self) -> &LevelOne {
        &self.base
    }
}

impl LevelTwo {
    pub fn custom() {}
}

In this example, LevelTwo derefs to LevelOne, which derefs to Base. However in the docs, only the methods from LevelOne are shown. We should recursively look for Deref impls on items we're collecting impls for via Deref.

@QuietMisdreavus QuietMisdreavus added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Aug 3, 2018
@aldanor
Copy link

aldanor commented Nov 19, 2018

Just ran into this as well - a bit annoying, especially if Deref is used aggressively through the codebase, e.g. if there are multiple newtype layers like in the example above (which wouldn't be so uncommon). Are there any plans for this to be fixed?

@aldanor
Copy link

aldanor commented Nov 19, 2018

Ok, apparently there's #26207 which has been open for over 3 years with no changes...

@jyn514
Copy link
Member

jyn514 commented Jan 3, 2021

Duplicate of #26207

@jyn514 jyn514 marked this as a duplicate of #26207 Jan 3, 2021
@jyn514 jyn514 closed this as completed Jan 3, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 8, 2021
…GuillaumeGomez

Recursively document methods via `Deref` traits

This changes `rustdoc` to recursively follow `Deref` targets so that methods from all levels are added to the rendered output. This implementation displays the methods from all levels in the expanded state with separate sections for each level.

![image](https://user-images.githubusercontent.com/279572/103482863-46723b00-4ddb-11eb-972b-c463351a425c.png)

Fixes rust-lang#26207
Fixes rust-lang#53038
Fixes rust-lang#71640

r? `@jyn514`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants