-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Trait implementation doesn't show in docs when implemented for pub type alias #40395
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
Comments
Here is an example, where 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);
}
} |
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 |
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 |
I think this is a duplicate of #32077. |
It does seem to be. I'll close in favor of that. |
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
#[derive(Default)]
a generic struct creates a documentation for the derived trait.Default
myself (e.g. for a particular typeT
) there is no documentation about that trait generated.@krdln
the problem exists only if you declare apub type
synonym and use that type synonym inimpl
.The text was updated successfully, but these errors were encountered: