@@ -638,7 +638,6 @@ function getNextElem(query, parserState, elems, isInGenerics) {
638
638
getFilteredNextElem ( query , parserState , generics , isInGenerics ) ;
639
639
generics [ generics . length - 1 ] . bindingName = makePrimitiveElement ( "output" ) ;
640
640
} else {
641
- // @ts -expect-error
642
641
generics . push ( makePrimitiveElement ( null , {
643
642
bindingName : makePrimitiveElement ( "output" ) ,
644
643
typeFilter : null ,
@@ -791,7 +790,7 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
791
790
generics : generics . filter ( gen => {
792
791
// Syntactically, bindings are parsed as generics,
793
792
// but the query engine treats them differently.
794
- if ( gen . bindingName !== null ) {
793
+ if ( gen . bindingName !== null && gen . bindingName . name !== null ) {
795
794
if ( gen . name !== null ) {
796
795
gen . bindingName . generics . unshift ( gen ) ;
797
796
}
@@ -811,8 +810,8 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
811
810
812
811
/**
813
812
*
814
- * @param {string } name
815
- * @param {Object = } extra
813
+ * @param {string|null } name
814
+ * @param {rustdoc.ParserQueryElementFields = } extra
816
815
* @returns {rustdoc.ParserQueryElement }
817
816
*/
818
817
function makePrimitiveElement ( name , extra ) {
@@ -1478,73 +1477,61 @@ class DocSearch {
1478
1477
* Special type name IDs for searching by array.
1479
1478
* @type {number }
1480
1479
*/
1481
- // @ts -expect-error
1482
1480
this . typeNameIdOfArray = this . buildTypeMapIndex ( "array" ) ;
1483
1481
/**
1484
1482
* Special type name IDs for searching by slice.
1485
1483
* @type {number }
1486
1484
*/
1487
- // @ts -expect-error
1488
1485
this . typeNameIdOfSlice = this . buildTypeMapIndex ( "slice" ) ;
1489
1486
/**
1490
1487
* Special type name IDs for searching by both array and slice (`[]` syntax).
1491
1488
* @type {number }
1492
1489
*/
1493
- // @ts -expect-error
1494
1490
this . typeNameIdOfArrayOrSlice = this . buildTypeMapIndex ( "[]" ) ;
1495
1491
/**
1496
1492
* Special type name IDs for searching by tuple.
1497
1493
* @type {number }
1498
1494
*/
1499
- // @ts -expect-error
1500
1495
this . typeNameIdOfTuple = this . buildTypeMapIndex ( "tuple" ) ;
1501
1496
/**
1502
1497
* Special type name IDs for searching by unit.
1503
1498
* @type {number }
1504
1499
*/
1505
- // @ts -expect-error
1506
1500
this . typeNameIdOfUnit = this . buildTypeMapIndex ( "unit" ) ;
1507
1501
/**
1508
1502
* Special type name IDs for searching by both tuple and unit (`()` syntax).
1509
1503
* @type {number }
1510
1504
*/
1511
- // @ts -expect-error
1512
1505
this . typeNameIdOfTupleOrUnit = this . buildTypeMapIndex ( "()" ) ;
1513
1506
/**
1514
1507
* Special type name IDs for searching `fn`.
1515
1508
* @type {number }
1516
1509
*/
1517
- // @ts -expect-error
1518
1510
this . typeNameIdOfFn = this . buildTypeMapIndex ( "fn" ) ;
1519
1511
/**
1520
1512
* Special type name IDs for searching `fnmut`.
1521
1513
* @type {number }
1522
1514
*/
1523
- // @ts -expect-error
1524
1515
this . typeNameIdOfFnMut = this . buildTypeMapIndex ( "fnmut" ) ;
1525
1516
/**
1526
1517
* Special type name IDs for searching `fnonce`.
1527
1518
* @type {number }
1528
1519
*/
1529
- // @ts -expect-error
1530
1520
this . typeNameIdOfFnOnce = this . buildTypeMapIndex ( "fnonce" ) ;
1531
1521
/**
1532
1522
* Special type name IDs for searching higher order functions (`->` syntax).
1533
1523
* @type {number }
1534
1524
*/
1535
- // @ts -expect-error
1536
1525
this . typeNameIdOfHof = this . buildTypeMapIndex ( "->" ) ;
1537
1526
/**
1538
1527
* Special type name IDs the output assoc type.
1539
1528
* @type {number }
1540
1529
*/
1541
- // @ts -expect-error
1542
1530
this . typeNameIdOfOutput = this . buildTypeMapIndex ( "output" , true ) ;
1543
1531
/**
1544
1532
* Special type name IDs for searching by reference.
1545
1533
* @type {number }
1546
1534
*/
1547
- // @ts -expect-error
1548
1535
this . typeNameIdOfReference = this . buildTypeMapIndex ( "reference" ) ;
1549
1536
1550
1537
/**
@@ -1586,7 +1573,6 @@ class DocSearch {
1586
1573
/**
1587
1574
* @type {Array<rustdoc.Row> }
1588
1575
*/
1589
- // @ts -expect-error
1590
1576
this . searchIndex = this . buildIndex ( rawSearchIndex ) ;
1591
1577
}
1592
1578
@@ -1598,10 +1584,16 @@ class DocSearch {
1598
1584
* done more quickly. Two types with the same name but different item kinds
1599
1585
* get the same ID.
1600
1586
*
1601
- * @param {string } name
1587
+ * @template T extends string
1588
+ * @overload
1589
+ * @param {T } name
1602
1590
* @param {boolean= } isAssocType - True if this is an assoc type
1591
+ * @returns {T extends "" ? null : number }
1592
+ *
1593
+ * @param {string } name
1594
+ * @param {boolean= } isAssocType
1595
+ * @returns {number | null }
1603
1596
*
1604
- * @returns {number? }
1605
1597
*/
1606
1598
buildTypeMapIndex ( name , isAssocType ) {
1607
1599
if ( name === "" || name === null ) {
@@ -1909,6 +1901,7 @@ class DocSearch {
1909
1901
* Convert raw search index into in-memory search index.
1910
1902
*
1911
1903
* @param {Map<string, rustdoc.RawSearchIndexCrate> } rawSearchIndex
1904
+ * @returns {rustdoc.Row[] }
1912
1905
*/
1913
1906
buildIndex ( rawSearchIndex ) {
1914
1907
/**
@@ -2008,6 +2001,7 @@ class DocSearch {
2008
2001
return cb ;
2009
2002
} ;
2010
2003
2004
+ /** @type {rustdoc.Row[] } */
2011
2005
const searchIndex = [ ] ;
2012
2006
let currentIndex = 0 ;
2013
2007
let id = 0 ;
@@ -2108,8 +2102,6 @@ class DocSearch {
2108
2102
// an array of [(Number) item type,
2109
2103
// (String) name]
2110
2104
const rawPaths = crateCorpus . p ;
2111
- // an array of [(String) alias name
2112
- // [Number] index to items]
2113
2105
const aliases = crateCorpus . a ;
2114
2106
// an array of [(Number) item index,
2115
2107
// (String) comma-separated list of function generic param names]
@@ -2232,6 +2224,7 @@ class DocSearch {
2232
2224
// object defined above.
2233
2225
const itemParentIdx = itemParentIdxDecoder . next ( ) ;
2234
2226
normalizedName = word . indexOf ( "_" ) === - 1 ? word : word . replace ( / _ / g, "" ) ;
2227
+ /** @type {rustdoc.Row } */
2235
2228
const row = {
2236
2229
crate,
2237
2230
ty : itemTypes . charCodeAt ( i ) - 65 , // 65 = "A"
@@ -2274,16 +2267,14 @@ class DocSearch {
2274
2267
continue ;
2275
2268
}
2276
2269
2277
- // @ts -expect-error
2270
+ /** @type { number[] } */
2278
2271
let currentNameAliases ;
2279
2272
if ( currentCrateAliases . has ( alias_name ) ) {
2280
2273
currentNameAliases = currentCrateAliases . get ( alias_name ) ;
2281
2274
} else {
2282
2275
currentNameAliases = [ ] ;
2283
- // @ts -expect-error
2284
2276
currentCrateAliases . set ( alias_name , currentNameAliases ) ;
2285
2277
}
2286
- // @ts -expect-error
2287
2278
for ( const local_alias of aliases [ alias_name ] ) {
2288
2279
currentNameAliases . push ( local_alias + currentIndex ) ;
2289
2280
}
@@ -2326,15 +2317,13 @@ class DocSearch {
2326
2317
* @param {rustdoc.ParserQueryElement } elem
2327
2318
*/
2328
2319
function convertTypeFilterOnElem ( elem ) {
2329
- if ( elem . typeFilter !== null ) {
2320
+ if ( typeof elem . typeFilter === "string" ) {
2330
2321
let typeFilter = elem . typeFilter ;
2331
2322
if ( typeFilter === "const" ) {
2332
2323
typeFilter = "constant" ;
2333
2324
}
2334
- // @ts -expect-error
2335
2325
elem . typeFilter = itemTypeFromName ( typeFilter ) ;
2336
2326
} else {
2337
- // @ts -expect-error
2338
2327
elem . typeFilter = NO_TYPE_FILTER ;
2339
2328
}
2340
2329
for ( const elem2 of elem . generics ) {
@@ -2407,9 +2396,9 @@ class DocSearch {
2407
2396
continue ;
2408
2397
}
2409
2398
if ( ! foundStopChar ) {
2410
- let extra = "" ;
2399
+ /** @type String[] */
2400
+ let extra = [ ] ;
2411
2401
if ( isLastElemGeneric ( query . elems , parserState ) ) {
2412
- // @ts -expect-error
2413
2402
extra = [ " after " , ">" ] ;
2414
2403
} else if ( prevIs ( parserState , "\"" ) ) {
2415
2404
throw [ "Cannot have more than one element if you use quotes" ] ;
@@ -2547,7 +2536,7 @@ class DocSearch {
2547
2536
* See `buildTypeMapIndex` for more information.
2548
2537
*
2549
2538
* @param {rustdoc.QueryElement } elem
2550
- * @param {boolean } isAssocType
2539
+ * @param {boolean= } isAssocType
2551
2540
*/
2552
2541
const convertNameToId = ( elem , isAssocType ) => {
2553
2542
const loweredName = elem . pathLast . toLowerCase ( ) ;
@@ -2627,7 +2616,6 @@ class DocSearch {
2627
2616
] ;
2628
2617
}
2629
2618
for ( const elem2 of elem . generics ) {
2630
- // @ts -expect-error
2631
2619
convertNameToId ( elem2 ) ;
2632
2620
}
2633
2621
elem . bindings = new Map ( Array . from ( elem . bindings . entries ( ) )
@@ -2750,7 +2738,11 @@ class DocSearch {
2750
2738
return [ displayPath , href , `${ exactPath } ::${ name } ` ] ;
2751
2739
} ;
2752
2740
2753
- // @ts -expect-error
2741
+ /**
2742
+ *
2743
+ * @param {string } path
2744
+ * @returns {string }
2745
+ */
2754
2746
function pathSplitter ( path ) {
2755
2747
const tmp = "<span>" + path . replace ( / : : / g, "::</span><span>" ) ;
2756
2748
if ( tmp . endsWith ( "<span>" ) ) {
@@ -2763,9 +2755,9 @@ class DocSearch {
2763
2755
* Add extra data to result objects, and filter items that have been
2764
2756
* marked for removal.
2765
2757
*
2766
- * @param {[ rustdoc.ResultObject] } results
2758
+ * @param {rustdoc.ResultObject[ ] } results
2767
2759
* @param {"sig"|"elems"|"returned"|null } typeInfo
2768
- * @returns {[ rustdoc.ResultObject] }
2760
+ * @returns {rustdoc.ResultObject[ ] }
2769
2761
*/
2770
2762
const transformResults = ( results , typeInfo ) => {
2771
2763
const duplicates = new Set ( ) ;
@@ -2840,7 +2832,7 @@ class DocSearch {
2840
2832
}
2841
2833
let fnInputs = null ;
2842
2834
let fnOutput = null ;
2843
- // @ts -expect-error
2835
+ /** @type { Map<number, number> | null } */
2844
2836
let mgens = null ;
2845
2837
if ( typeInfo !== "elems" && typeInfo !== "returned" ) {
2846
2838
fnInputs = unifyFunctionTypes (
@@ -3053,7 +3045,6 @@ class DocSearch {
3053
3045
writeFn ( nested , result ) ;
3054
3046
}
3055
3047
return ;
3056
- // @ts -expect-error
3057
3048
} else if ( mgens ) {
3058
3049
for ( const [ queryId , fnId ] of mgens ) {
3059
3050
if ( fnId === fnType . id ) {
@@ -3069,7 +3060,7 @@ class DocSearch {
3069
3060
name : fnParamNames [ - 1 - fnType . id ] ,
3070
3061
highlighted : ! ! fnType . highlighted ,
3071
3062
} , result ) ;
3072
- // @ts -expect-error
3063
+ /** @type { string[] } */
3073
3064
const where = [ ] ;
3074
3065
onEachBtwn (
3075
3066
fnType . generics ,
@@ -3079,7 +3070,6 @@ class DocSearch {
3079
3070
( ) => pushText ( { name : " + " , highlighted : false } , where ) ,
3080
3071
) ;
3081
3072
if ( where . length > 0 ) {
3082
- // @ts -expect-error
3083
3073
whereClause . set ( fnParamNames [ - 1 - fnType . id ] , where ) ;
3084
3074
}
3085
3075
} else {
@@ -3181,7 +3171,7 @@ class DocSearch {
3181
3171
* @param {rustdoc.Results } results
3182
3172
* @param {"sig"|"elems"|"returned"|null } typeInfo
3183
3173
* @param {string } preferredCrate
3184
- * @returns {Promise<[ rustdoc.ResultObject]> }
3174
+ * @returns {Promise<rustdoc.ResultObject[ ]> }
3185
3175
*/
3186
3176
const sortResults = async ( results , typeInfo , preferredCrate ) => {
3187
3177
const userQuery = parsedQuery . userQuery ;
@@ -3337,7 +3327,6 @@ class DocSearch {
3337
3327
return 0 ;
3338
3328
} ) ;
3339
3329
3340
- // @ts -expect-error
3341
3330
return transformResults ( result_list , typeInfo ) ;
3342
3331
} ;
3343
3332
0 commit comments