|
| 1 | +// Regression test for <https://github.com/rust-lang/rust/issues/32077>. |
| 2 | + |
| 3 | +#![crate_name = "foo"] |
| 4 | + |
| 5 | +pub struct GenericStruct<T>(T); |
| 6 | + |
| 7 | +impl<T> GenericStruct<T> { |
| 8 | + pub fn on_gen(arg: T) {} |
| 9 | +} |
| 10 | + |
| 11 | +impl GenericStruct<u32> { |
| 12 | + pub fn on_u32(arg: u32) {} |
| 13 | +} |
| 14 | + |
| 15 | +pub trait Foo {} |
| 16 | +pub trait Bar {} |
| 17 | + |
| 18 | +impl<T> Foo for GenericStruct<T> {} |
| 19 | +impl Bar for GenericStruct<u32> {} |
| 20 | + |
| 21 | +// @has 'foo/type.TypedefStruct.html' |
| 22 | +// We check that we have the implementation of the type alias itself. |
| 23 | +// @has - '//*[@id="impl-TypedefStruct"]/h3' 'impl TypedefStruct' |
| 24 | +// @has - '//*[@id="method.on_alias"]/h4' 'pub fn on_alias()' |
| 25 | +// @has - '//*[@id="impl-GenericStruct%3CT%3E"]/h3' 'impl<T> GenericStruct<T>' |
| 26 | +// @has - '//*[@id="method.on_gen"]/h4' 'pub fn on_gen(arg: T)' |
| 27 | +// @has - '//*[@id="impl-Foo-for-GenericStruct%3CT%3E"]/h3' 'impl<T> Foo for GenericStruct<T>' |
| 28 | +// This trait implementation doesn't match the type alias parameters so shouldn't appear in docs. |
| 29 | +// @!has - '//h3' 'impl Bar for GenericStruct<u32> {}' |
| 30 | +// Same goes for the `Deref` impl. |
| 31 | +// @!has - '//h2' 'Methods from Deref<Target = u32>' |
| 32 | +pub type TypedefStruct = GenericStruct<u8>; |
| 33 | + |
| 34 | +impl TypedefStruct { |
| 35 | + pub fn on_alias() {} |
| 36 | +} |
| 37 | + |
| 38 | +impl std::ops::Deref for GenericStruct<u32> { |
| 39 | + type Target = u32; |
| 40 | + |
| 41 | + fn deref(&self) -> &Self::Target { |
| 42 | + &self.0 |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +pub struct Wrap<T>(GenericStruct<T>); |
| 47 | + |
| 48 | +// @has 'foo/type.Alias.html' |
| 49 | +// @has - '//h2' 'Methods from Deref<Target = u32>' |
| 50 | +// @has - '//*[@id="impl-Deref-for-Wrap%3CT%3E"]/h3' 'impl<T> Deref for Wrap<T>' |
| 51 | +pub type Alias = Wrap<u32>; |
| 52 | + |
| 53 | +impl<T> std::ops::Deref for Wrap<T> { |
| 54 | + type Target = GenericStruct<T>; |
| 55 | + |
| 56 | + fn deref(&self) -> &Self::Target { |
| 57 | + &self.0 |
| 58 | + } |
| 59 | +} |
0 commit comments