@@ -1755,17 +1755,26 @@ function initSearch(rawSearchIndex) {
17551755 if ( mgens && mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
17561756 return false ;
17571757 }
1758+ // Where clauses can represent cyclical data.
1759+ // `null` prevents it from trying to unbox in an infinite loop
1760+ const mgensTmp = new Map ( mgens ) ;
1761+ mgensTmp . set ( fnType . id , null ) ;
17581762 // This is only a potential unbox if the search query appears in the where clause
17591763 // for example, searching `Read -> usize` should find
17601764 // `fn read_all<R: Read>(R) -> Result<usize>`
17611765 // generic `R` is considered "unboxed"
1762- return checkIfInList ( whereClause [ ( - fnType . id ) - 1 ] , queryElem , whereClause ) ;
1766+ return checkIfInList (
1767+ whereClause [ ( - fnType . id ) - 1 ] ,
1768+ queryElem ,
1769+ whereClause ,
1770+ mgensTmp
1771+ ) ;
17631772 } else if ( fnType . generics . length > 0 || fnType . bindings . size > 0 ) {
17641773 const simplifiedGenerics = [
17651774 ...fnType . generics ,
17661775 ...Array . from ( fnType . bindings . values ( ) ) . flat ( ) ,
17671776 ] ;
1768- return checkIfInList ( simplifiedGenerics , queryElem , whereClause ) ;
1777+ return checkIfInList ( simplifiedGenerics , queryElem , whereClause , mgens ) ;
17691778 }
17701779 return false ;
17711780 }
@@ -1777,12 +1786,13 @@ function initSearch(rawSearchIndex) {
17771786 * @param {Array<FunctionType> } list
17781787 * @param {QueryElement } elem - The element from the parsed query.
17791788 * @param {[FunctionType] } whereClause - Trait bounds for generic items.
1789+ * @param {Map<number,number>|null } mgens - Map functions generics to query generics.
17801790 *
17811791 * @return {boolean } - Returns true if found, false otherwise.
17821792 */
1783- function checkIfInList ( list , elem , whereClause ) {
1793+ function checkIfInList ( list , elem , whereClause , mgens ) {
17841794 for ( const entry of list ) {
1785- if ( checkType ( entry , elem , whereClause ) ) {
1795+ if ( checkType ( entry , elem , whereClause , mgens ) ) {
17861796 return true ;
17871797 }
17881798 }
@@ -1796,23 +1806,29 @@ function initSearch(rawSearchIndex) {
17961806 * @param {Row } row
17971807 * @param {QueryElement } elem - The element from the parsed query.
17981808 * @param {[FunctionType] } whereClause - Trait bounds for generic items.
1809+ * @param {Map<number,number>|null } mgens - Map functions generics to query generics.
17991810 *
18001811 * @return {boolean } - Returns true if the type matches, false otherwise.
18011812 */
1802- function checkType ( row , elem , whereClause ) {
1813+ function checkType ( row , elem , whereClause , mgens ) {
18031814 if ( row . bindings . size === 0 && elem . bindings . size === 0 ) {
18041815 if ( elem . id < 0 ) {
1805- return row . id < 0 || checkIfInList ( row . generics , elem , whereClause ) ;
1816+ return row . id < 0 || checkIfInList ( row . generics , elem , whereClause , mgens ) ;
18061817 }
18071818 if ( row . id > 0 && elem . id > 0 && elem . pathWithoutLast . length === 0 &&
18081819 typePassesFilter ( elem . typeFilter , row . ty ) && elem . generics . length === 0 &&
18091820 // special case
18101821 elem . id !== typeNameIdOfArrayOrSlice
18111822 ) {
1812- return row . id === elem . id || checkIfInList ( row . generics , elem , whereClause ) ;
1823+ return row . id === elem . id || checkIfInList (
1824+ row . generics ,
1825+ elem ,
1826+ whereClause ,
1827+ mgens
1828+ ) ;
18131829 }
18141830 }
1815- return unifyFunctionTypes ( [ row ] , [ elem ] , whereClause ) ;
1831+ return unifyFunctionTypes ( [ row ] , [ elem ] , whereClause , mgens ) ;
18161832 }
18171833
18181834 function checkPath ( contains , ty , maxEditDistance ) {
0 commit comments