@@ -59,7 +59,7 @@ use rustc_span::symbol::{sym, Symbol};
59
59
use serde:: ser:: SerializeSeq ;
60
60
use serde:: { Serialize , Serializer } ;
61
61
62
- use crate :: clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy } ;
62
+ use crate :: clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy , TypeKind } ;
63
63
use crate :: config:: RenderOptions ;
64
64
use crate :: docfs:: { DocFS , ErrorStorage , PathError } ;
65
65
use crate :: doctree;
@@ -303,8 +303,10 @@ impl Serialize for IndexItem {
303
303
/// A type used for the search index.
304
304
#[ derive( Debug ) ]
305
305
struct Type {
306
+ ty : Option < DefId > ,
307
+ idx : Option < usize > ,
306
308
name : Option < String > ,
307
- generics : Option < Vec < String > > ,
309
+ generics : Option < Vec < Generic > > ,
308
310
}
309
311
310
312
impl Serialize for Type {
@@ -314,7 +316,11 @@ impl Serialize for Type {
314
316
{
315
317
if let Some ( name) = & self . name {
316
318
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
+ }
318
324
if let Some ( generics) = & self . generics {
319
325
seq. serialize_element ( & generics) ?;
320
326
}
@@ -325,11 +331,32 @@ impl Serialize for Type {
325
331
}
326
332
}
327
333
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
+
328
355
/// Full type of functions/methods in the search index.
329
356
#[ derive( Debug ) ]
330
357
struct IndexItemFunctionType {
331
- inputs : Vec < Type > ,
332
- output : Option < Vec < Type > > ,
358
+ inputs : Vec < TypeWithKind > ,
359
+ output : Option < Vec < TypeWithKind > > ,
333
360
}
334
361
335
362
impl Serialize for IndexItemFunctionType {
@@ -340,8 +367,8 @@ impl Serialize for IndexItemFunctionType {
340
367
// If we couldn't figure out a type, just write `null`.
341
368
let mut iter = self . inputs . iter ( ) ;
342
369
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 ( ) ) ,
345
372
} {
346
373
serializer. serialize_none ( )
347
374
} else {
@@ -359,6 +386,34 @@ impl Serialize for IndexItemFunctionType {
359
386
}
360
387
}
361
388
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
+
362
417
thread_local ! ( static CACHE_KEY : RefCell <Arc <Cache >> = Default :: default ( ) ) ;
363
418
thread_local ! ( pub static CURRENT_DEPTH : Cell <usize > = Cell :: new( 0 ) ) ;
364
419
0 commit comments