Skip to content

Commit 478750c

Browse files
committed
rustdoc: Fix doc aliases with crate filtering
Fix a crash when searching for an alias contained in the currently selected filter crate. Also remove alias search results for crates that should be filtered out. The test suite needed to be fixed to actually take into account the crate filtering and check that there are no results when none are expected.
1 parent 033013c commit 478750c

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

src/librustdoc/html/static/main.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,13 @@ function defocusSearchBar() {
10151015
var aliases = [];
10161016
var crateAliases = [];
10171017
var i;
1018-
if (filterCrates !== undefined &&
1019-
ALIASES[filterCrates] &&
1020-
ALIASES[filterCrates][query.search]) {
1021-
for (i = 0; i < ALIASES[crate][query.search].length; ++i) {
1022-
aliases.push(
1023-
createAliasFromItem(searchIndex[ALIASES[filterCrates][query.search]]));
1018+
if (filterCrates !== undefined) {
1019+
if (ALIASES[filterCrates] && ALIASES[filterCrates][query.search]) {
1020+
for (i = 0; i < ALIASES[filterCrates][query.search].length; ++i) {
1021+
aliases.push(
1022+
createAliasFromItem(
1023+
searchIndex[ALIASES[filterCrates][query.search][i]]));
1024+
}
10241025
}
10251026
} else {
10261027
Object.keys(ALIASES).forEach(function(crate) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// exact-check
2+
3+
const QUERY = 'true';
4+
5+
const FILTER_CRATE = 'some_other_crate';
6+
7+
const EXPECTED = {
8+
'others': [],
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(doc_alias)]
2+
3+
#[doc(alias = "true")]
4+
pub struct Foo;
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// exact-check
2+
3+
const QUERY = 'true';
4+
5+
const FILTER_CRATE = 'doc_alias_filter';
6+
7+
const EXPECTED = {
8+
'others': [
9+
{
10+
'path': 'doc_alias_filter',
11+
'name': 'Foo',
12+
'alias': 'true',
13+
'href': '../doc_alias_filter/struct.Foo.html',
14+
'is_alias': true
15+
},
16+
],
17+
};
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(doc_alias)]
2+
3+
#[doc(alias = "true")]
4+
pub struct Foo;
5+
6+
#[doc(alias = "false")]
7+
pub struct Bar;

src/tools/rustdoc-js/tester.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ function runSearch(query, expected, index, loaded, loadedFile, queryName) {
269269
break;
270270
}
271271
var entry = expected[key];
272+
273+
if (exact_check == true && entry.length !== results[key].length) {
274+
error_text.push(queryName + "==> Expected exactly " + entry.length +
275+
" results but found " + results[key].length + " in '" + key + "'");
276+
}
277+
272278
var prev_pos = -1;
273279
for (var i = 0; i < entry.length; ++i) {
274280
var entry_pos = lookForEntry(entry[i], results[key]);
@@ -307,8 +313,11 @@ function checkResult(error_text, loadedFile, displaySuccess) {
307313
}
308314

309315
function runChecks(testFile, loaded, index) {
310-
var loadedFile = loadContent(
311-
readFile(testFile) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
316+
var testFileContent = readFile(testFile) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;';
317+
if (testFileContent.indexOf("FILTER_CRATE") !== -1) {
318+
testFileContent += "exports.FILTER_CRATE = FILTER_CRATE;";
319+
}
320+
var loadedFile = loadContent(testFileContent);
312321

313322
const expected = loadedFile.EXPECTED;
314323
const query = loadedFile.QUERY;

0 commit comments

Comments
 (0)