rustdoc-search: fix accidental shared, mutable map

This commit is contained in:
Michael Howell 2023-11-17 15:44:29 -07:00
parent c76c2e71f0
commit a66972d551
3 changed files with 49 additions and 30 deletions

View File

@ -1349,24 +1349,16 @@ function initSearch(rawSearchIndex) {
continue; continue;
} }
if (fnType.id < 0 && queryElem.id < 0) { if (fnType.id < 0 && queryElem.id < 0) {
if (mgens === null) { if (mgens && mgens.has(fnType.id) &&
mgens = new Map(); mgens.get(fnType.id) !== queryElem.id) {
continue;
} }
const alreadyAssigned = mgens.has(fnType.id); const mgensScratch = new Map(mgens);
if (alreadyAssigned) { mgensScratch.set(fnType.id, queryElem.id);
if (mgens.get(fnType.id) !== queryElem.id) { if (!solutionCb || solutionCb(mgensScratch)) {
continue;
}
} else {
mgens.set(fnType.id, queryElem.id);
}
if (!solutionCb || solutionCb(mgens)) {
return true; return true;
} }
if (!alreadyAssigned) { } else if (!solutionCb || solutionCb(mgens ? new Map(mgens) : null)) {
mgens.delete(fnType.id);
}
} else if (!solutionCb || solutionCb(mgens)) {
// unifyFunctionTypeIsMatchCandidate already checks that ids match // unifyFunctionTypeIsMatchCandidate already checks that ids match
return true; return true;
} }
@ -1376,34 +1368,26 @@ function initSearch(rawSearchIndex) {
continue; continue;
} }
if (fnType.id < 0) { if (fnType.id < 0) {
if (mgens === null) { if (mgens && mgens.has(fnType.id) &&
mgens = new Map(); mgens.get(fnType.id) !== 0) {
} continue;
const alreadyAssigned = mgens.has(fnType.id);
if (alreadyAssigned) {
if (mgens.get(fnType.id) !== 0) {
continue;
}
} else {
mgens.set(fnType.id, 0);
} }
const mgensScratch = new Map(mgens);
mgensScratch.set(fnType.id, 0);
if (unifyFunctionTypes( if (unifyFunctionTypes(
whereClause[(-fnType.id) - 1], whereClause[(-fnType.id) - 1],
queryElems, queryElems,
whereClause, whereClause,
mgens, mgensScratch,
solutionCb solutionCb
)) { )) {
return true; return true;
} }
if (!alreadyAssigned) {
mgens.delete(fnType.id);
}
} else if (unifyFunctionTypes( } else if (unifyFunctionTypes(
fnType.generics, fnType.generics,
queryElems, queryElems,
whereClause, whereClause,
mgens, mgens ? new Map(mgens) : null,
solutionCb solutionCb
)) { )) {
return true; return true;

View File

@ -0,0 +1,22 @@
// exact-check
const EXPECTED = [
{
'query': 'outside<U>, outside<V> -> outside<W>',
'others': [],
},
{
'query': 'outside<V>, outside<U> -> outside<W>',
'others': [],
},
{
'query': 'outside<U>, outside<U> -> outside<W>',
'others': [],
},
{
'query': 'outside<U>, outside<U> -> outside<U>',
'others': [
{"path": "generics2", "name": "should_match_3"}
],
},
];

View File

@ -0,0 +1,13 @@
pub struct Outside<T>(T);
pub fn no_match<U, V>(a: Outside<U>, b: Outside<V>) -> (Outside<U>, Outside<V>) {
unimplemented!();
}
pub fn no_match_2<U, V>(a: Outside<V>, b: Outside<U>) -> (Outside<U>, Outside<V>) {
unimplemented!();
}
pub fn should_match_3<U>(a: Outside<U>, b: Outside<U>) -> (Outside<U>, Outside<U>) {
unimplemented!();
}