# Generics, partial 'impl Default' (for some types), and resulting docs

**URL:** <https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850>\
**Category:** help\
**Created:** [March 9, 2017, 4:02pm UTC](https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850 "2017-03-09T16:02:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/wahn/32/1050_2.png) [@wahn](https://users.rust-lang.org/u/wahn)\
**Post date:** [March 9, 2017, 4:02pm UTC](https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850/1 "2017-03-09T16:02:05Z")

</div>

I have a question about the documentation created via `cargo doc` for a **generic struct** like this:

```rust
#[derive(Debug,Copy,Clone)]
pub struct Bounds3<T> {
    pub p_min: Point3<T>,
    pub p_max: Point3<T>,
}

```

I first derived the `Default` trait via `#[derive(Default]` but later removed `Default` from that list and implemented it only for one particular type of the more generic `T` type:

```rust
pub type Float = f64;
pub type Bounds3f = Bounds3<Float>;
...
impl Default for Bounds3f {
    fn default() -> Bounds3f {
        let min_num: Float = std::f64::MIN;
        let max_num: Float = std::f64::MAX;
        Bounds3f {
            p_min: Point3f {
                x: max_num,
                y: max_num,
                z: max_num,
            }, p_max: Point3f {
                x: min_num,
                y: min_num,
                z: min_num,
            },
        }
    }
}

```

Here is the resulting documentation:

[pbrt - Rust](https://www.janwalter.org/doc/rust/pbrt/index.html#structs) (structs)  
[https://www.janwalter.org/doc/rust/pbrt/struct.Bounds3.html](https://www.janwalter.org/doc/rust/pbrt/struct.Bounds3.html) (generic Bounds3)

What I can't find is where the documentation for `fn default() -> Bounds3f` would go. If I derive the trait it is there:

[https://www.janwalter.org/doc/rust/pbrt/struct.Bounds2.html](https://www.janwalter.org/doc/rust/pbrt/struct.Bounds2.html)

Is this a **bug** in the documentation system, or is my expectation (to find such a function being documented) wrong?

---

<div class="post-metadata">

**Author:** ![krdln](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/krdln/32/16764_2.png) [@krdln](https://users.rust-lang.org/u/krdln)\
**Post date:** [March 9, 2017, 4:26pm UTC](https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850/2 "2017-03-09T16:26:04Z")

</div>

It's definitely a bug, go ahead and file it! What's interesting is that the problem exists only if you declare a `pub type` synonym **and** use that type synonym in impl. If you eg. remove `pub` or use full struct name inside the impl, the `Default` impl is visible in docs. This applies to the outermost type. So it's fine to use type synonym inside: `impl for Bound3<Float>`, but not `for Bounds3f`.

---

<div class="post-metadata">

**Author:** ![wahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/wahn/32/1050_2.png) [@wahn](https://users.rust-lang.org/u/wahn)\
**Post date:** [March 9, 2017, 4:55pm UTC](https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850/3 "2017-03-09T16:55:27Z")

</div>

@krdln Thanks. It's the first time I report a bug, but here it is:

[https://github.com/rust-lang/rust/issues/40395](https://github.com/rust-lang/rust/issues/40395)

I hope that description is sufficient.

---

<div class="post-metadata">

**Author:** ![krdln](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/krdln/32/16764_2.png) [@krdln](https://users.rust-lang.org/u/krdln)\
**Post date:** [March 9, 2017, 5:01pm UTC](https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850/4 "2017-03-09T17:01:11Z")

</div>

I think that more appropriate title would be "Trait implementation doesn't show in docs when implemented for pub type alias". (I think) the issue is not connected to the particular trait (here `Default`, but could be any other) or to the fact that it's derived. I think it's also worth to paste a code snippet directly in the issue in addition to linking to the thread. You can try to mimize it by eg. maxing the struct just 1 field and the trait implementation simple.

---

<div class="post-metadata">

**Author:** ![wahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/wahn/32/1050_2.png) [@wahn](https://users.rust-lang.org/u/wahn)\
**Post date:** [March 9, 2017, 5:42pm UTC](https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850/5 "2017-03-09T17:42:28Z")

</div>

> [@krdln](#):
>
> Trait implementation doesn't show in docs when implemented for pub type alias

I changed the title and added an example ...

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:43am UTC](https://users.rust-lang.org/t/generics-partial-impl-default-for-some-types-and-resulting-docs/9850/6 "2023-01-12T08:43:11Z")

</div>

Closed on January 12, 2023, 8:43am UTC


