@@ -48,6 +48,7 @@ use crate::html::render::{self, IndexItem, IndexItemFunctionType, RenderType, Re
48
48
pub ( crate ) struct SerializedSearchIndex {
49
49
pub ( crate ) index : String ,
50
50
pub ( crate ) desc : Vec < ( usize , String ) > ,
51
+ pub ( crate ) param_names : String ,
51
52
}
52
53
53
54
const DESC_INDEX_SHARD_LEN : usize = 128 * 1024 ;
@@ -680,6 +681,23 @@ pub(crate) fn build_index<'tcx>(
680
681
desc. iter( ) . map( |( len, _) | * len) . sum:: <usize >( ) + empty_desc. len( )
681
682
) ;
682
683
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
+
683
701
// The index, which is actually used to search, is JSON
684
702
// It uses `JSON.parse(..)` to actually load, since JSON
685
703
// parses faster than the full JavaScript syntax.
@@ -701,7 +719,7 @@ pub(crate) fn build_index<'tcx>(
701
719
// We need to escape double quotes for the JSON.
702
720
. replace( "\\ \" " , "\\ \\ \" " )
703
721
) ;
704
- SerializedSearchIndex { index, desc }
722
+ SerializedSearchIndex { index, desc, param_names }
705
723
}
706
724
707
725
pub ( crate ) fn get_function_type_for_search < ' tcx > (
@@ -737,7 +755,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
737
755
None
738
756
}
739
757
} ) ;
740
- let ( mut inputs, mut output, where_clause) = match * item. kind {
758
+ let ( mut inputs, mut output, param_names , where_clause) = match * item. kind {
741
759
clean:: FunctionItem ( ref f) | clean:: MethodItem ( ref f, _) | clean:: TyMethodItem ( ref f) => {
742
760
get_fn_inputs_and_outputs ( f, tcx, impl_or_trait_generics, cache)
743
761
}
@@ -747,7 +765,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
747
765
inputs. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
748
766
output. retain ( |a| a. id . is_some ( ) || a. generics . is_some ( ) ) ;
749
767
750
- Some ( IndexItemFunctionType { inputs, output, where_clause } )
768
+ Some ( IndexItemFunctionType { inputs, output, where_clause, param_names } )
751
769
}
752
770
753
771
fn get_index_type (
@@ -1262,7 +1280,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
1262
1280
tcx : TyCtxt < ' tcx > ,
1263
1281
impl_or_trait_generics : Option < & ( clean:: Type , clean:: Generics ) > ,
1264
1282
cache : & Cache ,
1265
- ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Vec < RenderType > > ) {
1283
+ ) -> ( Vec < RenderType > , Vec < RenderType > , Vec < Symbol > , Vec < Vec < RenderType > > ) {
1266
1284
let decl = & func. decl ;
1267
1285
1268
1286
let mut rgen: FxHashMap < SimplifiedParam , ( isize , Vec < RenderType > ) > = Default :: default ( ) ;
@@ -1308,7 +1326,21 @@ fn get_fn_inputs_and_outputs<'tcx>(
1308
1326
let mut ret_types = Vec :: new ( ) ;
1309
1327
simplify_fn_type ( self_, generics, & decl. output , tcx, 0 , & mut ret_types, & mut rgen, true , cache) ;
1310
1328
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
+ )
1314
1346
}
0 commit comments