@@ -520,7 +520,8 @@ impl SerializedSearchIndex {
520520 ty,
521521 module_path,
522522 exact_module_path,
523- parent,
523+ parent,
524+ trait_parent,
524525 deprecated,
525526 associated_item_disambiguator,
526527 } | EntryData {
@@ -530,6 +531,7 @@ impl SerializedSearchIndex {
530531 exact_module_path : exact_module_path
531532 . and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
532533 parent : parent. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
534+ trait_parent : trait_parent. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
533535 deprecated : * deprecated,
534536 associated_item_disambiguator : associated_item_disambiguator. clone ( ) ,
535537 } ,
@@ -788,6 +790,7 @@ struct EntryData {
788790 module_path : Option < usize > ,
789791 exact_module_path : Option < usize > ,
790792 parent : Option < usize > ,
793+ trait_parent : Option < usize > ,
791794 deprecated : bool ,
792795 associated_item_disambiguator : Option < String > ,
793796}
@@ -803,6 +806,7 @@ impl Serialize for EntryData {
803806 seq. serialize_element ( & self . module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
804807 seq. serialize_element ( & self . exact_module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
805808 seq. serialize_element ( & self . parent . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
809+ seq. serialize_element ( & self . trait_parent . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
806810 seq. serialize_element ( & if self . deprecated { 1 } else { 0 } ) ?;
807811 if let Some ( disambig) = & self . associated_item_disambiguator {
808812 seq. serialize_element ( & disambig) ?;
@@ -834,6 +838,9 @@ impl<'de> Deserialize<'de> for EntryData {
834838 . ok_or_else ( || A :: Error :: missing_field ( "exact_module_path" ) ) ?;
835839 let parent: SerializedOptional32 =
836840 v. next_element ( ) ?. ok_or_else ( || A :: Error :: missing_field ( "parent" ) ) ?;
841+ let trait_parent: SerializedOptional32 =
842+ v. next_element ( ) ?. ok_or_else ( || A :: Error :: missing_field ( "trait_parent" ) ) ?;
843+
837844 let deprecated: u32 = v. next_element ( ) ?. unwrap_or ( 0 ) ;
838845 let associated_item_disambiguator: Option < String > = v. next_element ( ) ?;
839846 Ok ( EntryData {
@@ -843,6 +850,7 @@ impl<'de> Deserialize<'de> for EntryData {
843850 exact_module_path : Option :: < i32 > :: from ( exact_module_path)
844851 . map ( |path| path as usize ) ,
845852 parent : Option :: < i32 > :: from ( parent) . map ( |path| path as usize ) ,
853+ trait_parent : Option :: < i32 > :: from ( trait_parent) . map ( |path| path as usize ) ,
846854 deprecated : deprecated != 0 ,
847855 associated_item_disambiguator,
848856 } )
@@ -1167,7 +1175,7 @@ pub(crate) fn build_index(
11671175
11681176 // Attach all orphan items to the type's definition if the type
11691177 // has since been learned.
1170- for & OrphanImplItem { impl_id, parent, ref item, ref impl_generics } in & cache. orphan_impl_items
1178+ for & OrphanImplItem { impl_id, parent, trait_parent , ref item, ref impl_generics } in & cache. orphan_impl_items
11711179 {
11721180 if let Some ( ( fqp, _) ) = cache. paths . get ( & parent) {
11731181 let desc = short_markdown_summary ( & item. doc_value ( ) , & item. link_names ( cache) ) ;
@@ -1179,6 +1187,8 @@ pub(crate) fn build_index(
11791187 desc,
11801188 parent : Some ( parent) ,
11811189 parent_idx : None ,
1190+ trait_parent,
1191+ trait_parent_idx : None ,
11821192 exact_module_path : None ,
11831193 impl_id,
11841194 search_type : get_function_type_for_search (
@@ -1275,6 +1285,7 @@ pub(crate) fn build_index(
12751285 module_path : None ,
12761286 exact_module_path : None ,
12771287 parent : None ,
1288+ trait_parent : None ,
12781289 deprecated : false ,
12791290 associated_item_disambiguator : None ,
12801291 } ) ,
@@ -1288,12 +1299,12 @@ pub(crate) fn build_index(
12881299 }
12891300 } ;
12901301
1291- // First, populate associated item parents
1302+ // First, populate associated item parents and trait parents
12921303 let crate_items: Vec < & mut IndexItem > = search_index
12931304 . iter_mut ( )
12941305 . map ( |item| {
1295- item . parent_idx = item . parent . and_then ( |defid| {
1296- cache. paths . get ( & defid) . map ( |& ( ref fqp, ty) | {
1306+ let mut defid_to_rowid = |defid, check_external : bool | {
1307+ cache. paths . get ( & defid) . or_else ( || check_external . then ( || cache . external_paths . get ( & defid ) ) . flatten ( ) ) . map ( |& ( ref fqp, ty) | {
12971308 let pathid = serialized_index. names . len ( ) ;
12981309 match serialized_index. crate_paths_index . entry ( ( ty, fqp. clone ( ) ) ) {
12991310 Entry :: Occupied ( entry) => * entry. get ( ) ,
@@ -1319,8 +1330,10 @@ pub(crate) fn build_index(
13191330 usize:: try_from ( pathid) . unwrap ( )
13201331 }
13211332 }
1322- } )
1323- } ) ;
1333+ } ) } ;
1334+ item. parent_idx = item. parent . and_then ( |p| defid_to_rowid ( p, false ) ) ;
1335+ item. trait_parent_idx = item. trait_parent . and_then ( |p| defid_to_rowid ( p, true ) ) ;
1336+ debug_assert ! ( !item. trait_parent. is_some( ) || item. trait_parent_idx. is_some( ) , "unable to resolve trait parent for {item:?}" ) ;
13241337
13251338 if let Some ( defid) = item. defid
13261339 && item. parent_idx . is_none ( )
@@ -1403,6 +1416,7 @@ pub(crate) fn build_index(
14031416 Some ( EntryData {
14041417 ty : item. ty ,
14051418 parent : item. parent_idx ,
1419+ trait_parent : item. trait_parent_idx ,
14061420 module_path,
14071421 exact_module_path,
14081422 deprecated : item. deprecation . is_some ( ) ,
0 commit comments