Skip to content
New issue

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

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

Already on GitHub? # to your account

Trait implementation doesn't show in docs when implemented for pub type alias #40395

Closed
wahn opened this issue Mar 9, 2017 · 5 comments
Closed
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@wahn
Copy link

wahn commented Mar 9, 2017

I was told that what I described in a post on the forum is a bug, so let me simply link to that post, which contains a description of the bug:

https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850

  1. Basically, what I discovered was, that if I use #[derive(Default)] a generic struct creates a documentation for the derived trait.
  2. If I only partially implement Default myself (e.g. for a particular type T) there is no documentation about that trait generated.
  3. My expectation was that such a documentation would be generated.
  4. As mentioned by @krdln the problem exists only if you declare a pub type synonym and use that type synonym in impl.
@wahn wahn changed the title Generics, partial ‘impl Default’ (for some types), and resulting docs help Trait implementation doesn't show in docs when implemented for pub type alias Mar 9, 2017
@wahn
Copy link
Author

wahn commented Mar 9, 2017

Here is an example, where type Point4f shows default() in the resulting docs, whereas pub type Point3f does not:

pub type Float = f64;
pub type Point2f = Point2<Float>;
pub type Point3f = Point3<Float>;
type Point4f = Point4<Float>;

#[derive(Default)]
pub struct Point2<T> {
    pub x: T,
    pub y: T,
}

// do *not* derive Default                                                                                                    
pub struct Point3<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}

impl Default for Point3f {
    /// will *not* show up in docs                                                                                            
    fn default() -> Point3f {
        Point3f {
            x: 0.0,
            y: 1.0,
            z: 2.0,
        }
    }
}

// do *not* derive Default                                                                                                    
pub struct Point4<T> {
    pub x: T,
    pub y: T,
    pub z: T,
    pub w: T,
}

impl Default for Point4f {
    /// will show up in docs                                                                                                  
    fn default() -> Point4f {
        Point4f {
            x: 0.0,
            y: 1.0,
            z: 2.0,
            w: 1.0,
	}
    }
}

#[cfg(test)]
mod tests {
    use super::{Point2f, Point3f, Point4f};
    #[test]
    fn p2_works() {
        let p2: Point2f = Point2f::default();
        assert_eq!(p2.x, 0.0);
        assert_eq!(p2.y, 0.0);
    }
    #[test]
    fn p3_works() {
        let p3: Point3f = Point3f::default();
	assert_eq!(p3.x, 0.0);
        assert_eq!(p3.y, 1.0);
        assert_eq!(p3.z, 2.0);
    }
    #[test]
    fn p4_works() {
        let p4: Point4f = Point4f::default();
        assert_eq!(p4.x, 0.0);
        assert_eq!(p4.y, 1.0);
        assert_eq!(p4.z, 2.0);
        assert_eq!(p4.w, 1.0);
    }
}

@durka
Copy link
Contributor

durka commented Mar 9, 2017

Smaller reproduction:

pub trait Foo {}

pub struct Baz;
pub struct Quux;
pub type Thud = Quux;

impl Foo for Baz {}
impl Foo for Thud {}

The generated docs for Baz show the Foo impl, but it is not shown in the docs for either Quux or Thud. However, both implementations are shown on the Foo page (listed as impls for Baz and Thud).

@steveklabnik steveklabnik added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-tools and removed T-tools labels Mar 9, 2017
@Hoverbear
Copy link
Contributor

Hoverbear commented Apr 18, 2017

I was able to reproduce this with the following code:

#[derive(Default)]
pub struct Foo;

pub type AliasedFoo = Foo;

pub trait Bar {
    fn yep(&self) {}
}

impl Bar for Foo {}

pub trait Baz {
    fn nope(&self) {}
}

impl Baz for AliasedFoo {}

#[cfg(test)]
mod tests {
    use {Foo, AliasedFoo, Bar, Baz};
    #[test]
    fn it_works() {
        Foo::default().yep();
        Foo::default().nope();
        AliasedFoo::default().yep();
        AliasedFoo::default().nope();
    }
}

Test passes but Baz is not shown to be implemented for either Foo or AliasedFoo.

screen shot 2017-04-18 at 11 20 58

screen shot 2017-04-18 at 11 21 04

wahn added a commit to wahn/rs_pbrt that referenced this issue May 11, 2017
@mjkillough
Copy link
Contributor

I think this is a duplicate of #32077.

@Mark-Simulacrum
Copy link
Member

It does seem to be. I'll close in favor of that.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants