@@ -49,6 +49,7 @@ use encode::{bitmap_to_string, write_vlqhex_to_string};
4949pub ( crate ) struct SerializedSearchIndex {
5050 pub ( crate ) index : String ,
5151 pub ( crate ) desc : Vec < ( usize , String ) > ,
52+ pub ( crate ) param_names : String ,
5253}
5354
5455const DESC_INDEX_SHARD_LEN : usize = 128 * 1024 ;
@@ -681,6 +682,23 @@ pub(crate) fn build_index<'tcx>(
681682 desc. iter( ) . map( |( len, _) | * len) . sum:: <usize >( ) + empty_desc. len( )
682683 ) ;
683684
685+ let param_names = {
686+ let result: Vec < Vec < & str > > = crate_items
687+ . iter ( )
688+ . map ( |item| match & item. search_type {
689+ Some ( ty) => ty. param_names . iter ( ) . map ( |sym| sym. as_str ( ) ) . collect ( ) ,
690+ None => Vec :: new ( ) ,
691+ } )
692+ . collect ( ) ;
693+ serde_json:: to_string ( & result)
694+ . expect ( "failed serde conversion" )
695+ // All these `replace` calls are because we have to go through JS string for JSON content.
696+ . replace ( '\\' , r"\\" )
697+ . replace ( '\'' , r"\'" )
698+ // We need to escape double quotes for the JSON.
699+ . replace ( "\\ \" " , "\\ \\ \" " )
700+ } ;
701+
684702 // The index, which is actually used to search, is JSON
685703 // It uses `JSON.parse(..)` to actually load, since JSON
686704 // parses faster than the full JavaScript syntax.
@@ -702,7 +720,7 @@ pub(crate) fn build_index<'tcx>(
702720 // We need to escape double quotes for the JSON.
703721 . replace( "\\ \" " , "\\ \\ \" " )
704722 ) ;
705- SerializedSearchIndex { index, desc }
723+ SerializedSearchIndex { index, desc, param_names }
706724}
707725
708726pub ( crate ) fn get_function_type_for_search < ' tcx > (
@@ -738,7 +756,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
738756 None
739757 }
740758 } ) ;
741- let ( mut inputs, mut output, where_clause) = match * item. kind {
759+ let ( mut inputs, mut output, param_names , where_clause) = match * item. kind {
742760 clean:: FunctionItem ( ref f) | clean:: MethodItem ( ref f, _) | clean:: TyMethodItem ( ref f) => {
743761 get_fn_inputs_and_outputs ( f, tcx, impl_or_trait_generics, cache)
744762 }
@@ -748,7 +766,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
748766 inputs. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
749767 output. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
750768
751- Some ( IndexItemFunctionType { inputs, output, where_clause } )
769+ Some ( IndexItemFunctionType { inputs, output, where_clause, param_names } )
752770}
753771
754772fn get_index_type (
@@ -1250,7 +1268,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
12501268 tcx : TyCtxt < ' tcx > ,
12511269 impl_or_trait_generics : Option < & ( clean:: Type , clean:: Generics ) > ,
12521270 cache : & Cache ,
1253- ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Vec < RenderType > > ) {
1271+ ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Symbol > , Vec < Vec < RenderType > > ) {
12541272 let decl = & func. decl ;
12551273
12561274 let mut rgen: FxHashMap < SimplifiedParam , ( isize , Vec < RenderType > ) > = Default :: default ( ) ;
@@ -1296,7 +1314,21 @@ fn get_fn_inputs_and_outputs<'tcx>(
12961314 let mut ret_types = Vec :: new ( ) ;
12971315 simplify_fn_type ( self_, generics, & decl. output , tcx, 0 , & mut ret_types, & mut rgen, true , cache) ;
12981316
1299- let mut simplified_params = rgen. into_values ( ) . collect :: < Vec < _ > > ( ) ;
1300- simplified_params. sort_by_key ( |( idx, _) | -idx) ;
1301- ( arg_types, ret_types, simplified_params. into_iter ( ) . map ( |( _idx, traits) | traits) . collect ( ) )
1317+ let mut simplified_params = rgen. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
1318+ simplified_params. sort_by_key ( |( _, ( idx, _) ) | -idx) ;
1319+ (
1320+ arg_types,
1321+ ret_types,
1322+ simplified_params
1323+ . iter ( )
1324+ . map ( |( name, ( _idx, _traits) ) | match name {
1325+ SimplifiedParam :: Symbol ( name) => * name,
1326+ SimplifiedParam :: Anonymous ( _) => kw:: Empty ,
1327+ SimplifiedParam :: AssociatedType ( def_id, name) => {
1328+ Symbol :: intern ( & format ! ( "{}::{}" , tcx. item_name( * def_id) , name) )
1329+ }
1330+ } )
1331+ . collect ( ) ,
1332+ simplified_params. into_iter ( ) . map ( |( _name, ( _idx, traits) ) | traits) . collect ( ) ,
1333+ )
13021334}
0 commit comments