@@ -120,7 +120,7 @@ crate struct Cache {
120120
121121 /// Aliases added through `#[doc(alias = "...")]`. Since a few items can have the same alias,
122122 /// 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 > > ,
124124}
125125
126126impl Cache {
@@ -311,7 +311,7 @@ impl DocFolder for Cache {
311311 } ;
312312
313313 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 => {
315315 debug_assert ! ( !item. is_stripped( ) ) ;
316316
317317 // A crate has a module at its root, containing all items,
@@ -327,6 +327,21 @@ impl DocFolder for Cache {
327327 parent_idx : None ,
328328 search_type : get_index_search_type ( & item) ,
329329 } ) ;
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+ }
330345 }
331346 }
332347 ( Some ( parent) , None ) if is_inherent_impl_item => {
@@ -363,6 +378,9 @@ impl DocFolder for Cache {
363378 | clean:: MacroItem ( ..)
364379 | clean:: ProcMacroItem ( ..)
365380 | clean:: VariantItem ( ..)
381+ | clean:: StructFieldItem ( ..)
382+ | clean:: TyMethodItem ( ..)
383+ | clean:: MethodItem ( ..)
366384 if !self . stripped_mod =>
367385 {
368386 // Re-exported items mean that the same id can show up twice
@@ -376,11 +394,8 @@ impl DocFolder for Cache {
376394 {
377395 self . paths . insert ( item. def_id , ( self . stack . clone ( ) , item. type_ ( ) ) ) ;
378396 }
379- self . add_aliases ( & item) ;
380397 }
381-
382398 clean:: PrimitiveItem ( ..) => {
383- self . add_aliases ( & item) ;
384399 self . paths . insert ( item. def_id , ( self . stack . clone ( ) , item. type_ ( ) ) ) ;
385400 }
386401
@@ -489,36 +504,23 @@ impl DocFolder for Cache {
489504}
490505
491506impl 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 ( )
522524 }
523525}
524526
@@ -567,7 +569,8 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
567569 let mut crate_items = Vec :: with_capacity ( cache. search_index . len ( ) ) ;
568570 let mut crate_paths = vec ! [ ] ;
569571
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;
571574
572575 // Attach all orphan items to the type's definition if the type
573576 // has since been learned.
@@ -582,6 +585,20 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
582585 parent_idx : None ,
583586 search_type : get_index_search_type ( & item) ,
584587 } ) ;
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+ }
585602 }
586603 }
587604
0 commit comments