@@ -580,6 +580,7 @@ impl SerializedSearchIndex {
580580 module_path,
581581 exact_module_path,
582582 parent,
583+ trait_parent,
583584 deprecated,
584585 associated_item_disambiguator,
585586 } | EntryData {
@@ -589,6 +590,7 @@ impl SerializedSearchIndex {
589590 exact_module_path : exact_module_path
590591 . and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
591592 parent : parent. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
593+ trait_parent : trait_parent. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
592594 deprecated : * deprecated,
593595 associated_item_disambiguator : associated_item_disambiguator. clone ( ) ,
594596 } ,
@@ -870,6 +872,7 @@ struct EntryData {
870872 module_path : Option < usize > ,
871873 exact_module_path : Option < usize > ,
872874 parent : Option < usize > ,
875+ trait_parent : Option < usize > ,
873876 deprecated : bool ,
874877 associated_item_disambiguator : Option < String > ,
875878}
@@ -885,6 +888,7 @@ impl Serialize for EntryData {
885888 seq. serialize_element ( & self . module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
886889 seq. serialize_element ( & self . exact_module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
887890 seq. serialize_element ( & self . parent . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
891+ seq. serialize_element ( & self . trait_parent . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
888892 seq. serialize_element ( & if self . deprecated { 1 } else { 0 } ) ?;
889893 if let Some ( disambig) = & self . associated_item_disambiguator {
890894 seq. serialize_element ( & disambig) ?;
@@ -916,6 +920,9 @@ impl<'de> Deserialize<'de> for EntryData {
916920 . ok_or_else ( || A :: Error :: missing_field ( "exact_module_path" ) ) ?;
917921 let parent: SerializedOptional32 =
918922 v. next_element ( ) ?. ok_or_else ( || A :: Error :: missing_field ( "parent" ) ) ?;
923+ let trait_parent: SerializedOptional32 =
924+ v. next_element ( ) ?. ok_or_else ( || A :: Error :: missing_field ( "trait_parent" ) ) ?;
925+
919926 let deprecated: u32 = v. next_element ( ) ?. unwrap_or ( 0 ) ;
920927 let associated_item_disambiguator: Option < String > = v. next_element ( ) ?;
921928 Ok ( EntryData {
@@ -925,6 +932,7 @@ impl<'de> Deserialize<'de> for EntryData {
925932 exact_module_path : Option :: < i32 > :: from ( exact_module_path)
926933 . map ( |path| path as usize ) ,
927934 parent : Option :: < i32 > :: from ( parent) . map ( |path| path as usize ) ,
935+ trait_parent : Option :: < i32 > :: from ( trait_parent) . map ( |path| path as usize ) ,
928936 deprecated : deprecated != 0 ,
929937 associated_item_disambiguator,
930938 } )
@@ -1275,7 +1283,8 @@ pub(crate) fn build_index(
12751283
12761284 // Attach all orphan items to the type's definition if the type
12771285 // has since been learned.
1278- for & OrphanImplItem { impl_id, parent, ref item, ref impl_generics } in & cache. orphan_impl_items
1286+ for & OrphanImplItem { impl_id, parent, trait_parent, ref item, ref impl_generics } in
1287+ & cache. orphan_impl_items
12791288 {
12801289 if let Some ( ( fqp, _) ) = cache. paths . get ( & parent) {
12811290 let desc = short_markdown_summary ( & item. doc_value ( ) , & item. link_names ( cache) ) ;
@@ -1287,6 +1296,8 @@ pub(crate) fn build_index(
12871296 desc,
12881297 parent : Some ( parent) ,
12891298 parent_idx : None ,
1299+ trait_parent,
1300+ trait_parent_idx : None ,
12901301 exact_module_path : None ,
12911302 impl_id,
12921303 search_type : get_function_type_for_search (
@@ -1391,6 +1402,7 @@ pub(crate) fn build_index(
13911402 module_path : None ,
13921403 exact_module_path : None ,
13931404 parent : None ,
1405+ trait_parent : None ,
13941406 deprecated : false ,
13951407 associated_item_disambiguator : None ,
13961408 } ) ,
@@ -1404,39 +1416,46 @@ pub(crate) fn build_index(
14041416 }
14051417 } ;
14061418
1407- // First, populate associated item parents
1419+ // First, populate associated item parents and trait parents
14081420 let crate_items: Vec < & mut IndexItem > = search_index
14091421 . iter_mut ( )
14101422 . map ( |item| {
1411- item. parent_idx = item. parent . and_then ( |defid| {
1412- cache. paths . get ( & defid) . map ( |& ( ref fqp, ty) | {
1413- let pathid = serialized_index. names . len ( ) ;
1414- match serialized_index. crate_paths_index . entry ( ( ty, fqp. clone ( ) ) ) {
1415- Entry :: Occupied ( entry) => * entry. get ( ) ,
1416- Entry :: Vacant ( entry) => {
1417- entry. insert ( pathid) ;
1418- let ( name, path) = fqp. split_last ( ) . unwrap ( ) ;
1419- serialized_index. push_path (
1420- name. as_str ( ) . to_string ( ) ,
1421- PathData {
1422- ty,
1423- module_path : path. to_vec ( ) ,
1424- exact_module_path : if let Some ( exact_path) =
1425- cache. exact_paths . get ( & defid)
1426- && let Some ( ( name2, exact_path) ) = exact_path. split_last ( )
1427- && name == name2
1428- {
1429- Some ( exact_path. to_vec ( ) )
1430- } else {
1431- None
1423+ let mut defid_to_rowid = |defid, check_external : bool | {
1424+ cache
1425+ . paths
1426+ . get ( & defid)
1427+ . or_else ( || check_external. then ( || cache. external_paths . get ( & defid) ) . flatten ( ) )
1428+ . map ( |& ( ref fqp, ty) | {
1429+ let pathid = serialized_index. names . len ( ) ;
1430+ match serialized_index. crate_paths_index . entry ( ( ty, fqp. clone ( ) ) ) {
1431+ Entry :: Occupied ( entry) => * entry. get ( ) ,
1432+ Entry :: Vacant ( entry) => {
1433+ entry. insert ( pathid) ;
1434+ let ( name, path) = fqp. split_last ( ) . unwrap ( ) ;
1435+ serialized_index. push_path (
1436+ name. as_str ( ) . to_string ( ) ,
1437+ PathData {
1438+ ty,
1439+ module_path : path. to_vec ( ) ,
1440+ exact_module_path : if let Some ( exact_path) =
1441+ cache. exact_paths . get ( & defid)
1442+ && let Some ( ( name2, exact_path) ) =
1443+ exact_path. split_last ( )
1444+ && name == name2
1445+ {
1446+ Some ( exact_path. to_vec ( ) )
1447+ } else {
1448+ None
1449+ } ,
14321450 } ,
1433- } ,
1434- ) ;
1435- usize :: try_from ( pathid ) . unwrap ( )
1451+ ) ;
1452+ usize :: try_from ( pathid ) . unwrap ( )
1453+ }
14361454 }
1437- }
1438- } )
1439- } ) ;
1455+ } )
1456+ } ;
1457+ item. parent_idx = item. parent . and_then ( |p| defid_to_rowid ( p, false ) ) ;
1458+ item. trait_parent_idx = item. trait_parent . and_then ( |p| defid_to_rowid ( p, true ) ) ;
14401459
14411460 if let Some ( defid) = item. defid
14421461 && item. parent_idx . is_none ( )
@@ -1519,6 +1538,7 @@ pub(crate) fn build_index(
15191538 Some ( EntryData {
15201539 ty : item. ty ,
15211540 parent : item. parent_idx ,
1541+ trait_parent : item. trait_parent_idx ,
15221542 module_path,
15231543 exact_module_path,
15241544 deprecated : item. deprecation . is_some ( ) ,
0 commit comments