@@ -120,7 +120,7 @@ crate struct Cache {
120
120
121
121
/// Aliases added through `#[doc(alias = "...")]`. Since a few items can have the same alias,
122
122
/// we need the alias element to have an array of items.
123
- pub ( super ) aliases : FxHashMap < String , Vec < IndexItem > > ,
123
+ pub ( super ) aliases : FxHashMap < String , Vec < usize > > ,
124
124
}
125
125
126
126
impl Cache {
@@ -311,7 +311,7 @@ impl DocFolder for Cache {
311
311
} ;
312
312
313
313
match parent {
314
- ( parent, Some ( path) ) if is_inherent_impl_item || ( !self . stripped_mod ) => {
314
+ ( parent, Some ( path) ) if is_inherent_impl_item || !self . stripped_mod => {
315
315
debug_assert ! ( !item. is_stripped( ) ) ;
316
316
317
317
// A crate has a module at its root, containing all items,
@@ -327,6 +327,21 @@ impl DocFolder for Cache {
327
327
parent_idx : None ,
328
328
search_type : get_index_search_type ( & item) ,
329
329
} ) ;
330
+
331
+ for alias in item
332
+ . attrs
333
+ . lists ( sym:: doc)
334
+ . filter ( |a| a. check_name ( sym:: alias) )
335
+ . filter_map ( |a| a. value_str ( ) . map ( |s| s. to_string ( ) . replace ( "\" " , "" ) ) )
336
+ . filter ( |v| !v. is_empty ( ) )
337
+ . collect :: < FxHashSet < _ > > ( )
338
+ . into_iter ( )
339
+ {
340
+ self . aliases
341
+ . entry ( alias. to_lowercase ( ) )
342
+ . or_insert ( Vec :: with_capacity ( 1 ) )
343
+ . push ( self . search_index . len ( ) - 1 ) ;
344
+ }
330
345
}
331
346
}
332
347
( Some ( parent) , None ) if is_inherent_impl_item => {
@@ -363,6 +378,9 @@ impl DocFolder for Cache {
363
378
| clean:: MacroItem ( ..)
364
379
| clean:: ProcMacroItem ( ..)
365
380
| clean:: VariantItem ( ..)
381
+ | clean:: StructFieldItem ( ..)
382
+ | clean:: TyMethodItem ( ..)
383
+ | clean:: MethodItem ( ..)
366
384
if !self . stripped_mod =>
367
385
{
368
386
// Re-exported items mean that the same id can show up twice
@@ -376,11 +394,8 @@ impl DocFolder for Cache {
376
394
{
377
395
self . paths . insert ( item. def_id , ( self . stack . clone ( ) , item. type_ ( ) ) ) ;
378
396
}
379
- self . add_aliases ( & item) ;
380
397
}
381
-
382
398
clean:: PrimitiveItem ( ..) => {
383
- self . add_aliases ( & item) ;
384
399
self . paths . insert ( item. def_id , ( self . stack . clone ( ) , item. type_ ( ) ) ) ;
385
400
}
386
401
@@ -489,36 +504,23 @@ impl DocFolder for Cache {
489
504
}
490
505
491
506
impl Cache {
492
- fn add_aliases ( & mut self , item : & clean:: Item ) {
493
- if item. def_id . index == CRATE_DEF_INDEX {
494
- return ;
495
- }
496
- if let Some ( ref item_name) = item. name {
497
- let path = self
498
- . paths
499
- . get ( & item. def_id )
500
- . map ( |p| p. 0 [ ..p. 0 . len ( ) - 1 ] . join ( "::" ) )
501
- . unwrap_or ( "std" . to_owned ( ) ) ;
502
- for alias in item
503
- . attrs
504
- . lists ( sym:: doc)
505
- . filter ( |a| a. check_name ( sym:: alias) )
506
- . filter_map ( |a| a. value_str ( ) . map ( |s| s. to_string ( ) . replace ( "\" " , "" ) ) )
507
- . filter ( |v| !v. is_empty ( ) )
508
- . collect :: < FxHashSet < _ > > ( )
509
- . into_iter ( )
510
- {
511
- self . aliases . entry ( alias) . or_insert ( Vec :: with_capacity ( 1 ) ) . push ( IndexItem {
512
- ty : item. type_ ( ) ,
513
- name : item_name. to_string ( ) ,
514
- path : path. clone ( ) ,
515
- desc : shorten ( plain_summary_line ( item. doc_value ( ) ) ) ,
516
- parent : None ,
517
- parent_idx : None ,
518
- search_type : get_index_search_type ( & item) ,
519
- } ) ;
520
- }
521
- }
507
+ pub fn get_aliases < ' a > ( & ' a self ) -> FxHashMap < String , Vec < & ' a IndexItem > > {
508
+ self . aliases
509
+ . iter ( )
510
+ . map ( |( k, values) | {
511
+ (
512
+ k. clone ( ) ,
513
+ values
514
+ . iter ( )
515
+ . filter ( |v| {
516
+ let x = & self . search_index [ * * v] ;
517
+ x. parent_idx . is_some ( ) == x. parent . is_some ( )
518
+ } )
519
+ . map ( |v| & self . search_index [ * v] )
520
+ . collect :: < Vec < _ > > ( ) ,
521
+ )
522
+ } )
523
+ . collect ( )
522
524
}
523
525
}
524
526
@@ -567,7 +569,8 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
567
569
let mut crate_items = Vec :: with_capacity ( cache. search_index . len ( ) ) ;
568
570
let mut crate_paths = vec ! [ ] ;
569
571
570
- let Cache { ref mut search_index, ref orphan_impl_items, ref paths, .. } = * cache;
572
+ let Cache { ref mut search_index, ref orphan_impl_items, ref paths, ref mut aliases, .. } =
573
+ * cache;
571
574
572
575
// Attach all orphan items to the type's definition if the type
573
576
// has since been learned.
@@ -582,6 +585,20 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
582
585
parent_idx : None ,
583
586
search_type : get_index_search_type ( & item) ,
584
587
} ) ;
588
+ for alias in item
589
+ . attrs
590
+ . lists ( sym:: doc)
591
+ . filter ( |a| a. check_name ( sym:: alias) )
592
+ . filter_map ( |a| a. value_str ( ) . map ( |s| s. to_string ( ) . replace ( "\" " , "" ) ) )
593
+ . filter ( |v| !v. is_empty ( ) )
594
+ . collect :: < FxHashSet < _ > > ( )
595
+ . into_iter ( )
596
+ {
597
+ aliases
598
+ . entry ( alias. to_lowercase ( ) )
599
+ . or_insert ( Vec :: with_capacity ( 1 ) )
600
+ . push ( search_index. len ( ) - 1 ) ;
601
+ }
585
602
}
586
603
}
587
604
0 commit comments