Skip to content

Commit

Permalink
rustdoc-search: fix accidental shared, mutable map
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Nov 18, 2023
1 parent 0f36695 commit 5de7521
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 30 deletions.
44 changes: 14 additions & 30 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,24 +1349,16 @@ function initSearch(rawSearchIndex) {
continue;
}
if (fnType.id < 0 && queryElem.id < 0) {
if (mgens === null) {
mgens = new Map();
if (mgens && mgens.has(fnType.id) &&
mgens.get(fnType.id) !== queryElem.id) {
continue;
}
const alreadyAssigned = mgens.has(fnType.id);
if (alreadyAssigned) {
if (mgens.get(fnType.id) !== queryElem.id) {
continue;
}
} else {
mgens.set(fnType.id, queryElem.id);
}
if (!solutionCb || solutionCb(mgens)) {
const mgensScratch = new Map(mgens);
mgensScratch.set(fnType.id, queryElem.id);
if (!solutionCb || solutionCb(mgensScratch)) {
return true;
}
if (!alreadyAssigned) {
mgens.delete(fnType.id);
}
} else if (!solutionCb || solutionCb(mgens)) {
} else if (!solutionCb || solutionCb(mgens ? new Map(mgens) : null)) {
// unifyFunctionTypeIsMatchCandidate already checks that ids match
return true;
}
Expand All @@ -1376,34 +1368,26 @@ function initSearch(rawSearchIndex) {
continue;
}
if (fnType.id < 0) {
if (mgens === null) {
mgens = new Map();
}
const alreadyAssigned = mgens.has(fnType.id);
if (alreadyAssigned) {
if (mgens.get(fnType.id) !== 0) {
continue;
}
} else {
mgens.set(fnType.id, 0);
if (mgens && mgens.has(fnType.id) &&
mgens.get(fnType.id) !== 0) {
continue;
}
const mgensScratch = new Map(mgens);
mgensScratch.set(fnType.id, 0);
if (unifyFunctionTypes(
whereClause[(-fnType.id) - 1],
queryElems,
whereClause,
mgens,
mgensScratch,
solutionCb
)) {
return true;
}
if (!alreadyAssigned) {
mgens.delete(fnType.id);
}
} else if (unifyFunctionTypes(
fnType.generics,
queryElems,
whereClause,
mgens,
mgens ? new Map(mgens) : null,
solutionCb
)) {
return true;
Expand Down
22 changes: 22 additions & 0 deletions tests/rustdoc-js/generics2.js
Original file line number Diff line number Diff line change
@@ -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"}
],
},
];
13 changes: 13 additions & 0 deletions tests/rustdoc-js/generics2.rs
Original file line number Diff line number Diff line change
@@ -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!();
}

0 comments on commit 5de7521

Please sign in to comment.