@@ -610,6 +610,7 @@ impl SerializedSearchIndex {
610
610
module_path,
611
611
exact_module_path,
612
612
parent,
613
+ trait_parent,
613
614
deprecated,
614
615
associated_item_disambiguator,
615
616
} | EntryData {
@@ -619,6 +620,7 @@ impl SerializedSearchIndex {
619
620
exact_module_path : exact_module_path
620
621
. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
621
622
parent : parent. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
623
+ trait_parent : trait_parent. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
622
624
deprecated : * deprecated,
623
625
associated_item_disambiguator : associated_item_disambiguator. clone ( ) ,
624
626
} ,
@@ -900,6 +902,7 @@ struct EntryData {
900
902
module_path : Option < usize > ,
901
903
exact_module_path : Option < usize > ,
902
904
parent : Option < usize > ,
905
+ trait_parent : Option < usize > ,
903
906
deprecated : bool ,
904
907
associated_item_disambiguator : Option < String > ,
905
908
}
@@ -915,6 +918,7 @@ impl Serialize for EntryData {
915
918
seq. serialize_element ( & self . module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
916
919
seq. serialize_element ( & self . exact_module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
917
920
seq. serialize_element ( & self . parent . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
921
+ seq. serialize_element ( & self . trait_parent . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
918
922
seq. serialize_element ( & if self . deprecated { 1 } else { 0 } ) ?;
919
923
if let Some ( disambig) = & self . associated_item_disambiguator {
920
924
seq. serialize_element ( & disambig) ?;
@@ -946,6 +950,9 @@ impl<'de> Deserialize<'de> for EntryData {
946
950
. ok_or_else ( || A :: Error :: missing_field ( "exact_module_path" ) ) ?;
947
951
let parent: SerializedOptional32 =
948
952
v. next_element ( ) ?. ok_or_else ( || A :: Error :: missing_field ( "parent" ) ) ?;
953
+ let trait_parent: SerializedOptional32 =
954
+ v. next_element ( ) ?. ok_or_else ( || A :: Error :: missing_field ( "trait_parent" ) ) ?;
955
+
949
956
let deprecated: u32 = v. next_element ( ) ?. unwrap_or ( 0 ) ;
950
957
let associated_item_disambiguator: Option < String > = v. next_element ( ) ?;
951
958
Ok ( EntryData {
@@ -955,6 +962,7 @@ impl<'de> Deserialize<'de> for EntryData {
955
962
exact_module_path : Option :: < i32 > :: from ( exact_module_path)
956
963
. map ( |path| path as usize ) ,
957
964
parent : Option :: < i32 > :: from ( parent) . map ( |path| path as usize ) ,
965
+ trait_parent : Option :: < i32 > :: from ( trait_parent) . map ( |path| path as usize ) ,
958
966
deprecated : deprecated != 0 ,
959
967
associated_item_disambiguator,
960
968
} )
@@ -1305,7 +1313,8 @@ pub(crate) fn build_index(
1305
1313
1306
1314
// Attach all orphan items to the type's definition if the type
1307
1315
// has since been learned.
1308
- for & OrphanImplItem { impl_id, parent, ref item, ref impl_generics } in & cache. orphan_impl_items
1316
+ for & OrphanImplItem { impl_id, parent, trait_parent, ref item, ref impl_generics } in
1317
+ & cache. orphan_impl_items
1309
1318
{
1310
1319
if let Some ( ( fqp, _) ) = cache. paths . get ( & parent) {
1311
1320
let desc = short_markdown_summary ( & item. doc_value ( ) , & item. link_names ( cache) ) ;
@@ -1317,6 +1326,8 @@ pub(crate) fn build_index(
1317
1326
desc,
1318
1327
parent : Some ( parent) ,
1319
1328
parent_idx : None ,
1329
+ trait_parent,
1330
+ trait_parent_idx : None ,
1320
1331
exact_module_path : None ,
1321
1332
impl_id,
1322
1333
search_type : get_function_type_for_search (
@@ -1421,6 +1432,7 @@ pub(crate) fn build_index(
1421
1432
module_path : None ,
1422
1433
exact_module_path : None ,
1423
1434
parent : None ,
1435
+ trait_parent : None ,
1424
1436
deprecated : false ,
1425
1437
associated_item_disambiguator : None ,
1426
1438
} ) ,
@@ -1434,39 +1446,46 @@ pub(crate) fn build_index(
1434
1446
}
1435
1447
} ;
1436
1448
1437
- // First, populate associated item parents
1449
+ // First, populate associated item parents and trait parents
1438
1450
let crate_items: Vec < & mut IndexItem > = search_index
1439
1451
. iter_mut ( )
1440
1452
. map ( |item| {
1441
- item. parent_idx = item. parent . and_then ( |defid| {
1442
- cache. paths . get ( & defid) . map ( |& ( ref fqp, ty) | {
1443
- let pathid = serialized_index. names . len ( ) ;
1444
- match serialized_index. crate_paths_index . entry ( ( ty, fqp. clone ( ) ) ) {
1445
- Entry :: Occupied ( entry) => * entry. get ( ) ,
1446
- Entry :: Vacant ( entry) => {
1447
- entry. insert ( pathid) ;
1448
- let ( name, path) = fqp. split_last ( ) . unwrap ( ) ;
1449
- serialized_index. push_path (
1450
- name. as_str ( ) . to_string ( ) ,
1451
- PathData {
1452
- ty,
1453
- module_path : path. to_vec ( ) ,
1454
- exact_module_path : if let Some ( exact_path) =
1455
- cache. exact_paths . get ( & defid)
1456
- && let Some ( ( name2, exact_path) ) = exact_path. split_last ( )
1457
- && name == name2
1458
- {
1459
- Some ( exact_path. to_vec ( ) )
1460
- } else {
1461
- None
1453
+ let mut defid_to_rowid = |defid, check_external : bool | {
1454
+ cache
1455
+ . paths
1456
+ . get ( & defid)
1457
+ . or_else ( || check_external. then ( || cache. external_paths . get ( & defid) ) . flatten ( ) )
1458
+ . map ( |& ( ref fqp, ty) | {
1459
+ let pathid = serialized_index. names . len ( ) ;
1460
+ match serialized_index. crate_paths_index . entry ( ( ty, fqp. clone ( ) ) ) {
1461
+ Entry :: Occupied ( entry) => * entry. get ( ) ,
1462
+ Entry :: Vacant ( entry) => {
1463
+ entry. insert ( pathid) ;
1464
+ let ( name, path) = fqp. split_last ( ) . unwrap ( ) ;
1465
+ serialized_index. push_path (
1466
+ name. as_str ( ) . to_string ( ) ,
1467
+ PathData {
1468
+ ty,
1469
+ module_path : path. to_vec ( ) ,
1470
+ exact_module_path : if let Some ( exact_path) =
1471
+ cache. exact_paths . get ( & defid)
1472
+ && let Some ( ( name2, exact_path) ) =
1473
+ exact_path. split_last ( )
1474
+ && name == name2
1475
+ {
1476
+ Some ( exact_path. to_vec ( ) )
1477
+ } else {
1478
+ None
1479
+ } ,
1462
1480
} ,
1463
- } ,
1464
- ) ;
1465
- usize :: try_from ( pathid ) . unwrap ( )
1481
+ ) ;
1482
+ usize :: try_from ( pathid ) . unwrap ( )
1483
+ }
1466
1484
}
1467
- }
1468
- } )
1469
- } ) ;
1485
+ } )
1486
+ } ;
1487
+ item. parent_idx = item. parent . and_then ( |p| defid_to_rowid ( p, false ) ) ;
1488
+ item. trait_parent_idx = item. trait_parent . and_then ( |p| defid_to_rowid ( p, true ) ) ;
1470
1489
1471
1490
if let Some ( defid) = item. defid
1472
1491
&& item. parent_idx . is_none ( )
@@ -1549,6 +1568,7 @@ pub(crate) fn build_index(
1549
1568
EntryData {
1550
1569
ty : item. ty ,
1551
1570
parent : item. parent_idx ,
1571
+ trait_parent : item. trait_parent_idx ,
1552
1572
module_path,
1553
1573
exact_module_path,
1554
1574
deprecated : item. deprecation . is_some ( ) ,
0 commit comments