@@ -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:: RenderOptions ;
6464use crate :: docfs:: { DocFS , ErrorStorage , PathError } ;
6565use crate :: doctree;
@@ -303,8 +303,10 @@ impl Serialize for IndexItem {
303303/// A type used for the search index.
304304#[ derive( Debug ) ]
305305struct Type {
306+ ty : Option < DefId > ,
307+ idx : Option < usize > ,
306308 name : Option < String > ,
307- generics : Option < Vec < String > > ,
309+ generics : Option < Vec < Generic > > ,
308310}
309311
310312impl Serialize for Type {
@@ -314,7 +316,11 @@ impl Serialize for Type {
314316 {
315317 if let Some ( name) = & self . name {
316318 let mut seq = serializer. serialize_seq ( None ) ?;
317- seq. serialize_element ( & name) ?;
319+ if let Some ( id) = self . idx {
320+ seq. serialize_element ( & id) ?;
321+ } else {
322+ seq. serialize_element ( & name) ?;
323+ }
318324 if let Some ( generics) = & self . generics {
319325 seq. serialize_element ( & generics) ?;
320326 }
@@ -325,11 +331,32 @@ impl Serialize for Type {
325331 }
326332}
327333
334+ /// A type used for the search index.
335+ #[ derive( Debug ) ]
336+ struct Generic {
337+ name : String ,
338+ defid : Option < DefId > ,
339+ idx : Option < usize > ,
340+ }
341+
342+ impl Serialize for Generic {
343+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
344+ where
345+ S : Serializer ,
346+ {
347+ if let Some ( id) = self . idx {
348+ serializer. serialize_some ( & id)
349+ } else {
350+ serializer. serialize_some ( & self . name )
351+ }
352+ }
353+ }
354+
328355/// Full type of functions/methods in the search index.
329356#[ derive( Debug ) ]
330357struct IndexItemFunctionType {
331- inputs : Vec < Type > ,
332- output : Option < Vec < Type > > ,
358+ inputs : Vec < TypeWithKind > ,
359+ output : Option < Vec < TypeWithKind > > ,
333360}
334361
335362impl Serialize for IndexItemFunctionType {
@@ -340,8 +367,8 @@ impl Serialize for IndexItemFunctionType {
340367 // If we couldn't figure out a type, just write `null`.
341368 let mut iter = self . inputs . iter ( ) ;
342369 if match self . output {
343- Some ( ref output) => iter. chain ( output. iter ( ) ) . any ( |ref i| i. name . is_none ( ) ) ,
344- None => iter. any ( |ref i| i. name . is_none ( ) ) ,
370+ Some ( ref output) => iter. chain ( output. iter ( ) ) . any ( |ref i| i. ty . name . is_none ( ) ) ,
371+ None => iter. any ( |ref i| i. ty . name . is_none ( ) ) ,
345372 } {
346373 serializer. serialize_none ( )
347374 } else {
@@ -359,6 +386,34 @@ impl Serialize for IndexItemFunctionType {
359386 }
360387}
361388
389+ #[ derive( Debug ) ]
390+ pub struct TypeWithKind {
391+ ty : Type ,
392+ kind : TypeKind ,
393+ }
394+
395+ impl From < ( Type , TypeKind ) > for TypeWithKind {
396+ fn from ( x : ( Type , TypeKind ) ) -> TypeWithKind {
397+ TypeWithKind {
398+ ty : x. 0 ,
399+ kind : x. 1 ,
400+ }
401+ }
402+ }
403+
404+ impl Serialize for TypeWithKind {
405+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
406+ where
407+ S : Serializer ,
408+ {
409+ let mut seq = serializer. serialize_seq ( None ) ?;
410+ seq. serialize_element ( & self . ty . name ) ?;
411+ let x: ItemType = self . kind . into ( ) ;
412+ seq. serialize_element ( & x) ?;
413+ seq. end ( )
414+ }
415+ }
416+
362417thread_local ! ( static CACHE_KEY : RefCell <Arc <Cache >> = Default :: default ( ) ) ;
363418thread_local ! ( pub static CURRENT_DEPTH : Cell <usize > = Cell :: new( 0 ) ) ;
364419
0 commit comments