rust/tests/rustdoc-js
Guillaume Gomez 4be9cfabf2
Rollup merge of #109422 - notriddle:notriddle/impl-disambiguate-search, r=GuillaumeGomez
rustdoc-search: add impl disambiguator to duplicate assoc items

Preview (to see the difference, click the link and pay attention to the specific function that comes up):

| Before | After |
|--|--|
| [`simd<i64>, simd<i64> -> simd<i64>`](https://doc.rust-lang.org/nightly/std/?search=simd%3Ci64%3E%2C%20simd%3Ci64%3E%20-%3E%20simd%3Ci64%3E) | [`simd<i64>, simd<i64> -> simd<i64>`](https://notriddle.com/rustdoc-demo-html-3/impl-disambiguate-search/std/index.html?search=simd%3Ci64%3E%2C%20simd%3Ci64%3E%20-%3E%20simd%3Ci64%3E) |
| [`cow, vec -> bool`](https://doc.rust-lang.org/nightly/std/?search=cow%2C%20vec%20-%3E%20bool) | [`cow, vec -> bool`](https://notriddle.com/rustdoc-demo-html-3/impl-disambiguate-search/std/index.html?search=cow%2C%20vec%20-%3E%20bool)

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.

### The bug

On the "Before" links, this example search calls for `i64`:

![image](https://github.com/rust-lang/rust/assets/1593513/9431d89d-41dc-4f68-bbb1-3e2704a973d2)

But if I click any of the results, I get `f64` instead.

![image](https://github.com/rust-lang/rust/assets/1593513/6d89c692-1847-421a-84d9-22e359d9cf82)

The PR fixes this problem by adding enough information to the search result `href` to disambiguate methods with different types but the same name.

More detailed description of the problem at:
https://github.com/rust-lang/rust/pull/109422#issuecomment-1491089293

> When a struct/enum/union has multiple impls with different type parameters, it can have multiple methods that have the same name, but which are on different impls. Besides Simd, [Any](https://doc.rust-lang.org/nightly/std/any/trait.Any.html?search=any%3A%3Adowncast) also demonstrates this pattern. It has three methods named `downcast`, on three different impls.
>
> When that happens, it presents a challenge in linking to the method. Normally we link like `#method.foo`. When there are multiple `foo`, we number them like `#method.foo`, `#method.foo-1`, `#method.foo-2`, etc.
>
> It also presents a challenge for our search code. Currently we store all the variants in the index, but don’t have any way to generate unambiguous URLs in the results page, or to distinguish them in the SERP.
>
> To fix this, we need three things:
>
> 1. A fragment format that fully specifies the impl type parameters when needed to disambiguate (`#impl-SimdOrd-for-Simd<i64,+LANES>/method.simd_max`)
> 2. A search index that stores methods with enough information to disambiguate the impl they were on.
> 3. A search results interface that can display multiple methods on the same type with the same name, when appropriate OR a disambiguation landing section on item pages?
>
> For reviewers: it can be hard to see the new fragment format in action since it immediately gets rewritten to the numbered form.
2023-10-10 18:44:43 +02:00
..
basic.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
basic.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
doc-alias-filter-out.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
doc-alias-filter-out.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
doc-alias-filter.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
doc-alias-filter.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
doc-alias-whitespace.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
doc-alias-whitespace.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
doc-alias.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
doc-alias.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
exact-match.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
exact-match.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreign-type-path.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
foreign-type-path.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
full-path-function.js Correctly handle paths from foreign items 2023-09-02 23:04:37 +02:00
full-path-function.rs Correctly handle paths from foreign items 2023-09-02 23:04:37 +02:00
generics-impl.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
generics-impl.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
generics-match-ambiguity.js rustdoc-search: fix bugs when unboxing and reordering combine 2023-09-09 16:58:37 -07:00
generics-match-ambiguity.rs rustdoc-search: fix order-independence bug 2023-06-11 18:57:33 -07:00
generics-multi-trait.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
generics-multi-trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
generics-nested.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
generics-nested.rs rustdoc-search: add support for nested generics 2023-04-14 14:55:45 -07:00
generics-trait.js rustdoc: fix test case for generics that look like names 2023-09-03 13:06:08 -07:00
generics-trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
generics-unbox.js rustdoc-search: fix bugs when unboxing and reordering combine 2023-09-09 16:58:37 -07:00
generics-unbox.rs rustdoc-search: fix bugs when unboxing and reordering combine 2023-09-09 16:58:37 -07:00
generics.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
generics.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
impl-trait.js rustdoc-search: fix bug with multi-item impl trait 2023-10-05 22:32:37 -07:00
impl-trait.rs rustdoc-search: fix bug with multi-item impl trait 2023-10-05 22:32:37 -07:00
macro-search.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
macro-search.rs rustdoc: search by macro when query ends with ! 2023-02-16 18:16:09 -07:00
module-substring.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
module-substring.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nested-unboxed.js rustdoc-search: build args, return, and generics on one unifier 2023-06-11 18:19:37 -07:00
nested-unboxed.rs rustdoc-search: build args, return, and generics on one unifier 2023-06-11 18:19:37 -07:00
never-search.js rustdoc-search: search never type with ! 2023-06-12 17:30:23 -07:00
never-search.rs rustdoc-search: search never type with ! 2023-06-12 17:30:23 -07:00
path-ordering.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
path-ordering.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
primitive.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
primitive.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
prototype.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
prototype.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
raw-pointer.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
raw-pointer.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
reexport.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
reexport.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
search-bag-semantics.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
search-bag-semantics.rs rustdoc: implement bag semantics for function parameter search 2023-03-19 18:19:24 -07:00
search-method-disambiguate.js rustdoc-search: add impl disambiguator to duplicate assoc items 2023-09-21 15:16:44 -07:00
search-method-disambiguate.rs rustdoc-search: add impl disambiguator to duplicate assoc items 2023-09-21 15:16:44 -07:00
search-short-types.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
search-short-types.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
slice-array.js rustdoc: add note about slice/array searches to help popup 2023-06-10 14:08:26 -07:00
slice-array.rs rustdoc: search for slices and arrays by type with [] 2023-06-10 13:52:54 -07:00
struct-like-variant.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
struct-like-variant.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
substring.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
substring.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
summaries.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
summaries.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
type-parameters.js rustdoc-search: add support for type parameters 2023-09-03 13:06:06 -07:00
type-parameters.rs rustdoc-search: add support for type parameters 2023-09-03 13:06:06 -07:00
where-clause.js Update rustdoc-js* format 2023-06-09 17:00:47 +02:00
where-clause.rs rustdoc: fix type search when more than one where clause applies 2023-03-07 11:37:04 -07:00