rust/tests/rustdoc-js-std/option-type-signatures.js
Michael Howell 12dc24f460 rustdoc-search: simplify rules for generics and type params
This commit is a response to feedback on the displayed type
signatures results, by making generics act stricter.

Generics are tightened by making order significant. This means
`Vec<Allocator>` now matches only with a true vector of allocators,
instead of matching the second type param. It also makes unboxing
within generics stricter, so `Result<A, B>` only matches if `B`
is in the error type and `A` is in the success type. The top level
of the function search is unaffected.

Find the discussion on:

* <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149>
* <https://github.com/rust-lang/rust/pull/124544#issuecomment-2204272265>
* <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search/near/476841363>
2024-10-30 12:27:48 -07:00

204 lines
6.1 KiB
JavaScript

// ignore-order
const FILTER_CRATE = "std";
const EXPECTED = [
{
'query': 'option, fnonce -> option',
'others': [
{
'path': 'std::option::Option',
'name': 'map',
'displayType': '`Option`<T>, F -> `Option`<U>',
'displayWhereClause': "F: `FnOnce` (T) -> U",
},
],
},
{
'query': 'option<t>, fnonce -> option',
'others': [
{
'path': 'std::option::Option',
'name': 'map',
'displayType': '`Option`<`T`>, F -> `Option`<U>',
'displayWhereClause': "F: `FnOnce` (T) -> U",
},
],
},
{
'query': 'option -> default',
'others': [
{
'path': 'std::option::Option',
'name': 'unwrap_or_default',
'displayType': '`Option`<T> -> `T`',
'displayWhereClause': "T: `Default`",
},
{
'path': 'std::option::Option',
'name': 'get_or_insert_default',
'displayType': '&mut `Option`<T> -> &mut `T`',
'displayWhereClause': "T: `Default`",
},
],
},
{
'query': 'option -> []',
'others': [
{
'path': 'std::option::Option',
'name': 'as_slice',
'displayType': '&`Option`<T> -> &`[`T`]`',
},
{
'path': 'std::option::Option',
'name': 'as_mut_slice',
'displayType': '&mut `Option`<T> -> &mut `[`T`]`',
},
],
},
{
'query': 'option<t>, option<t> -> option<t>',
'others': [
{
'path': 'std::option::Option',
'name': 'or',
'displayType': '`Option`<`T`>, `Option`<`T`> -> `Option`<`T`>',
},
{
'path': 'std::option::Option',
'name': 'xor',
'displayType': '`Option`<`T`>, `Option`<`T`> -> `Option`<`T`>',
},
],
},
{
'query': 'option<t>, option<u> -> option<u>',
'others': [
{
'path': 'std::option::Option',
'name': 'and',
'displayType': '`Option`<`T`>, `Option`<`U`> -> `Option`<`U`>',
},
],
},
{
'query': 'option<t>, option<u> -> option<t>',
'others': [
{
'path': 'std::option::Option',
'name': 'and',
'displayType': '`Option`<`T`>, `Option`<`U`> -> `Option`<`U`>',
},
{
'path': 'std::option::Option',
'name': 'zip',
'displayType': '`Option`<`T`>, `Option`<`U`> -> `Option`<(`T`, U)>',
},
],
},
{
'query': 'option<t>, option<u> -> option<(t, u)>',
'others': [
{
'path': 'std::option::Option',
'name': 'zip',
'displayType': '`Option`<`T`>, `Option`<`U`> -> `Option`<`(T`, `U)`>',
},
],
},
{
'query': 'option<t>, e -> result<t, e>',
'others': [
{
'path': 'std::option::Option',
'name': 'ok_or',
'displayType': '`Option`<`T`>, `E` -> `Result`<`T`, `E`>',
},
{
'path': 'std::result::Result',
'name': 'transpose',
'displayType': 'Result<`Option`<`T`>, `E`> -> Option<`Result`<`T`, `E`>>',
},
],
},
{
'query': 'result<option<t>, e> -> option<result<t, e>>',
'others': [
{
'path': 'std::result::Result',
'name': 'transpose',
'displayType': '`Result`<`Option`<`T`>, `E`> -> `Option`<`Result`<`T`, `E`>>',
},
],
},
{
'query': 'option<t>, option<t> -> bool',
'others': [
{
'path': 'std::option::Option',
'name': 'eq',
'displayType': '&`Option`<`T`>, &`Option`<`T`> -> `bool`',
},
],
},
{
'query': 'option<option<t>> -> option<t>',
'others': [
{
'path': 'std::option::Option',
'name': 'flatten',
'displayType': '`Option`<`Option`<`T`>> -> `Option`<`T`>',
},
],
},
{
'query': 'option<t>',
'returned': [
{
'path': 'std::result::Result',
'name': 'ok',
'displayType': 'Result<T, E> -> `Option`<`T`>',
},
],
},
{
'query': 'option<t>, (fnonce () -> u) -> option',
'others': [
{
'path': 'std::option::Option',
'name': 'map',
'displayType': '`Option`<`T`>, F -> `Option`<U>',
'displayMappedNames': `t = T, u = U`,
'displayWhereClause': "F: `FnOnce` (T) -> `U`",
},
{
'path': 'std::option::Option',
'name': 'and_then',
'displayType': '`Option`<`T`>, F -> `Option`<U>',
'displayMappedNames': `t = T, u = U`,
'displayWhereClause': "F: `FnOnce` (T) -> Option<`U`>",
},
{
'path': 'std::option::Option',
'name': 'zip_with',
'displayType': 'Option<T>, `Option`<`U`>, F -> `Option`<R>',
'displayMappedNames': `t = U, u = R`,
'displayWhereClause': "F: `FnOnce` (T, U) -> `R`",
},
],
},
{
'query': 'option<t>, (fnonce () -> option<u>) -> option',
'others': [
{
'path': 'std::option::Option',
'name': 'and_then',
'displayType': '`Option`<`T`>, F -> `Option`<U>',
'displayMappedNames': `t = T, u = U`,
'displayWhereClause': "F: `FnOnce` (T) -> `Option`<`U`>",
},
],
},
];