@@ -49,6 +49,7 @@ use encode::{bitmap_to_string, write_vlqhex_to_string};
49
49
pub ( crate ) struct SerializedSearchIndex {
50
50
pub ( crate ) index : String ,
51
51
pub ( crate ) desc : Vec < ( usize , String ) > ,
52
+ pub ( crate ) param_names : String ,
52
53
}
53
54
54
55
const DESC_INDEX_SHARD_LEN : usize = 128 * 1024 ;
@@ -681,6 +682,23 @@ pub(crate) fn build_index<'tcx>(
681
682
desc. iter( ) . map( |( len, _) | * len) . sum:: <usize >( ) + empty_desc. len( )
682
683
) ;
683
684
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
+
684
702
// The index, which is actually used to search, is JSON
685
703
// It uses `JSON.parse(..)` to actually load, since JSON
686
704
// parses faster than the full JavaScript syntax.
@@ -702,7 +720,7 @@ pub(crate) fn build_index<'tcx>(
702
720
// We need to escape double quotes for the JSON.
703
721
. replace( "\\ \" " , "\\ \\ \" " )
704
722
) ;
705
- SerializedSearchIndex { index, desc }
723
+ SerializedSearchIndex { index, desc, param_names }
706
724
}
707
725
708
726
pub ( crate ) fn get_function_type_for_search < ' tcx > (
@@ -738,7 +756,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
738
756
None
739
757
}
740
758
} ) ;
741
- let ( mut inputs, mut output, where_clause) = match * item. kind {
759
+ let ( mut inputs, mut output, param_names , where_clause) = match * item. kind {
742
760
clean:: FunctionItem ( ref f) | clean:: MethodItem ( ref f, _) | clean:: TyMethodItem ( ref f) => {
743
761
get_fn_inputs_and_outputs ( f, tcx, impl_or_trait_generics, cache)
744
762
}
@@ -748,7 +766,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
748
766
inputs. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
749
767
output. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
750
768
751
- Some ( IndexItemFunctionType { inputs, output, where_clause } )
769
+ Some ( IndexItemFunctionType { inputs, output, where_clause, param_names } )
752
770
}
753
771
754
772
fn get_index_type (
@@ -1250,7 +1268,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
1250
1268
tcx : TyCtxt < ' tcx > ,
1251
1269
impl_or_trait_generics : Option < & ( clean:: Type , clean:: Generics ) > ,
1252
1270
cache : & Cache ,
1253
- ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Vec < RenderType > > ) {
1271
+ ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Symbol > , Vec < Vec < RenderType > > ) {
1254
1272
let decl = & func. decl ;
1255
1273
1256
1274
let mut rgen: FxHashMap < SimplifiedParam , ( isize , Vec < RenderType > ) > = Default :: default ( ) ;
@@ -1296,7 +1314,21 @@ fn get_fn_inputs_and_outputs<'tcx>(
1296
1314
let mut ret_types = Vec :: new ( ) ;
1297
1315
simplify_fn_type ( self_, generics, & decl. output , tcx, 0 , & mut ret_types, & mut rgen, true , cache) ;
1298
1316
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
+ )
1302
1334
}
0 commit comments