1
Fork 0

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>
This commit is contained in:
Michael Howell 2024-09-24 18:18:01 -07:00
parent 20a4b4fea1
commit 12dc24f460
40 changed files with 630 additions and 217 deletions

View file

@ -2,12 +2,15 @@
const EXPECTED = [
{
'query': 'bufread -> result<u8>',
'query': 'bufread -> result<[u8]>',
'others': [
{ 'path': 'std::boxed::Box', 'name': 'fill_buf' },
],
},
{
'query': 'split<bufread> -> option<result<vec<u8>>>',
'others': [
{ 'path': 'std::io::Split', 'name': 'next' },
{ 'path': 'std::boxed::Box', 'name': 'fill_buf' },
{ 'path': 'std::io::Chain', 'name': 'fill_buf' },
{ 'path': 'std::io::Take', 'name': 'fill_buf' },
],
},
];

View file

@ -80,11 +80,6 @@ const EXPECTED = [
'name': 'and',
'displayType': '`Option`<`T`>, `Option`<`U`> -> `Option`<`U`>',
},
{
'path': 'std::option::Option',
'name': 'zip',
'displayType': '`Option`<`T`>, `Option`<`U`> -> `Option`<(T, `U`)>',
},
],
},
{
@ -103,12 +98,12 @@ const EXPECTED = [
],
},
{
'query': '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`)>',
'displayType': '`Option`<`T`>, `Option`<`U`> -> `Option`<`(T`, `U)`>',
},
],
},
@ -174,37 +169,23 @@ const EXPECTED = [
'path': 'std::option::Option',
'name': 'map',
'displayType': '`Option`<`T`>, F -> `Option`<U>',
'displayMappedNames': `T = t, U = 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`,
'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': `U = t, R = u`,
'displayMappedNames': `t = U, u = R`,
'displayWhereClause': "F: `FnOnce` (T, U) -> `R`",
},
{
'path': 'std::task::Poll',
'name': 'map_ok',
'displayType': 'Poll<`Option`<Result<`T`, E>>>, F -> Poll<`Option`<Result<U, E>>>',
'displayMappedNames': `T = t, U = u`,
'displayWhereClause': "F: `FnOnce` (T) -> `U`",
},
{
'path': 'std::task::Poll',
'name': 'map_err',
'displayType': 'Poll<`Option`<Result<`T`, E>>>, F -> Poll<`Option`<Result<T, U>>>',
'displayMappedNames': `T = t, U = u`,
'displayWhereClause': "F: `FnOnce` (E) -> `U`",
},
],
},
{
@ -214,7 +195,7 @@ const EXPECTED = [
'path': 'std::option::Option',
'name': 'and_then',
'displayType': '`Option`<`T`>, F -> `Option`<U>',
'displayMappedNames': `T = t, U = u`,
'displayMappedNames': `t = T, u = U`,
'displayWhereClause': "F: `FnOnce` (T) -> `Option`<`U`>",
},
],

View file

@ -19,4 +19,16 @@ const EXPECTED = [
{ 'path': 'std::vec::IntoIter', 'name': 'next_chunk' },
],
},
{
'query': 'vec<T, Allocator> -> Box<[T]>',
'others': [
{
'path': 'std::boxed::Box',
'name': 'from',
'displayType': '`Vec`<`T`, `A`> -> `Box`<`[T]`, A>',
'displayMappedNames': `T = T`,
'displayWhereClause': 'A: `Allocator`',
},
],
},
];