2023-08-24 22:44:32 -05:00
|
|
|
// Regression test for <https://github.com/rust-lang/rust/issues/32077>.
|
|
|
|
|
2023-10-16 18:12:17 -05:00
|
|
|
// https://github.com/rust-lang/rust/issues/32077
|
2023-08-24 22:44:32 -05:00
|
|
|
#![crate_name = "foo"]
|
|
|
|
|
|
|
|
pub struct GenericStruct<T>(T);
|
|
|
|
|
|
|
|
impl<T> GenericStruct<T> {
|
|
|
|
pub fn on_gen(arg: T) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GenericStruct<u32> {
|
|
|
|
pub fn on_u32(arg: u32) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Foo {}
|
|
|
|
pub trait Bar {}
|
|
|
|
|
|
|
|
impl<T> Foo for GenericStruct<T> {}
|
|
|
|
impl Bar for GenericStruct<u32> {}
|
|
|
|
|
|
|
|
// @has 'foo/type.TypedefStruct.html'
|
2023-09-11 07:17:39 -05:00
|
|
|
// We check that "Aliased type" is also present as a title in the sidebar.
|
|
|
|
// @has - '//*[@class="sidebar-elems"]//h3/a[@href="#aliased-type"]' 'Aliased type'
|
2023-08-24 22:44:32 -05:00
|
|
|
// We check that we have the implementation of the type alias itself.
|
rustdoc-search: add impl disambiguator to duplicate assoc items
Helps with #90929
This changes the search results, specifically, when there's more than
one impl with an associated item with the same name. For example,
the search queries `simd<i8> -> simd<i8>` and `simd<i64> -> simd<i64>`
don't link to the same function, but most of the functions have the
same names.
This change should probably be FCP-ed, especially since it adds a new
anchor link format for `main.js` to handle, so that URLs like
`struct.Vec.html#impl-AsMut<[T]>-for-Vec<T,+A>/method.as_mut` redirect
to `struct.Vec.html#method.as_mut-2`. It's a strange design, but there
are a few reasons for it:
* I'd like to avoid making the HTML bigger. Obviously, fixing this bug
is going to add at least a little more data to the search index, but
adding more HTML penalises viewers for the benefit of searchers.
* Breaking `struct.Vec.html#method.len` would also be a disappointment.
On the other hand:
* The path-style anchors might be less prone to link rot than the numbered
anchors. It's definitely less likely to have URLs that appear to "work",
but silently point at the wrong thing.
* This commit arranges the path-style anchor to redirect to the numbered
anchor. Nothing stops rustdoc from doing the opposite, making path-style
anchors the default and redirecting the "legacy" numbered ones.
2023-03-20 18:02:51 -05:00
|
|
|
// @has - '//*[@id="impl-GenericStruct%3Cu8%3E"]/h3' 'impl TypedefStruct'
|
2023-08-24 22:44:32 -05:00
|
|
|
// @has - '//*[@id="method.on_alias"]/h4' 'pub fn on_alias()'
|
|
|
|
// @has - '//*[@id="impl-GenericStruct%3CT%3E"]/h3' 'impl<T> GenericStruct<T>'
|
|
|
|
// @has - '//*[@id="method.on_gen"]/h4' 'pub fn on_gen(arg: T)'
|
|
|
|
// @has - '//*[@id="impl-Foo-for-GenericStruct%3CT%3E"]/h3' 'impl<T> Foo for GenericStruct<T>'
|
|
|
|
// This trait implementation doesn't match the type alias parameters so shouldn't appear in docs.
|
|
|
|
// @!has - '//h3' 'impl Bar for GenericStruct<u32> {}'
|
|
|
|
// Same goes for the `Deref` impl.
|
|
|
|
// @!has - '//h2' 'Methods from Deref<Target = u32>'
|
2023-09-08 16:59:54 -05:00
|
|
|
// @count - '//nav[@class="sidebar"]//a' 'on_alias' 1
|
|
|
|
// @count - '//nav[@class="sidebar"]//a' 'on_gen' 1
|
|
|
|
// @count - '//nav[@class="sidebar"]//a' 'Foo' 1
|
|
|
|
// @!has - '//nav[@class="sidebar"]//a' 'Bar'
|
|
|
|
// @!has - '//nav[@class="sidebar"]//a' 'on_u32'
|
2023-08-24 22:44:32 -05:00
|
|
|
pub type TypedefStruct = GenericStruct<u8>;
|
|
|
|
|
|
|
|
impl TypedefStruct {
|
|
|
|
pub fn on_alias() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::Deref for GenericStruct<u32> {
|
|
|
|
type Target = u32;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Wrap<T>(GenericStruct<T>);
|
|
|
|
|
|
|
|
// @has 'foo/type.Alias.html'
|
|
|
|
// @has - '//h2' 'Methods from Deref<Target = u32>'
|
|
|
|
// @has - '//*[@id="impl-Deref-for-Wrap%3CT%3E"]/h3' 'impl<T> Deref for Wrap<T>'
|
|
|
|
pub type Alias = Wrap<u32>;
|
|
|
|
|
|
|
|
impl<T> std::ops::Deref for Wrap<T> {
|
|
|
|
type Target = GenericStruct<T>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|