Skip to content

Commit c4d9318

Browse files
Make current crate aliases go first
1 parent 883c177 commit c4d9318

File tree

5 files changed

+67
-34
lines changed

5 files changed

+67
-34
lines changed

src/librustdoc/html/static/main.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,10 @@ function getSearchElement() {
978978
}
979979

980980
function handleAliases(ret, query, filterCrates) {
981+
// We separate aliases and crate aliases because we want to have current crate
982+
// aliases to be before the others in the displayed results.
981983
var aliases = [];
984+
var crateAliases = [];
982985
var i;
983986
if (filterCrates !== undefined &&
984987
ALIASES[filterCrates] &&
@@ -990,25 +993,28 @@ function getSearchElement() {
990993
} else {
991994
Object.keys(ALIASES).forEach(function(crate) {
992995
if (ALIASES[crate][query.search]) {
996+
var pushTo = crate === window.currentCrate ? crateAliases : aliases;
993997
for (i = 0; i < ALIASES[crate][query.search].length; ++i) {
994-
aliases.push(
998+
pushTo.push(
995999
createAliasFromItem(
9961000
searchIndex[ALIASES[crate][query.search][i]]));
9971001
}
9981002
}
9991003
});
10001004
}
1001-
aliases.sort(function(aaa, bbb) {
1005+
1006+
var sortFunc = function(aaa, bbb) {
10021007
if (aaa.path < bbb.path) {
10031008
return 1;
10041009
} else if (aaa.path === bbb.path) {
10051010
return 0;
10061011
}
10071012
return -1;
1008-
});
1009-
for (i = 0; i < aliases.length; ++i) {
1010-
var alias = aliases[i];
1013+
};
1014+
crateAliases.sort(sortFunc);
1015+
aliases.sort(sortFunc);
10111016

1017+
var pushFunc = function(alias) {
10121018
alias.alias = query.raw;
10131019
var res = buildHrefAndPath(alias);
10141020
alias.displayPath = pathSplitter(res[0]);
@@ -1019,7 +1025,9 @@ function getSearchElement() {
10191025
if (ret.others.length > MAX_RESULTS) {
10201026
ret.others.pop();
10211027
}
1022-
}
1028+
};
1029+
onEach(aliases, pushFunc);
1030+
onEach(crateAliases, pushFunc);
10231031
}
10241032

10251033
// quoted values mean literal search

src/test/rustdoc-js-std/alias-2.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// ignore-order
2-
31
const QUERY = '+';
42

53
const EXPECTED = {
64
'others': [
7-
{ 'path': 'core::ops', 'name': 'AddAssign' },
8-
{ 'path': 'core::ops', 'name': 'Add' },
95
{ 'path': 'std::ops', 'name': 'AddAssign' },
106
{ 'path': 'std::ops', 'name': 'Add' },
7+
{ 'path': 'core::ops', 'name': 'AddAssign' },
8+
{ 'path': 'core::ops', 'name': 'Add' },
119
],
1210
};

src/test/rustdoc-js/doc-alias.js

+47-21
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const EXPECTED = [
3232
'path': 'doc_alias',
3333
'name': 'Struct',
3434
'alias': 'StructItem',
35-
'href': '../doc_alias/struct.Struct.html'
35+
'href': '../doc_alias/struct.Struct.html',
36+
'is_alias': true
3637
},
3738
],
3839
},
@@ -42,7 +43,8 @@ const EXPECTED = [
4243
'path': 'doc_alias::Struct',
4344
'name': 'field',
4445
'alias': 'StructFieldItem',
45-
'href': '../doc_alias/struct.Struct.html#structfield.field'
46+
'href': '../doc_alias/struct.Struct.html#structfield.field',
47+
'is_alias': true
4648
},
4749
],
4850
},
@@ -52,7 +54,8 @@ const EXPECTED = [
5254
'path': 'doc_alias::Struct',
5355
'name': 'method',
5456
'alias': 'StructMethodItem',
55-
'href': '../doc_alias/struct.Struct.html#method.method'
57+
'href': '../doc_alias/struct.Struct.html#method.method',
58+
'is_alias': true
5659
},
5760
],
5861
},
@@ -65,16 +68,24 @@ const EXPECTED = [
6568
'others': [],
6669
},
6770
{
68-
// ImplTraitFunction
69-
'others': [],
71+
'others': [
72+
{
73+
'path': 'doc_alias::Struct',
74+
'name': 'function',
75+
'alias': 'ImplTraitFunction',
76+
'href': '../doc_alias/struct.Struct.html#method.function',
77+
'is_alias': true
78+
},
79+
],
7080
},
7181
{
7282
'others': [
7383
{
7484
'path': 'doc_alias',
7585
'name': 'Enum',
7686
'alias': 'EnumItem',
77-
'href': '../doc_alias/enum.Enum.html'
87+
'href': '../doc_alias/enum.Enum.html',
88+
'is_alias': true
7889
},
7990
],
8091
},
@@ -84,7 +95,8 @@ const EXPECTED = [
8495
'path': 'doc_alias::Enum',
8596
'name': 'Variant',
8697
'alias': 'VariantItem',
87-
'href': '../doc_alias/enum.Enum.html#variant.Variant'
98+
'href': '../doc_alias/enum.Enum.html#variant.Variant',
99+
'is_alias': true
88100
},
89101
],
90102
},
@@ -94,7 +106,8 @@ const EXPECTED = [
94106
'path': 'doc_alias::Enum',
95107
'name': 'method',
96108
'alias': 'EnumMethodItem',
97-
'href': '../doc_alias/enum.Enum.html#method.method'
109+
'href': '../doc_alias/enum.Enum.html#method.method',
110+
'is_alias': true
98111
},
99112
],
100113
},
@@ -104,7 +117,8 @@ const EXPECTED = [
104117
'path': 'doc_alias',
105118
'name': 'Typedef',
106119
'alias': 'TypedefItem',
107-
'href': '../doc_alias/type.Typedef.html'
120+
'href': '../doc_alias/type.Typedef.html',
121+
'is_alias': true
108122
},
109123
],
110124
},
@@ -114,7 +128,8 @@ const EXPECTED = [
114128
'path': 'doc_alias',
115129
'name': 'Trait',
116130
'alias': 'TraitItem',
117-
'href': '../doc_alias/trait.Trait.html'
131+
'href': '../doc_alias/trait.Trait.html',
132+
'is_alias': true
118133
},
119134
],
120135
},
@@ -124,7 +139,8 @@ const EXPECTED = [
124139
'path': 'doc_alias::Trait',
125140
'name': 'Target',
126141
'alias': 'TraitTypeItem',
127-
'href': '../doc_alias/trait.Trait.html#associatedtype.Target'
142+
'href': '../doc_alias/trait.Trait.html#associatedtype.Target',
143+
'is_alias': true
128144
},
129145
],
130146
},
@@ -134,7 +150,8 @@ const EXPECTED = [
134150
'path': 'doc_alias::Trait',
135151
'name': 'AssociatedConst',
136152
'alias': 'AssociatedConstItem',
137-
'href': '../doc_alias/trait.Trait.html#associatedconstant.AssociatedConst'
153+
'href': '../doc_alias/trait.Trait.html#associatedconstant.AssociatedConst',
154+
'is_alias': true
138155
},
139156
],
140157
},
@@ -144,7 +161,8 @@ const EXPECTED = [
144161
'path': 'doc_alias::Trait',
145162
'name': 'function',
146163
'alias': 'TraitFunctionItem',
147-
'href': '../doc_alias/trait.Trait.html#tymethod.function'
164+
'href': '../doc_alias/trait.Trait.html#tymethod.function',
165+
'is_alias': true
148166
},
149167
],
150168
},
@@ -154,7 +172,8 @@ const EXPECTED = [
154172
'path': 'doc_alias',
155173
'name': 'function',
156174
'alias': 'FunctionItem',
157-
'href': '../doc_alias/fn.function.html'
175+
'href': '../doc_alias/fn.function.html',
176+
'is_alias': true
158177
},
159178
],
160179
},
@@ -164,7 +183,8 @@ const EXPECTED = [
164183
'path': 'doc_alias',
165184
'name': 'Module',
166185
'alias': 'ModuleItem',
167-
'href': '../doc_alias/Module/index.html'
186+
'href': '../doc_alias/Module/index.html',
187+
'is_alias': true
168188
},
169189
],
170190
},
@@ -174,7 +194,8 @@ const EXPECTED = [
174194
'path': 'doc_alias',
175195
'name': 'Const',
176196
'alias': 'ConstItem',
177-
'href': '../doc_alias/constant.Const.html'
197+
'href': '../doc_alias/constant.Const.html',
198+
'is_alias': true
178199
},
179200
],
180201
},
@@ -184,7 +205,8 @@ const EXPECTED = [
184205
'path': 'doc_alias',
185206
'name': 'Static',
186207
'alias': 'StaticItem',
187-
'href': '../doc_alias/static.Static.html'
208+
'href': '../doc_alias/static.Static.html',
209+
'is_alias': true
188210
},
189211
],
190212
},
@@ -194,7 +216,8 @@ const EXPECTED = [
194216
'path': 'doc_alias',
195217
'name': 'Union',
196218
'alias': 'UnionItem',
197-
'href': '../doc_alias/union.Union.html'
219+
'href': '../doc_alias/union.Union.html',
220+
'is_alias': true
198221
},
199222
// Not an alias!
200223
{
@@ -210,7 +233,8 @@ const EXPECTED = [
210233
'path': 'doc_alias::Union',
211234
'name': 'union_item',
212235
'alias': 'UnionFieldItem',
213-
'href': '../doc_alias/union.Union.html#structfield.union_item'
236+
'href': '../doc_alias/union.Union.html#structfield.union_item',
237+
'is_alias': true
214238
},
215239
],
216240
},
@@ -220,7 +244,8 @@ const EXPECTED = [
220244
'path': 'doc_alias::Union',
221245
'name': 'method',
222246
'alias': 'UnionMethodItem',
223-
'href': '../doc_alias/union.Union.html#method.method'
247+
'href': '../doc_alias/union.Union.html#method.method',
248+
'is_alias': true
224249
},
225250
],
226251
},
@@ -230,7 +255,8 @@ const EXPECTED = [
230255
'path': 'doc_alias',
231256
'name': 'Macro',
232257
'alias': 'MacroItem',
233-
'href': '../doc_alias/macro.Macro.html'
258+
'href': '../doc_alias/macro.Macro.html',
259+
'is_alias': true
234260
},
235261
],
236262
},

