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

Commit 2f9ea8a

Browse files
committed
rustdoc search: give buildTypeMapIndex a conditional return type
we encode "if the argument is a non-empty string, this will never return null" into the type signature.
1 parent a8c0b3b commit 2f9ea8a

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,73 +1477,61 @@ class DocSearch {
14771477
* Special type name IDs for searching by array.
14781478
* @type {number}
14791479
*/
1480-
// @ts-expect-error
14811480
this.typeNameIdOfArray = this.buildTypeMapIndex("array");
14821481
/**
14831482
* Special type name IDs for searching by slice.
14841483
* @type {number}
14851484
*/
1486-
// @ts-expect-error
14871485
this.typeNameIdOfSlice = this.buildTypeMapIndex("slice");
14881486
/**
14891487
* Special type name IDs for searching by both array and slice (`[]` syntax).
14901488
* @type {number}
14911489
*/
1492-
// @ts-expect-error
14931490
this.typeNameIdOfArrayOrSlice = this.buildTypeMapIndex("[]");
14941491
/**
14951492
* Special type name IDs for searching by tuple.
14961493
* @type {number}
14971494
*/
1498-
// @ts-expect-error
14991495
this.typeNameIdOfTuple = this.buildTypeMapIndex("tuple");
15001496
/**
15011497
* Special type name IDs for searching by unit.
15021498
* @type {number}
15031499
*/
1504-
// @ts-expect-error
15051500
this.typeNameIdOfUnit = this.buildTypeMapIndex("unit");
15061501
/**
15071502
* Special type name IDs for searching by both tuple and unit (`()` syntax).
15081503
* @type {number}
15091504
*/
1510-
// @ts-expect-error
15111505
this.typeNameIdOfTupleOrUnit = this.buildTypeMapIndex("()");
15121506
/**
15131507
* Special type name IDs for searching `fn`.
15141508
* @type {number}
15151509
*/
1516-
// @ts-expect-error
15171510
this.typeNameIdOfFn = this.buildTypeMapIndex("fn");
15181511
/**
15191512
* Special type name IDs for searching `fnmut`.
15201513
* @type {number}
15211514
*/
1522-
// @ts-expect-error
15231515
this.typeNameIdOfFnMut = this.buildTypeMapIndex("fnmut");
15241516
/**
15251517
* Special type name IDs for searching `fnonce`.
15261518
* @type {number}
15271519
*/
1528-
// @ts-expect-error
15291520
this.typeNameIdOfFnOnce = this.buildTypeMapIndex("fnonce");
15301521
/**
15311522
* Special type name IDs for searching higher order functions (`->` syntax).
15321523
* @type {number}
15331524
*/
1534-
// @ts-expect-error
15351525
this.typeNameIdOfHof = this.buildTypeMapIndex("->");
15361526
/**
15371527
* Special type name IDs the output assoc type.
15381528
* @type {number}
15391529
*/
1540-
// @ts-expect-error
15411530
this.typeNameIdOfOutput = this.buildTypeMapIndex("output", true);
15421531
/**
15431532
* Special type name IDs for searching by reference.
15441533
* @type {number}
15451534
*/
1546-
// @ts-expect-error
15471535
this.typeNameIdOfReference = this.buildTypeMapIndex("reference");
15481536

15491537
/**
@@ -1596,11 +1584,17 @@ class DocSearch {
15961584
* This is effectively string interning, so that function matching can be
15971585
* done more quickly. Two types with the same name but different item kinds
15981586
* get the same ID.
1599-
*
1600-
* @param {string} name
1587+
*
1588+
* @template T extends string
1589+
* @overload
1590+
* @param {T} name
16011591
* @param {boolean=} isAssocType - True if this is an assoc type
1602-
*
1603-
* @returns {number?}
1592+
* @returns {T extends "" ? null : number}
1593+
*
1594+
* @param {string} name
1595+
* @param {boolean=} isAssocType
1596+
* @returns {number | null}
1597+
*
16041598
*/
16051599
buildTypeMapIndex(name, isAssocType) {
16061600
if (name === "" || name === null) {

0 commit comments

Comments
 (0)