@@ -521,6 +521,7 @@ impl SerializedSearchIndex {
521
521
module_path,
522
522
exact_module_path,
523
523
parent,
524
+ trait_parent,
524
525
deprecated,
525
526
associated_item_disambiguator,
526
527
} | EntryData {
@@ -530,6 +531,7 @@ impl SerializedSearchIndex {
530
531
exact_module_path : exact_module_path
531
532
. and_then ( |path_id| map. get ( & path_id) . copied ( ) ) ,
532
533
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 ( ) ) ,
533
535
deprecated : * deprecated,
534
536
associated_item_disambiguator : associated_item_disambiguator. clone ( ) ,
535
537
} ,
@@ -788,6 +790,7 @@ struct EntryData {
788
790
module_path : Option < usize > ,
789
791
exact_module_path : Option < usize > ,
790
792
parent : Option < usize > ,
793
+ trait_parent : Option < usize > ,
791
794
deprecated : bool ,
792
795
associated_item_disambiguator : Option < String > ,
793
796
}
@@ -803,6 +806,7 @@ impl Serialize for EntryData {
803
806
seq. serialize_element ( & self . module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
804
807
seq. serialize_element ( & self . exact_module_path . map ( |id| id + 1 ) . unwrap_or ( 0 ) ) ?;
805
808
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 ) ) ?;
806
810
seq. serialize_element ( & if self . deprecated { 1 } else { 0 } ) ?;
807
811
if let Some ( disambig) = & self . associated_item_disambiguator {
808
812
seq. serialize_element ( & disambig) ?;
@@ -834,6 +838,9 @@ impl<'de> Deserialize<'de> for EntryData {
834
838
. ok_or_else ( || A :: Error :: missing_field ( "exact_module_path" ) ) ?;
835
839
let parent: SerializedOptional32 =
836
840
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
+
837
844
let deprecated: u32 = v. next_element ( ) ?. unwrap_or ( 0 ) ;
838
845
let associated_item_disambiguator: Option < String > = v. next_element ( ) ?;
839
846
Ok ( EntryData {
@@ -843,6 +850,7 @@ impl<'de> Deserialize<'de> for EntryData {
843
850
exact_module_path : Option :: < i32 > :: from ( exact_module_path)
844
851
. map ( |path| path as usize ) ,
845
852
parent : Option :: < i32 > :: from ( parent) . map ( |path| path as usize ) ,
853
+ trait_parent : Option :: < i32 > :: from ( trait_parent) . map ( |path| path as usize ) ,
846
854
deprecated : deprecated != 0 ,
847
855
associated_item_disambiguator,
848
856
} )
@@ -1167,7 +1175,8 @@ pub(crate) fn build_index(
1167
1175
1168
1176
// Attach all orphan items to the type's definition if the type
1169
1177
// 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
1179
+ & cache. orphan_impl_items
1171
1180
{
1172
1181
if let Some ( ( fqp, _) ) = cache. paths . get ( & parent) {
1173
1182
let desc = short_markdown_summary ( & item. doc_value ( ) , & item. link_names ( cache) ) ;
@@ -1179,6 +1188,8 @@ pub(crate) fn build_index(
1179
1188
desc,
1180
1189
parent : Some ( parent) ,
1181
1190
parent_idx : None ,
1191
+ trait_parent,
1192
+ trait_parent_idx : None ,
1182
1193
exact_module_path : None ,
1183
1194
impl_id,
1184
1195
search_type : get_function_type_for_search (
@@ -1275,6 +1286,7 @@ pub(crate) fn build_index(
1275
1286
module_path : None ,
1276
1287
exact_module_path : None ,
1277
1288
parent : None ,
1289
+ trait_parent : None ,
1278
1290
deprecated : false ,
1279
1291
associated_item_disambiguator : None ,
1280
1292
} ) ,
@@ -1288,39 +1300,50 @@ pub(crate) fn build_index(
1288
1300
}
1289
1301
} ;
1290
1302
1291
- // First, populate associated item parents
1303
+ // First, populate associated item parents and trait parents
1292
1304
let crate_items: Vec < & mut IndexItem > = search_index
1293
1305
. iter_mut ( )
1294
1306
. map ( |item| {
1295
- item. parent_idx = item. parent . and_then ( |defid| {
1296
- cache. paths . get ( & defid) . map ( |& ( ref fqp, ty) | {
1297
- let pathid = serialized_index. names . len ( ) ;
1298
- match serialized_index. crate_paths_index . entry ( ( ty, fqp. clone ( ) ) ) {
1299
- Entry :: Occupied ( entry) => * entry. get ( ) ,
1300
- Entry :: Vacant ( entry) => {
1301
- entry. insert ( pathid) ;
1302
- let ( name, path) = fqp. split_last ( ) . unwrap ( ) ;
1303
- serialized_index. push_path (
1304
- name. as_str ( ) . to_string ( ) ,
1305
- PathData {
1306
- ty,
1307
- module_path : path. to_vec ( ) ,
1308
- exact_module_path : if let Some ( exact_path) =
1309
- cache. exact_paths . get ( & defid)
1310
- && let Some ( ( name2, exact_path) ) = exact_path. split_last ( )
1311
- && name == name2
1312
- {
1313
- Some ( exact_path. to_vec ( ) )
1314
- } else {
1315
- None
1307
+ let mut defid_to_rowid = |defid, check_external : bool | {
1308
+ cache
1309
+ . paths
1310
+ . get ( & defid)
1311
+ . or_else ( || check_external. then ( || cache. external_paths . get ( & defid) ) . flatten ( ) )
1312
+ . map ( |& ( ref fqp, ty) | {
1313
+ let pathid = serialized_index. names . len ( ) ;
1314
+ match serialized_index. crate_paths_index . entry ( ( ty, fqp. clone ( ) ) ) {
1315
+ Entry :: Occupied ( entry) => * entry. get ( ) ,
1316
+ Entry :: Vacant ( entry) => {
1317
+ entry. insert ( pathid) ;
1318
+ let ( name, path) = fqp. split_last ( ) . unwrap ( ) ;
1319
+ serialized_index. push_path (
1320
+ name. as_str ( ) . to_string ( ) ,
1321
+ PathData {
1322
+ ty,
1323
+ module_path : path. to_vec ( ) ,
1324
+ exact_module_path : if let Some ( exact_path) =
1325
+ cache. exact_paths . get ( & defid)
1326
+ && let Some ( ( name2, exact_path) ) =
1327
+ exact_path. split_last ( )
1328
+ && name == name2
1329
+ {
1330
+ Some ( exact_path. to_vec ( ) )
1331
+ } else {
1332
+ None
1333
+ } ,
1316
1334
} ,
1317
- } ,
1318
- ) ;
1319
- usize :: try_from ( pathid ) . unwrap ( )
1335
+ ) ;
1336
+ usize :: try_from ( pathid ) . unwrap ( )
1337
+ }
1320
1338
}
1321
- }
1322
- } )
1323
- } ) ;
1339
+ } )
1340
+ } ;
1341
+ item. parent_idx = item. parent . and_then ( |p| defid_to_rowid ( p, false ) ) ;
1342
+ item. trait_parent_idx = item. trait_parent . and_then ( |p| defid_to_rowid ( p, true ) ) ;
1343
+ debug_assert ! (
1344
+ !item. trait_parent. is_some( ) || item. trait_parent_idx. is_some( ) ,
1345
+ "unable to resolve trait parent for {item:?}"
1346
+ ) ;
1324
1347
1325
1348
if let Some ( defid) = item. defid
1326
1349
&& item. parent_idx . is_none ( )
@@ -1403,6 +1426,7 @@ pub(crate) fn build_index(
1403
1426
Some ( EntryData {
1404
1427
ty : item. ty ,
1405
1428
parent : item. parent_idx ,
1429
+ trait_parent : item. trait_parent_idx ,
1406
1430
module_path,
1407
1431
exact_module_path,
1408
1432
deprecated : item. deprecation . is_some ( ) ,
0 commit comments