Skip to content

Commit 1ab60f2

Browse files
committed
rustdoc-search: fix inaccurate type descriptions
1 parent a2541e8 commit 1ab60f2

File tree

2 files changed

+63
-54
lines changed

2 files changed

+63
-54
lines changed

src/librustdoc/html/static/js/externs.js

+56
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,59 @@ let FunctionSearchType;
200200
* }}
201201
*/
202202
let FunctionType;
203+
204+
/**
205+
* The raw search data for a given crate. `n`, `t`, `d`, `i`, and `f`
206+
* are arrays with the same length. `q`, `a`, and `c` use a sparse
207+
* representation for compactness.
208+
*
209+
* `n[i]` contains the name of an item.
210+
*
211+
* `t[i]` contains the type of that item
212+
* (as a string of characters that represent an offset in `itemTypes`).
213+
*
214+
* `d[i]` contains the description of that item.
215+
*
216+
* `q` contains the full paths of the items. For compactness, it is a set of
217+
* (index, path) pairs used to create a map. If a given index `i` is
218+
* not present, this indicates "same as the last index present".
219+
*
220+
* `i[i]` contains an item's parent, usually a module. For compactness,
221+
* it is a set of indexes into the `p` array.
222+
*
223+
* `f` contains function signatures, or `0` if the item isn't a function.
224+
* More information on how they're encoded can be found in rustc-dev-guide
225+
*
226+
* Functions are themselves encoded as arrays. The first item is a list of
227+
* types representing the function's inputs, and the second list item is a list
228+
* of types representing the function's output. Tuples are flattened.
229+
* Types are also represented as arrays; the first item is an index into the `p`
230+
* array, while the second is a list of types representing any generic parameters.
231+
*
232+
* b[i] contains an item's impl disambiguator. This is only present if an item
233+
* is defined in an impl block and, the impl block's type has more than one associated
234+
* item with the same name.
235+
*
236+
* `a` defines aliases with an Array of pairs: [name, offset], where `offset`
237+
* points into the n/t/d/q/i/f arrays.
238+
*
239+
* `doc` contains the description of the crate.
240+
*
241+
* `p` is a list of path/type pairs. It is used for parents and function parameters.
242+
*
243+
* `c` is an array of item indices that are deprecated.
244+
* @typedef {{
245+
* doc: string,
246+
* a: Object,
247+
* n: Array<string>,
248+
* t: String,
249+
* d: Array<string>,
250+
* q: Array<[Number, string]>,
251+
* i: Array<Number>,
252+
* f: string,
253+
* p: Array<Object>,
254+
* b: Array<[Number, String]>,
255+
* c: Array<Number>
256+
* }}
257+
*/
258+
let RawSearchIndexCrate;

src/librustdoc/html/static/js/search.js

+7-54
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,11 @@ ${item.displayPath}<span class="${type}">${name}</span>\
29242924
return functionTypeFingerprint[(fullId * 4) + 3];
29252925
}
29262926

2927+
/**
2928+
* Convert raw search index into in-memory search index.
2929+
*
2930+
* @param {[string, RawSearchIndexCrate][]} rawSearchIndex
2931+
*/
29272932
function buildIndex(rawSearchIndex) {
29282933
searchIndex = [];
29292934
typeNameIdMap = new Map();
@@ -2950,59 +2955,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
29502955
// This loop actually generates the search item indexes, including
29512956
// normalized names, type signature objects and fingerprints, and aliases.
29522957
id = 0;
2953-
/**
2954-
* The raw search data for a given crate. `n`, `t`, `d`, `i`, and `f`
2955-
* are arrays with the same length. `q`, `a`, and `c` use a sparse
2956-
* representation for compactness.
2957-
*
2958-
* `n[i]` contains the name of an item.
2959-
*
2960-
* `t[i]` contains the type of that item
2961-
* (as a string of characters that represent an offset in `itemTypes`).
2962-
*
2963-
* `d[i]` contains the description of that item.
2964-
*
2965-
* `q` contains the full paths of the items. For compactness, it is a set of
2966-
* (index, path) pairs used to create a map. If a given index `i` is
2967-
* not present, this indicates "same as the last index present".
2968-
*
2969-
* `i[i]` contains an item's parent, usually a module. For compactness,
2970-
* it is a set of indexes into the `p` array.
2971-
*
2972-
* `f[i]` contains function signatures, or `0` if the item isn't a function.
2973-
* Functions are themselves encoded as arrays. The first item is a list of
2974-
* types representing the function's inputs, and the second list item is a list
2975-
* of types representing the function's output. Tuples are flattened.
2976-
* Types are also represented as arrays; the first item is an index into the `p`
2977-
* array, while the second is a list of types representing any generic parameters.
2978-
*
2979-
* b[i] contains an item's impl disambiguator. This is only present if an item
2980-
* is defined in an impl block and, the impl block's type has more than one associated
2981-
* item with the same name.
2982-
*
2983-
* `a` defines aliases with an Array of pairs: [name, offset], where `offset`
2984-
* points into the n/t/d/q/i/f arrays.
2985-
*
2986-
* `doc` contains the description of the crate.
2987-
*
2988-
* `p` is a list of path/type pairs. It is used for parents and function parameters.
2989-
*
2990-
* `c` is an array of item indices that are deprecated.
2991-
*
2992-
* @type {{
2993-
* doc: string,
2994-
* a: Object,
2995-
* n: Array<string>,
2996-
* t: String,
2997-
* d: Array<string>,
2998-
* q: Array<[Number, string]>,
2999-
* i: Array<Number>,
3000-
* f: Array<RawFunctionSearchType>,
3001-
* p: Array<Object>,
3002-
* b: Array<[Number, String]>,
3003-
* c: Array<Number>
3004-
* }}
3005-
*/
2958+
30062959
for (const [crate, crateCorpus] of rawSearchIndex) {
30072960
// This object should have exactly the same set of fields as the "row"
30082961
// object defined below. Your JavaScript runtime will thank you.
@@ -3039,7 +2992,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
30392992
const itemDescs = crateCorpus.d;
30402993
// an array of (Number) the parent path index + 1 to `paths`, or 0 if none
30412994
const itemParentIdxs = crateCorpus.i;
3042-
// an array of (Object | null) the type of the function, if any
2995+
// an array of (Array | 0) the type of the function, if any
30432996
const itemFunctionSearchTypes = crateCorpus.f;
30442997
// an array of (Number) indices for the deprecated items
30452998
const deprecatedItems = new Set(crateCorpus.c);

0 commit comments

Comments
 (0)