src/test/rustdoc-js/doc-alias.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ impl Trait for Struct {
1919
#[doc(alias = "ImplAssociatedConstItem")]
2020
const AssociatedConst: i32 = 12;
2121

22-
// Shouldn't be listed in aliases!
2322
#[doc(alias = "ImplTraitFunction")]
2423
fn function() -> Self::Target { 0 }
2524
}

src/tools/rustdoc-js/tester.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function lookForEntry(entry, data) {
218218
return null;
219219
}
220220

221-
function loadMainJsAndIndex(mainJs, searchIndex, crate) {
221+
function loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate) {
222222
if (searchIndex[searchIndex.length - 1].length === 0) {
223223
searchIndex.pop();
224224
}
@@ -241,6 +241,7 @@ function loadMainJsAndIndex(mainJs, searchIndex, crate) {
241241
ALIASES = {};
242242
finalJS += 'window = { "currentCrate": "' + crate + '" };\n';
243243
finalJS += 'var rootPath = "../";\n';
244+
finalJS += loadThings(["onEach"], 'function', extractFunction, storageJs);
244245
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
245246
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
246247
finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs);
@@ -338,10 +339,11 @@ function runChecks(testFile, loaded, index) {
338339

339340
function load_files(doc_folder, resource_suffix, crate) {
340341
var mainJs = readFile(path.join(doc_folder, "main" + resource_suffix + ".js"));
342+
var storageJs = readFile(path.join(doc_folder, "storage" + resource_suffix + ".js"));
341343
var searchIndex = readFile(
342344
path.join(doc_folder, "search-index" + resource_suffix + ".js")).split("\n");
343345

344-
return loadMainJsAndIndex(mainJs, searchIndex, crate);
346+
return loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate);
345347
}
346348

347349
function showHelp() {

0 commit comments

Comments
 (0)