Skip to content

Commit 314c39d

Browse files
committed
Auto merge of rust-lang#112233 - notriddle:notriddle/search-unify, r=GuillaumeGomez
rustdoc-search: clean up type unification and "unboxing" This PR redesigns parameter matching, return matching, and generics matching to use a single function that compares two lists of types. It also makes the algorithms more consistent, so the "unboxing" behavior where `Vec<i32>` is considered a match for `i32` works inside generics, and not just at the top level.
2 parents 6ee4265 + 94badbe commit 314c39d

File tree

7 files changed

+357
-166
lines changed

7 files changed

+357
-166
lines changed

src/librustdoc/html/static/js/externs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let ParsedQuery;
5353
* parent: (Object|null|undefined),
5454
* path: string,
5555
* ty: (Number|null|number),
56-
* type: (Array<?>|null)
56+
* type: FunctionSearchType?
5757
* }}
5858
*/
5959
let Row;
@@ -135,7 +135,7 @@ let RawFunctionType;
135135
/**
136136
* @typedef {{
137137
* inputs: Array<FunctionType>,
138-
* outputs: Array<FunctionType>,
138+
* output: Array<FunctionType>,
139139
* }}
140140
*/
141141
let FunctionSearchType;

src/librustdoc/html/static/js/search.js

