@@ -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:: { OutputFormat , RenderOptions } ;
64
64
use crate :: docfs:: { DocFS , ErrorStorage , PathError } ;
65
65
use crate :: doctree;
@@ -304,8 +304,10 @@ impl Serialize for IndexItem {
304
304
/// A type used for the search index.
305
305
#[ derive( Debug ) ]
306
306
struct Type {
307
+ ty : Option < DefId > ,
308
+ idx : Option < usize > ,
307
309
name : Option < String > ,
308
- generics : Option < Vec < String > > ,
310
+ generics : Option < Vec < Generic > > ,
309
311
}
310
312
311
313
impl Serialize for Type {
@@ -315,7 +317,11 @@ impl Serialize for Type {
315
317
{
316
318
if let Some ( name) = & self . name {
317
319
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
+ }
319
325
if let Some ( generics) = & self . generics {
320
326
seq. serialize_element ( & generics) ?;
321
327
}
@@ -326,11 +332,32 @@ impl Serialize for Type {
326
332
}
327
333
}
328
334
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
+
329
356
/// Full type of functions/methods in the search index.
330
357
#[ derive( Debug ) ]
331
358
struct IndexItemFunctionType {
332
- inputs : Vec < Type > ,
333
- output : Option < Vec < Type > > ,
359
+ inputs : Vec < TypeWithKind > ,
360
+ output : Option < Vec < TypeWithKind > > ,
334
361
}
335
362
336
363
impl Serialize for IndexItemFunctionType {
@@ -341,8 +368,8 @@ impl Serialize for IndexItemFunctionType {
341
368
// If we couldn't figure out a type, just write `null`.
342
369
let mut iter = self . inputs . iter ( ) ;
343
370
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 ( ) ) ,
346
373
} {
347
374
serializer. serialize_none ( )
348
375
} else {
@@ -360,6 +387,34 @@ impl Serialize for IndexItemFunctionType {
360
387
}
361
388
}
362
389
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
+
363
418
thread_local ! ( static CACHE_KEY : RefCell <Arc <Cache >> = Default :: default ( ) ) ;
364
419
thread_local ! ( pub static CURRENT_DEPTH : Cell <usize > = Cell :: new( 0 ) ) ;
365
420
0 commit comments