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


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

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:

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: (structs) (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:

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


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.


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

I hope that description is sufficient.


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.


I changed the title and added an example …