+161-164
Large diffs are not rendered by default.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ignore-order
2+
3+
const EXPECTED = [
4+
{
5+
'query': 'bufread -> result<u8>',
6+
'others': [
7+
{ 'path': 'std::io::Split', 'name': 'next' },
8+
{ 'path': 'std::boxed::Box', 'name': 'fill_buf' },
9+
{ 'path': 'std::io::Chain', 'name': 'fill_buf' },
10+
{ 'path': 'std::io::Take', 'name': 'fill_buf' },
11+
],
12+
},
13+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// ignore-order
2+
// exact-check
3+
4+
// Make sure that results are order-agnostic, even when there's search items that only differ
5+
// by generics.
6+
7+
const EXPECTED = [
8+
{
9+
'query': 'Wrap',
10+
'in_args': [
11+
{ 'path': 'generics_match_ambiguity', 'name': 'bar' },
12+
{ 'path': 'generics_match_ambiguity', 'name': 'foo' },
13+
],
14+
},
15+
{
16+
'query': 'Wrap<i32>',
17+
'in_args': [
18+
{ 'path': 'generics_match_ambiguity', 'name': 'bar' },
19+
{ 'path': 'generics_match_ambiguity', 'name': 'foo' },
20+
],
21+
},
22+
{
23+
'query': 'Wrap<i32>, Wrap<i32, u32>',
24+
'others': [
25+
{ 'path': 'generics_match_ambiguity', 'name': 'bar' },
26+
{ 'path': 'generics_match_ambiguity', 'name': 'foo' },
27+
],
28+
},
29+
{
30+
'query': 'Wrap<i32, u32>, Wrap<i32>',
31+
'others': [
32+
{ 'path': 'generics_match_ambiguity', 'name': 'bar' },
33+
{ 'path': 'generics_match_ambiguity', 'name': 'foo' },
34+
],
35+
},
36+
{
37+
'query': 'W3<i32>, W3<i32, u32>',
38+
'others': [
39+
{ 'path': 'generics_match_ambiguity', 'name': 'baaa' },
40+
{ 'path': 'generics_match_ambiguity', 'name': 'baab' },
41+
{ 'path': 'generics_match_ambiguity', 'name': 'baac' },
42+
{ 'path': 'generics_match_ambiguity', 'name': 'baad' },
43+
{ 'path': 'generics_match_ambiguity', 'name': 'baae' },
44+
{ 'path': 'generics_match_ambiguity', 'name': 'baaf' },
45+
{ 'path': 'generics_match_ambiguity', 'name': 'baag' },
46+
{ 'path': 'generics_match_ambiguity', 'name': 'baah' },
47+
],
48+
},
49+
{
50+
'query': 'W3<i32, u32>, W3<i32>',
51+
'others': [
52+
{ 'path': 'generics_match_ambiguity', 'name': 'baaa' },
53+
{ 'path': 'generics_match_ambiguity', 'name': 'baab' },
54+
{ 'path': 'generics_match_ambiguity', 'name': 'baac' },
55+
{ 'path': 'generics_match_ambiguity', 'name': 'baad' },
56+
{ 'path': 'generics_match_ambiguity', 'name': 'baae' },
57+
{ 'path': 'generics_match_ambiguity', 'name': 'baaf' },
58+
{ 'path': 'generics_match_ambiguity', 'name': 'baag' },
59+
{ 'path': 'generics_match_ambiguity', 'name': 'baah' },
60+
],
61+
},
62+
{
63+
'query': 'W2<i32>, W2<i32, u32>',
64+
'others': [
65+
{ 'path': 'generics_match_ambiguity', 'name': 'baag' },
66+
{ 'path': 'generics_match_ambiguity', 'name': 'baah' },
67+
],
68+
},
69+
{
70+
'query': 'W2<i32, u32>, W2<i32>',
71+
'others': [
72+
{ 'path': 'generics_match_ambiguity', 'name': 'baag' },
73+
{ 'path': 'generics_match_ambiguity', 'name': 'baah' },
74+
],
75+
},
76+
{
77+
'query': 'W2<i32>, W3<i32, u32>',
78+
'others': [
79+
{ 'path': 'generics_match_ambiguity', 'name': 'baac' },
80+
{ 'path': 'generics_match_ambiguity', 'name': 'baaf' },
81+
{ 'path': 'generics_match_ambiguity', 'name': 'baag' },
82+
],
83+
},
84+
{
85+
'query': 'W2<i32>, W2<i32>',
86+
'others': [
87+
{ 'path': 'generics_match_ambiguity', 'name': 'baag' },
88+
{ 'path': 'generics_match_ambiguity', 'name': 'baah' },
89+
],
90+
},
91+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub struct Wrap<T, U = ()>(pub T, pub U);
2+
3+
pub fn foo(a: Wrap<i32>, b: Wrap<i32, u32>) {}
4+
pub fn bar(a: Wrap<i32, u32>, b: Wrap<i32>) {}
5+
6+
pub struct W2<T>(pub T);
7+
pub struct W3<T, U = ()>(pub T, pub U);
8+
9+
pub fn baaa(a: W3<i32>, b: W3<i32, u32>) {}
10+
pub fn baab(a: W3<i32, u32>, b: W3<i32>) {}
11+
pub fn baac(a: W2<W3<i32>>, b: W3<i32, u32>) {}
12+
pub fn baad(a: W2<W3<i32, u32>>, b: W3<i32>) {}
13+
pub fn baae(a: W3<i32>, b: W2<W3<i32, u32>>) {}
14+
pub fn baaf(a: W3<i32, u32>, b: W2<W3<i32>>) {}
15+
pub fn baag(a: W2<W3<i32>>, b: W2<W3<i32, u32>>) {}
16+
pub fn baah(a: W2<W3<i32, u32>>, b: W2<W3<i32>>) {}
17+
//

tests/rustdoc-js/nested-unboxed.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// exact-check
2+
3+
const EXPECTED = [
4+
{
5+
'query': '-> Result<Object, bool>',
6+
'others': [
7+
{ 'path': 'nested_unboxed', 'name': 'something' },
8+
],
9+
},
10+
{
11+
'query': '-> Result<Object<i32, u32>, bool>',
12+
'others': [
13+
{ 'path': 'nested_unboxed', 'name': 'something' },
14+
],
15+
},
16+
{
17+
'query': '-> Object, bool',
18+
'others': [
19+
{ 'path': 'nested_unboxed', 'name': 'something' },
20+
],
21+
},
22+
{
23+
'query': '-> Object<i32, u32>, bool',
24+
'others': [
25+
{ 'path': 'nested_unboxed', 'name': 'something' },
26+
],
27+
},
28+
{
29+
'query': '-> i32, u32, bool',
30+
'others': [
31+
{ 'path': 'nested_unboxed', 'name': 'something' },
32+
],
33+
},
34+
{
35+
'query': '-> Result<i32, u32, bool>',
36+
'others': [
37+
{ 'path': 'nested_unboxed', 'name': 'something' },
38+
],
39+
},
40+
{
41+
'query': '-> Result<Object<i32>, bool>',
42+
'others': [
43+
{ 'path': 'nested_unboxed', 'name': 'something' },
44+
],
45+
},
46+
{
47+
'query': '-> Result<Object<u32>, bool>',
48+
'others': [
49+
{ 'path': 'nested_unboxed', 'name': 'something' },
50+
],
51+
},
52+
{
53+
'query': '-> Result<Object<i32>, u32, bool>',
54+
'others': [],
55+
},
56+
{
57+
'query': '-> Result<i32, Object<u32>, bool>',
58+
'others': [],
59+
},
60+
{
61+
'query': '-> Result<i32, u32, Object<bool>>',
62+
'others': [],
63+
},
64+
{
65+
'query': '-> Result<Object<i32>, Object<u32>, bool>',
66+
'others': [],
67+
},
68+
];

tests/rustdoc-js/nested-unboxed.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub struct Object<T, U>(T, U);
2+
3+
pub fn something() -> Result<Object<i32, u32>, bool> {
4+
loop {}
5+
}

0 commit comments

Comments
 (0)