Skip to content

Commit b436a38

Browse files
committed
rustdoc-search: fix accidental shared, mutable map
1 parent 0f36695 commit b436a38

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

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

+11-15
Original file line numberDiff line numberDiff line change
@@ -1349,24 +1349,16 @@ function initSearch(rawSearchIndex) {
13491349
continue;
13501350
}
13511351
if (fnType.id < 0 && queryElem.id < 0) {
1352-
if (mgens === null) {
1353-
mgens = new Map();
1354-
}
1355-
const alreadyAssigned = mgens.has(fnType.id);
1356-
if (alreadyAssigned) {
1357-
if (mgens.get(fnType.id) !== queryElem.id) {
1358-
continue;
1359-
}
1360-
} else {
1361-
mgens.set(fnType.id, queryElem.id);
1352+
if (mgens && mgens.has(fnType.id) &&
1353+
mgens.get(fnType.id) !== queryElem.id) {
1354+
continue;
13621355
}
1363-
if (!solutionCb || solutionCb(mgens)) {
1356+
const mgensScratch = new Map(mgens);
1357+
mgensScratch.set(fnType.id, queryElem.id);
1358+
if (!solutionCb || solutionCb(mgensScratch)) {
13641359
return true;
13651360
}
1366-
if (!alreadyAssigned) {
1367-
mgens.delete(fnType.id);
1368-
}
1369-
} else if (!solutionCb || solutionCb(mgens)) {
1361+
} else if (!solutionCb || solutionCb(mgens ? new Map(mgens) : null)) {
13701362
// unifyFunctionTypeIsMatchCandidate already checks that ids match
13711363
return true;
13721364
}
@@ -1391,6 +1383,8 @@ function initSearch(rawSearchIndex) {
13911383
whereClause[(-fnType.id) - 1],
13921384
queryElems,
13931385
whereClause,
1386+
// don't need to copy mgens here
1387+
// unifyFunctionTypes already does that
13941388
mgens,
13951389
solutionCb
13961390
)) {
@@ -1403,6 +1397,8 @@ function initSearch(rawSearchIndex) {
14031397
fnType.generics,
14041398
queryElems,
14051399
whereClause,
1400+
// don't need to copy mgens here
1401+
// unifyFunctionTypes already does that
14061402
mgens,
14071403
solutionCb
14081404
)) {

tests/rustdoc-js/generics2.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// exact-check
2+
3+
const EXPECTED = [
4+
{
5+
'query': 'outside<U>, outside<V> -> outside<W>',
6+
'others': [],
7+
},
8+
{
9+
'query': 'outside<V>, outside<U> -> outside<W>',
10+
'others': [],
11+
},
12+
{
13+
'query': 'outside<U>, outside<U> -> outside<W>',
14+
'others': [],
15+
},
16+
{
17+
'query': 'outside<U>, outside<U> -> outside<U>',
18+
'others': [
19+
{"path": "generics2", "name": "should_match_3"}
20+
],
21+
},
22+
];

tests/rustdoc-js/generics2.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub struct Outside<T>(T);
2+
3+
pub fn no_match<U, V>(a: Outside<U>, b: Outside<V>) -> (Outside<U>, Outside<V>) {
4+
unimplemented!();
5+
}
6+
7+
pub fn no_match_2<U, V>(a: Outside<V>, b: Outside<U>) -> (Outside<U>, Outside<V>) {
8+
unimplemented!();
9+
}
10+
11+
pub fn should_match_3<U>(a: Outside<U>, b: Outside<U>) -> (Outside<U>, Outside<U>) {
12+
unimplemented!();
13+
}

0 commit comments

Comments
 (0)