@@ -1489,7 +1489,16 @@ function initSearch(rawSearchIndex) {
1489
1489
1490
1490
const fnParamNames = ( await searchState . loadParamNames ( obj . crate ) ) [ obj . bitIndex - 1 ] ;
1491
1491
const queryParamNames = [ ] ;
1492
- /** @param {QueryElement } queryElem */
1492
+ /**
1493
+ * Recursively writes a map of IDs to query generic names,
1494
+ * which are later used to map query generic names to function generic names.
1495
+ * For example, when the user writes `X -> Option<X>` and the function
1496
+ * is actually written as `T -> Option<T>`, this function stores the
1497
+ * mapping `(-1, "X")`, and the writeFn function looks up the entry
1498
+ * for -1 to form the final, user-visible mapping of "X is T".
1499
+ *
1500
+ * @param {QueryElement } queryElem
1501
+ */
1493
1502
function remapQuery ( queryElem ) {
1494
1503
if ( queryElem . id < 0 ) {
1495
1504
queryParamNames [ - 1 - queryElem . id ] = queryElem . name ;
@@ -1503,9 +1512,22 @@ function initSearch(rawSearchIndex) {
1503
1512
}
1504
1513
parsedQuery . elems . forEach ( remapQuery ) ;
1505
1514
parsedQuery . returned . forEach ( remapQuery ) ;
1515
+ /**
1516
+ * Write text to a highlighting array.
1517
+ * Index 0 is not highlighted, index 1 is highlighted,
1518
+ * index 2 is not highlighted, etc.
1519
+ *
1520
+ * @param {{name: string, highlighted: bool|undefined} } fnType - input
1521
+ * @param {[string] } result
1522
+ */
1506
1523
function pushText ( fnType , result ) {
1507
1524
// If !!(result.length % 2) == false, then pushing a new slot starts an even
1508
1525
// numbered slot. Even numbered slots are not highlighted.
1526
+ //
1527
+ // `highlighted` will not be defined if an entire subtree is not highlighted,
1528
+ // so `!!` is used to coerce it to boolean. `result.length % 2` is used to
1529
+ // check if the number is even, but it evaluates to a number, so it also
1530
+ // needs coerced to a boolean.
1509
1531
if ( ! ! ( result . length % 2 ) === ! ! fnType . highlighted ) {
1510
1532
result . push ( "" ) ;
1511
1533
} else if ( result . length === 0 && ! ! fnType . highlighted ) {
@@ -1514,6 +1536,13 @@ function initSearch(rawSearchIndex) {
1514
1536
}
1515
1537
result [ result . length - 1 ] += fnType . name ;
1516
1538
}
1539
+ /**
1540
+ * Write a higher order function type: either a function pointer
1541
+ * or a trait bound on Fn, FnMut, or FnOnce.
1542
+ *
1543
+ * @param {FunctionType } fnType - input
1544
+ * @param {[string] } result
1545
+ */
1517
1546
function writeHof ( fnType , result ) {
1518
1547
const hofOutput = fnType . bindings . get ( typeNameIdOfOutput ) || [ ] ;
1519
1548
const hofInputs = fnType . generics ;
@@ -1547,6 +1576,10 @@ function initSearch(rawSearchIndex) {
1547
1576
}
1548
1577
}
1549
1578
/**
1579
+ * Write a type. This function checks for special types,
1580
+ * like slices, with their own formatting. It also handles
1581
+ * updating the where clause and generic type param map.
1582
+ *
1550
1583
* @param {FunctionType } fnType
1551
1584
* @param {[string] } result
1552
1585
*/
@@ -2397,15 +2430,15 @@ function initSearch(rawSearchIndex) {
2397
2430
if ( row . id > 0 && elem . id > 0 && elem . pathWithoutLast . length === 0 &&
2398
2431
row . generics . length === 0 && elem . generics . length === 0 &&
2399
2432
row . bindings . size === 0 && elem . bindings . size === 0 &&
2400
- // special case
2433
+ // special case for types that can be matched without actually
2434
+ // using the heavyweight unification machinery
2401
2435
elem . id !== typeNameIdOfArrayOrSlice &&
2402
2436
elem . id !== typeNameIdOfHof &&
2403
2437
elem . id !== typeNameIdOfTupleOrUnit
2404
2438
) {
2405
2439
return row . id === elem . id && typePassesFilter ( elem . typeFilter , row . ty ) ;
2406
- } else {
2407
- return unifyFunctionTypes ( [ row ] , [ elem ] , whereClause , mgens , null , unboxingDepth ) ;
2408
2440
}
2441
+ return unifyFunctionTypes ( [ row ] , [ elem ] , whereClause , mgens , null , unboxingDepth ) ;
2409
2442
}
2410
2443
2411
2444
/**
0 commit comments