@@ -59,7 +59,7 @@ use rustc_span::symbol::{sym, Symbol};
5959use serde:: ser:: SerializeSeq ;
6060use serde:: { Serialize , Serializer } ;
6161
62- use crate :: clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy } ;
62+ use crate :: clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy , TypeKind } ;
6363use crate :: config:: { OutputFormat , RenderOptions } ;
6464use crate :: docfs:: { DocFS , ErrorStorage , PathError } ;
6565use crate :: doctree;
@@ -304,8 +304,10 @@ impl Serialize for IndexItem {
304304/// A type used for the search index.
305305#[ derive( Debug ) ]
306306struct Type {
307+ ty : Option < DefId > ,
308+ idx : Option < usize > ,
307309 name : Option < String > ,
308- generics : Option < Vec < String > > ,
310+ generics : Option < Vec < Generic > > ,
309311}
310312
311313impl Serialize for Type {
@@ -315,7 +317,11 @@ impl Serialize for Type {
315317 {
316318 if let Some ( name) = & self . name {
317319 let mut seq = serializer. serialize_seq ( None ) ?;
318- seq. serialize_element ( & name) ?;
320+ if let Some ( id) = self . idx {
321+ seq. serialize_element ( & id) ?;
322+ } else {
323+ seq. serialize_element ( & name) ?;
324+ }
319325 if let Some ( generics) = & self . generics {
320326 seq. serialize_element ( & generics) ?;
321327 }
@@ -326,11 +332,32 @@ impl Serialize for Type {
326332 }
327333}
328334
335+ /// A type used for the search index.
336+ #[ derive( Debug ) ]
337+ struct Generic {
338+ name : String ,
339+ defid : Option < DefId > ,
340+ idx : Option < usize > ,
341+ }
342+
343+ impl Serialize for Generic {
344+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
345+ where
346+ S : Serializer ,
347+ {
348+ if let Some ( id) = self . idx {
349+ serializer. serialize_some ( & id)
350+ } else {
351+ serializer. serialize_some ( & self . name )
352+ }
353+ }
354+ }
355+
329356/// Full type of functions/methods in the search index.
330357#[ derive( Debug ) ]
331358struct IndexItemFunctionType {
332- inputs : Vec < Type > ,
333- output : Option < Vec < Type > > ,
359+ inputs : Vec < TypeWithKind > ,
360+ output : Option < Vec < TypeWithKind > > ,
334361}
335362
336363impl Serialize for IndexItemFunctionType {
@@ -341,8 +368,8 @@ impl Serialize for IndexItemFunctionType {
341368 // If we couldn't figure out a type, just write `null`.
342369 let mut iter = self . inputs . iter ( ) ;
343370 if match self . output {
344- Some ( ref output) => iter. chain ( output. iter ( ) ) . any ( |ref i| i. name . is_none ( ) ) ,
345- None => iter. any ( |ref i| i. name . is_none ( ) ) ,
371+ Some ( ref output) => iter. chain ( output. iter ( ) ) . any ( |ref i| i. ty . name . is_none ( ) ) ,
372+ None => iter. any ( |ref i| i. ty . name . is_none ( ) ) ,
346373 } {
347374 serializer. serialize_none ( )
348375 } else {
@@ -360,6 +387,34 @@ impl Serialize for IndexItemFunctionType {
360387 }
361388}
362389
390+ #[ derive( Debug ) ]
391+ pub struct TypeWithKind {
392+ ty : Type ,
393+ kind : TypeKind ,
394+ }
395+
396+ impl From < ( Type , TypeKind ) > for TypeWithKind {
397+ fn from ( x : ( Type , TypeKind ) ) -> TypeWithKind {
398+ TypeWithKind {
399+ ty : x. 0 ,
400+ kind : x. 1 ,
401+ }
402+ }
403+ }
404+
405+ impl Serialize for TypeWithKind {
406+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
407+ where
408+ S : Serializer ,
409+ {
410+ let mut seq = serializer. serialize_seq ( None ) ?;
411+ seq. serialize_element ( & self . ty . name ) ?;
412+ let x: ItemType = self . kind . into ( ) ;
413+ seq. serialize_element ( & x) ?;
414+ seq. end ( )
415+ }
416+ }
417+
363418thread_local ! ( static CACHE_KEY : RefCell <Arc <Cache >> = Default :: default ( ) ) ;
364419thread_local ! ( pub static CURRENT_DEPTH : Cell <usize > = Cell :: new( 0 ) ) ;
365420
0 commit comments