@@ -579,6 +579,7 @@ pub struct ModuleItems {
579
579
pub items : BTreeSet < HirId > ,
580
580
pub trait_items : BTreeSet < TraitItemId > ,
581
581
pub impl_items : BTreeSet < ImplItemId > ,
582
+ pub foreign_items : BTreeSet < ForeignItemId > ,
582
583
}
583
584
584
585
/// A type representing only the top-level module.
@@ -612,6 +613,7 @@ pub struct Crate<'hir> {
612
613
613
614
pub trait_items : BTreeMap < TraitItemId , TraitItem < ' hir > > ,
614
615
pub impl_items : BTreeMap < ImplItemId , ImplItem < ' hir > > ,
616
+ pub foreign_items : BTreeMap < ForeignItemId , ForeignItem < ' hir > > ,
615
617
pub bodies : BTreeMap < BodyId , Body < ' hir > > ,
616
618
pub trait_impls : BTreeMap < DefId , Vec < HirId > > ,
617
619
@@ -644,6 +646,10 @@ impl Crate<'hir> {
644
646
& self . impl_items [ & id]
645
647
}
646
648
649
+ pub fn foreign_item ( & self , id : ForeignItemId ) -> & ForeignItem < ' hir > {
650
+ & self . foreign_items [ & id]
651
+ }
652
+
647
653
pub fn body ( & self , id : BodyId ) -> & Body < ' hir > {
648
654
& self . bodies [ & id]
649
655
}
@@ -673,6 +679,10 @@ impl Crate<'_> {
673
679
for impl_item in self . impl_items . values ( ) {
674
680
visitor. visit_impl_item ( impl_item) ;
675
681
}
682
+
683
+ for foreign_item in self . foreign_items . values ( ) {
684
+ visitor. visit_foreign_item ( foreign_item) ;
685
+ }
676
686
}
677
687
678
688
/// A parallel version of `visit_all_item_likes`.
@@ -695,6 +705,11 @@ impl Crate<'_> {
695
705
par_for_each_in( & self . impl_items, |( _, impl_item) | {
696
706
visitor. visit_impl_item( impl_item) ;
697
707
} ) ;
708
+ } ,
709
+ {
710
+ par_for_each_in( & self . foreign_items, |( _, foreign_item) | {
711
+ visitor. visit_foreign_item( foreign_item) ;
712
+ } ) ;
698
713
}
699
714
) ;
700
715
}
@@ -1840,7 +1855,7 @@ pub struct FnSig<'hir> {
1840
1855
}
1841
1856
1842
1857
// The bodies for items are stored "out of line", in a separate
1843
- // hashmap in the `Crate`. Here we just record the node -id of the item
1858
+ // hashmap in the `Crate`. Here we just record the hir -id of the item
1844
1859
// so it can fetched later.
1845
1860
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Encodable , Debug ) ]
1846
1861
pub struct TraitItemId {
@@ -1884,7 +1899,7 @@ pub enum TraitItemKind<'hir> {
1884
1899
}
1885
1900
1886
1901
// The bodies for items are stored "out of line", in a separate
1887
- // hashmap in the `Crate`. Here we just record the node -id of the item
1902
+ // hashmap in the `Crate`. Here we just record the hir -id of the item
1888
1903
// so it can fetched later.
1889
1904
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Encodable , Debug ) ]
1890
1905
pub struct ImplItemId {
@@ -2269,12 +2284,6 @@ pub struct Mod<'hir> {
2269
2284
pub item_ids : & ' hir [ ItemId ] ,
2270
2285
}
2271
2286
2272
- #[ derive( Debug , HashStable_Generic ) ]
2273
- pub struct ForeignMod < ' hir > {
2274
- pub abi : Abi ,
2275
- pub items : & ' hir [ ForeignItem < ' hir > ] ,
2276
- }
2277
-
2278
2287
#[ derive( Encodable , Debug , HashStable_Generic ) ]
2279
2288
pub struct GlobalAsm {
2280
2289
pub asm : Symbol ,
@@ -2432,7 +2441,7 @@ impl VariantData<'hir> {
2432
2441
}
2433
2442
2434
2443
// The bodies for items are stored "out of line", in a separate
2435
- // hashmap in the `Crate`. Here we just record the node -id of the item
2444
+ // hashmap in the `Crate`. Here we just record the hir -id of the item
2436
2445
// so it can fetched later.
2437
2446
#[ derive( Copy , Clone , Encodable , Debug ) ]
2438
2447
pub struct ItemId {
@@ -2521,7 +2530,7 @@ pub enum ItemKind<'hir> {
2521
2530
/// A module.
2522
2531
Mod ( Mod < ' hir > ) ,
2523
2532
/// An external module, e.g. `extern { .. }`.
2524
- ForeignMod ( ForeignMod < ' hir > ) ,
2533
+ ForeignMod { abi : Abi , items : & ' hir [ ForeignItemRef < ' hir > ] } ,
2525
2534
/// Module-level inline assembly (from `global_asm!`).
2526
2535
GlobalAsm ( & ' hir GlobalAsm ) ,
2527
2536
/// A type alias, e.g., `type Foo = Bar<u8>`.
@@ -2614,6 +2623,29 @@ pub enum AssocItemKind {
2614
2623
Type ,
2615
2624
}
2616
2625
2626
+ // The bodies for items are stored "out of line", in a separate
2627
+ // hashmap in the `Crate`. Here we just record the hir-id of the item
2628
+ // so it can fetched later.
2629
+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Encodable , Debug ) ]
2630
+ pub struct ForeignItemId {
2631
+ pub hir_id : HirId ,
2632
+ }
2633
+
2634
+ /// A reference from a foreign block to one of its items. This
2635
+ /// contains the item's ID, naturally, but also the item's name and
2636
+ /// some other high-level details (like whether it is an associated
2637
+ /// type or method, and whether it is public). This allows other
2638
+ /// passes to find the impl they want without loading the ID (which
2639
+ /// means fewer edges in the incremental compilation graph).
2640
+ #[ derive( Debug , HashStable_Generic ) ]
2641
+ pub struct ForeignItemRef < ' hir > {
2642
+ pub id : ForeignItemId ,
2643
+ #[ stable_hasher( project( name) ) ]
2644
+ pub ident : Ident ,
2645
+ pub span : Span ,
2646
+ pub vis : Visibility < ' hir > ,
2647
+ }
2648
+
2617
2649
#[ derive( Debug , HashStable_Generic ) ]
2618
2650
pub struct ForeignItem < ' hir > {
2619
2651
#[ stable_hasher( project( name) ) ]
0 commit comments