Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cbde61c

Browse files
ollie27Mark-Simulacrum
authored andcommitted
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 8196407 commit cbde61c

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

src/librustdoc/html/static/main.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,13 @@ function defocusSearchBar() {
10061006
var aliases = [];
10071007
var crateAliases = [];
10081008
var i;
1009-
if (filterCrates !== undefined &&
1010-
ALIASES[filterCrates] &&
1011-
ALIASES[filterCrates][query.search]) {
1012-
for (i = 0; i < ALIASES[crate][query.search].length; ++i) {
1013-
aliases.push(
1014-
createAliasFromItem(searchIndex[ALIASES[filterCrates][query.search]]));
1009+
if (filterCrates !== undefined) {
1010+
if (ALIASES[filterCrates] && ALIASES[filterCrates][query.search]) {
1011+
for (i = 0; i < ALIASES[filterCrates][query.search].length; ++i) {
1012+
aliases.push(
1013+
createAliasFromItem(
1014+
searchIndex[ALIASES[filterCrates][query.search][i]]));
1015+
}
10151016
}
10161017
} else {
10171018
Object.keys(ALIASES).forEach(function(crate) {
Lines changed: 9 additions & 0 deletions
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+
};
Lines changed: 4 additions & 0 deletions
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;
Lines changed: 17 additions & 0 deletions
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+
};
Lines changed: 7 additions & 0 deletions
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

Lines changed: 11 additions & 2 deletions
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)