@@ -580,6 +580,7 @@ impl SerializedSearchIndex {
580
580
module_path,
581
581
exact_module_path,
582
582
parent,
583
+ trait_parent,
583
584
deprecated,
584
585
associated_item_disambiguator,
585
586
} | EntryData {
@@ -589,6 +590,7 @@ impl SerializedSearchIndex {
589
590
exact_module_path : exact_module_path
590
591
. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
591
592
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 ( ) ) ,
592
594
deprecated : * deprecated,
593
595
associated_item_disambiguator : associated_item_disambiguator. clone ( ) ,
594
596
} ,
@@ -870,6 +872,7 @@ struct EntryData {
870
872
module_path : Option < usize > ,
871
873
exact_module_path : Option < usize > ,
872
874
parent : Option < usize > ,
875
+ trait_parent : Option < usize > ,
873
876
deprecated : bool ,
874
877
associated_item_disambiguator : Option < String > ,
875
878
}
@@ -885,6 +888,7 @@ impl Serialize for EntryData {
885
888
seq. serialize_element ( & self . module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
886
889
seq. serialize_element ( & self . exact_module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
887
890
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 ) ) ?;
888
892
seq. serialize_element ( & if self . deprecated { 1 } else { 0 } ) ?;
889
893
if let Some ( disambig) = & self . associated_item_disambiguator {
890
894
seq. serialize_element ( & disambig) ?;
@@ -916,6 +920,9 @@ impl<'de> Deserialize<'de> for EntryData {
916
920
. ok_or_else ( || A :: Error :: missing_field ( "exact_module_path" ) ) ?;
917
921
let parent: SerializedOptional32 =
918
922
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
+
919
926
let deprecated: u32 = v. next_element ( ) ?. unwrap_or ( 0 ) ;
920
927
let associated_item_disambiguator: Option < String > = v. next_element ( ) ?;
921
928
Ok ( EntryData {
@@ -925,6 +932,7 @@ impl<'de> Deserialize<'de> for EntryData {
925
932
exact_module_path : Option :: < i32 > :: from ( exact_module_path)
926
933
. map ( |path| path as usize ) ,
927
934
parent : Option :: < i32 > :: from ( parent) . map ( |path| path as usize ) ,
935
+ trait_parent : Option :: < i32 > :: from ( trait_parent) . map ( |path| path as usize ) ,
928
936
deprecated : deprecated != 0 ,
929
937
associated_item_disambiguator,
930
938
} )
@@ -1275,7 +1283,8 @@ pub(crate) fn build_index(
1275
1283
1276
1284
// Attach all orphan items to the type's definition if the type
1277
1285
// 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
1279
1288
{
1280
1289
if let Some ( ( fqp, _) ) = cache. paths . get ( & parent) {
1281
1290
let desc = short_markdown_summary ( & item. doc_value ( ) , & item. link_names ( cache) ) ;
@@ -1287,6 +1296,8 @@ pub(crate) fn build_index(
1287
1296
desc,
1288
1297
parent : Some ( parent) ,
1289
1298
parent_idx : None ,
1299
+ trait_parent,
1300
+ trait_parent_idx : None ,
1290
1301
exact_module_path : None ,
1291
1302
impl_id,
1292
1303
search_type : get_function_type_for_search (
@@ -1391,6 +1402,7 @@ pub(crate) fn build_index(
1391
1402
module_path : None ,
1392
1403
exact_module_path : None ,
1393
1404
parent : None ,
1405
+ trait_parent : None ,
1394
1406
deprecated : false ,
1395
1407
associated_item_disambiguator : None ,
1396
1408
} ) ,
@@ -1404,39 +1416,46 @@ pub(crate) fn build_index(
1404
1416
}
1405
1417
} ;
1406
1418
1407
- // First, populate associated item parents
1419
+ // First, populate associated item parents and trait parents
1408
1420
let crate_items: Vec < & mut IndexItem > = search_index
1409
1421
. iter_mut ( )
1410
1422
. 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
+ } ,
1432
1450
} ,
1433
- } ,
1434
- ) ;
1435
- usize :: try_from ( pathid ) . unwrap ( )
1451
+ ) ;
1452
+ usize :: try_from ( pathid ) . unwrap ( )
1453
+ }
1436
1454
}
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 ) ) ;
1440
1459
1441
1460
if let Some ( defid) = item. defid
1442
1461
&& item. parent_idx . is_none ( )
@@ -1519,6 +1538,7 @@ pub(crate) fn build_index(
1519
1538
Some ( EntryData {
1520
1539
ty : item. ty ,
1521
1540
parent : item. parent_idx ,
1541
+ trait_parent : item. trait_parent_idx ,
1522
1542
module_path,
1523
1543
exact_module_path,
1524
1544
deprecated : item. deprecation . is_some ( ) ,
0 commit comments