@@ -48,6 +48,7 @@ use crate::html::render::{self, IndexItem, IndexItemFunctionType, RenderType, Re
4848pub ( crate ) struct SerializedSearchIndex {
4949 pub ( crate ) index : String ,
5050 pub ( crate ) desc : Vec < ( usize , String ) > ,
51+ pub ( crate ) param_names : String ,
5152}
5253
5354const DESC_INDEX_SHARD_LEN : usize = 128 * 1024 ;
@@ -680,6 +681,23 @@ pub(crate) fn build_index<'tcx>(
680681 desc. iter( ) . map( |( len, _) | * len) . sum:: <usize >( ) + empty_desc. len( )
681682 ) ;
682683
684+ let param_names = {
685+ let result: Vec < Vec < & str > > = crate_items
686+ . iter ( )
687+ . map ( |item| match & item. search_type {
688+ Some ( ty) => ty. param_names . iter ( ) . map ( |sym| sym. as_str ( ) ) . collect ( ) ,
689+ None => Vec :: new ( ) ,
690+ } )
691+ . collect ( ) ;
692+ serde_json:: to_string ( & result)
693+ . expect ( "failed serde conversion" )
694+ // All these `replace` calls are because we have to go through JS string for JSON content.
695+ . replace ( '\\' , r"\\" )
696+ . replace ( '\'' , r"\'" )
697+ // We need to escape double quotes for the JSON.
698+ . replace ( "\\ \" " , "\\ \\ \" " )
699+ } ;
700+
683701 // The index, which is actually used to search, is JSON
684702 // It uses `JSON.parse(..)` to actually load, since JSON
685703 // parses faster than the full JavaScript syntax.
@@ -701,7 +719,7 @@ pub(crate) fn build_index<'tcx>(
701719 // We need to escape double quotes for the JSON.
702720 . replace( "\\ \" " , "\\ \\ \" " )
703721 ) ;
704- SerializedSearchIndex { index, desc }
722+ SerializedSearchIndex { index, desc, param_names }
705723}
706724
707725pub ( crate ) fn get_function_type_for_search < ' tcx > (
@@ -737,7 +755,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
737755 None
738756 }
739757 } ) ;
740- let ( mut inputs, mut output, where_clause) = match * item. kind {
758+ let ( mut inputs, mut output, param_names , where_clause) = match * item. kind {
741759 clean:: FunctionItem ( ref f) | clean:: MethodItem ( ref f, _) | clean:: TyMethodItem ( ref f) => {
742760 get_fn_inputs_and_outputs ( f, tcx, impl_or_trait_generics, cache)
743761 }
@@ -747,7 +765,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
747765 inputs. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
748766 output. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
749767
750- Some ( IndexItemFunctionType { inputs, output, where_clause } )
768+ Some ( IndexItemFunctionType { inputs, output, where_clause, param_names } )
751769}
752770
753771fn get_index_type (
@@ -1262,7 +1280,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
12621280 tcx : TyCtxt < ' tcx > ,
12631281 impl_or_trait_generics : Option < & ( clean:: Type , clean:: Generics ) > ,
12641282 cache : & Cache ,
1265- ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Vec < RenderType > > ) {
1283+ ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Symbol > , Vec < Vec < RenderType > > ) {
12661284 let decl = & func. decl ;
12671285
12681286 let mut rgen: FxHashMap < SimplifiedParam , ( isize , Vec < RenderType > ) > = Default :: default ( ) ;
@@ -1308,7 +1326,21 @@ fn get_fn_inputs_and_outputs<'tcx>(
13081326 let mut ret_types = Vec :: new ( ) ;
13091327 simplify_fn_type ( self_, generics, & decl. output , tcx, 0 , & mut ret_types, & mut rgen, true , cache) ;
13101328
1311- let mut simplified_params = rgen. into_values ( ) . collect :: < Vec < _ > > ( ) ;
1312- simplified_params. sort_by_key ( |( idx, _) | -idx) ;
1313- ( arg_types, ret_types, simplified_params. into_iter ( ) . map ( |( _idx, traits) | traits) . collect ( ) )
1329+ let mut simplified_params = rgen. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
1330+ simplified_params. sort_by_key ( |( _, ( idx, _) ) | -idx) ;
1331+ (
1332+ arg_types,
1333+ ret_types,
1334+ simplified_params
1335+ . iter ( )
1336+ . map ( |( name, ( _idx, _traits) ) | match name {
1337+ SimplifiedParam :: Symbol ( name) => * name,
1338+ SimplifiedParam :: Anonymous ( _) => kw:: Empty ,
1339+ SimplifiedParam :: AssociatedType ( def_id, name) => {
1340+ Symbol :: intern ( & format ! ( "{}::{}" , tcx. item_name( * def_id) , name) )
1341+ }
1342+ } )
1343+ . collect ( ) ,
1344+ simplified_params. into_iter ( ) . map ( |( _name, ( _idx, traits) ) | traits) . collect ( ) ,
1345+ )
13141346}
0 commit comments