Skip to content

Commit 032f68d

Browse files
committed
Remove ForeignMod struct.
1 parent 419a918 commit 032f68d

File tree

26 files changed

+69
-85
lines changed

26 files changed

+69
-85
lines changed

compiler/rustc_ast_lowering/src/item.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
316316
})
317317
}
318318
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
319-
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
319+
ItemKind::ForeignMod(ref fm) => hir::ItemKind::ForeignMod {
320+
abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)),
321+
items: self
322+
.arena
323+
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
324+
},
320325
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
321326
ItemKind::TyAlias(_, ref gen, _, Some(ref ty)) => {
322327
// We lower
@@ -725,15 +730,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
725730
}
726731
}
727732

728-
fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod<'hir> {
729-
hir::ForeignMod {
730-
abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)),
731-
items: self
732-
.arena
733-
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
734-
}
735-
}
736-
737733
fn lower_global_asm(&mut self, ga: &GlobalAsm) -> &'hir hir::GlobalAsm {
738734
self.arena.alloc(hir::GlobalAsm { asm: ga.asm })
739735
}

compiler/rustc_hir/src/hir.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2284,12 +2284,6 @@ pub struct Mod<'hir> {
22842284
pub item_ids: &'hir [ItemId],
22852285
}
22862286

2287-
#[derive(Debug, HashStable_Generic)]
2288-
pub struct ForeignMod<'hir> {
2289-
pub abi: Abi,
2290-
pub items: &'hir [ForeignItemRef<'hir>],
2291-
}
2292-
22932287
#[derive(Encodable, Debug, HashStable_Generic)]
22942288
pub struct GlobalAsm {
22952289
pub asm: Symbol,
@@ -2536,7 +2530,7 @@ pub enum ItemKind<'hir> {
25362530
/// A module.
25372531
Mod(Mod<'hir>),
25382532
/// An external module, e.g. `extern { .. }`.
2539-
ForeignMod(ForeignMod<'hir>),
2533+
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef<'hir>] },
25402534
/// Module-level inline assembly (from `global_asm!`).
25412535
GlobalAsm(&'hir GlobalAsm),
25422536
/// A type alias, e.g., `type Foo = Bar<u8>`.

compiler/rustc_hir/src/intravisit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
589589
// `visit_mod()` takes care of visiting the `Item`'s `HirId`.
590590
visitor.visit_mod(module, item.span, item.hir_id)
591591
}
592-
ItemKind::ForeignMod(ref foreign_module) => {
592+
ItemKind::ForeignMod { abi: _, items } => {
593593
visitor.visit_id(item.hir_id);
594-
walk_list!(visitor, visit_foreign_item_ref, foreign_module.items);
594+
walk_list!(visitor, visit_foreign_item_ref, items);
595595
}
596596
ItemKind::GlobalAsm(_) => {
597597
visitor.visit_id(item.hir_id);

compiler/rustc_hir/src/target.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Target {
9191
ItemKind::Const(..) => Target::Const,
9292
ItemKind::Fn(..) => Target::Fn,
9393
ItemKind::Mod(..) => Target::Mod,
94-
ItemKind::ForeignMod(..) => Target::ForeignMod,
94+
ItemKind::ForeignMod { .. } => Target::ForeignMod,
9595
ItemKind::GlobalAsm(..) => Target::GlobalAsm,
9696
ItemKind::TyAlias(..) => Target::TyAlias,
9797
ItemKind::OpaqueTy(..) => Target::OpaqueTy,

compiler/rustc_hir_pretty/src/lib.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,6 @@ impl<'a> State<'a> {
352352
}
353353
}
354354

355-
pub fn print_foreign_mod(&mut self, nmod: &hir::ForeignMod<'_>, attrs: &[ast::Attribute]) {
356-
self.print_inner_attributes(attrs);
357-
for item in nmod.items {
358-
self.ann.nested(self, Nested::ForeignItem(item.id));
359-
}
360-
}
361-
362355
pub fn print_opt_lifetime(&mut self, lifetime: &hir::Lifetime) {
363356
if !lifetime.is_elided() {
364357
self.print_lifetime(lifetime);
@@ -647,11 +640,14 @@ impl<'a> State<'a> {
647640
self.print_mod(_mod, &item.attrs);
648641
self.bclose(item.span);
649642
}
650-
hir::ItemKind::ForeignMod(ref nmod) => {
643+
hir::ItemKind::ForeignMod { abi, items } => {
651644
self.head("extern");
652-
self.word_nbsp(nmod.abi.to_string());
645+
self.word_nbsp(abi.to_string());
653646
self.bopen();
654-
self.print_foreign_mod(nmod, &item.attrs);
647+
self.print_inner_attributes(item.attrs);
648+
for item in items {
649+
self.ann.nested(self, Nested::ForeignItem(item.id));
650+
}
655651
self.bclose(item.span);
656652
}
657653
hir::ItemKind::GlobalAsm(ref ga) => {

compiler/rustc_incremental/src/persist/dirty_clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl DirtyCleanVisitor<'tcx> {
280280
HirItem::Mod(..) => ("ItemMod", LABELS_HIR_ONLY),
281281

282282
// // An external module
283-
HirItem::ForeignMod(..) => ("ItemForeignMod", LABELS_HIR_ONLY),
283+
HirItem::ForeignMod { .. } => ("ItemForeignMod", LABELS_HIR_ONLY),
284284

285285
// Module-level inline assembly (from global_asm!)
286286
HirItem::GlobalAsm(..) => ("ItemGlobalAsm", LABELS_HIR_ONLY),

compiler/rustc_metadata/src/foreign_modules.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ struct Collector<'tcx> {
1616

1717
impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
1818
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
19-
let fm = match it.kind {
20-
hir::ItemKind::ForeignMod(ref fm) => fm,
19+
let items = match it.kind {
20+
hir::ItemKind::ForeignMod { items, .. } => items,
2121
_ => return,
2222
};
2323

24-
let foreign_items = fm
25-
.items
26-
.iter()
27-
.map(|it| self.tcx.hir().local_def_id(it.id.hir_id).to_def_id())
28-
.collect();
24+
let foreign_items =
25+
items.iter().map(|it| self.tcx.hir().local_def_id(it.id.hir_id).to_def_id()).collect();
2926
self.modules.push(ForeignModule {
3027
foreign_items,
3128
def_id: self.tcx.hir().local_def_id(it.hir_id).to_def_id(),

compiler/rustc_metadata/src/link_args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ struct Collector<'tcx> {
2626

2727
impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
2828
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
29-
let fm = match it.kind {
30-
hir::ItemKind::ForeignMod(ref fm) => fm,
29+
let abi = match it.kind {
30+
hir::ItemKind::ForeignMod { abi, .. } => abi,
3131
_ => return,
3232
};
33-
if fm.abi == Abi::Rust || fm.abi == Abi::RustIntrinsic || fm.abi == Abi::PlatformIntrinsic {
33+
if abi == Abi::Rust || abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
3434
return;
3535
}
3636

compiler/rustc_metadata/src/native_libs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ struct Collector<'tcx> {
3333

3434
impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
3535
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
36-
let fm = match it.kind {
37-
hir::ItemKind::ForeignMod(ref fm) => fm,
36+
let abi = match it.kind {
37+
hir::ItemKind::ForeignMod { abi, .. } => abi,
3838
_ => return,
3939
};
4040

41-
if fm.abi == Abi::Rust || fm.abi == Abi::RustIntrinsic || fm.abi == Abi::PlatformIntrinsic {
41+
if abi == Abi::Rust || abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
4242
return;
4343
}
4444

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ impl EncodeContext<'a, 'tcx> {
12251225
hir::ItemKind::Mod(ref m) => {
12261226
return self.encode_info_for_mod(item.hir_id, m, &item.attrs);
12271227
}
1228-
hir::ItemKind::ForeignMod(_) => EntryKind::ForeignMod,
1228+
hir::ItemKind::ForeignMod{..} => EntryKind::ForeignMod,
12291229
hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm,
12301230
hir::ItemKind::TyAlias(..) => EntryKind::Type,
12311231
hir::ItemKind::OpaqueTy(..) => {
@@ -1320,8 +1320,8 @@ impl EncodeContext<'a, 'tcx> {
13201320
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
13211321
// FIXME(eddyb) there should be a nicer way to do this.
13221322
match item.kind {
1323-
hir::ItemKind::ForeignMod(ref fm) => record!(self.tables.children[def_id] <-
1324-
fm.items
1323+
hir::ItemKind::ForeignMod { items, .. } => record!(self.tables.children[def_id] <-
1324+
items
13251325
.iter()
13261326
.map(|foreign_item| tcx.hir().local_def_id(
13271327
foreign_item.id.hir_id).local_def_index)
@@ -1836,7 +1836,7 @@ impl EncodeContext<'a, 'tcx> {
18361836
| hir::ItemKind::Const(..)
18371837
| hir::ItemKind::Fn(..)
18381838
| hir::ItemKind::Mod(..)
1839-
| hir::ItemKind::ForeignMod(..)
1839+
| hir::ItemKind::ForeignMod { .. }
18401840
| hir::ItemKind::GlobalAsm(..)
18411841
| hir::ItemKind::ExternCrate(..)
18421842
| hir::ItemKind::Use(..)

compiler/rustc_middle/src/hir/map/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'hir> Map<'hir> {
205205
ItemKind::TraitAlias(..) => DefKind::TraitAlias,
206206
ItemKind::ExternCrate(_) => DefKind::ExternCrate,
207207
ItemKind::Use(..) => DefKind::Use,
208-
ItemKind::ForeignMod(..) => DefKind::ForeignMod,
208+
ItemKind::ForeignMod { .. } => DefKind::ForeignMod,
209209
ItemKind::GlobalAsm(..) => DefKind::GlobalAsm,
210210
ItemKind::Impl { .. } => DefKind::Impl,
211211
},
@@ -729,10 +729,11 @@ impl<'hir> Map<'hir> {
729729
let parent = self.get_parent_item(hir_id);
730730
if let Some(entry) = self.find_entry(parent) {
731731
if let Entry {
732-
node: Node::Item(Item { kind: ItemKind::ForeignMod(ref nm), .. }), ..
732+
node: Node::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }),
733+
..
733734
} = entry
734735
{
735-
return nm.abi;
736+
return *abi;
736737
}
737738
}
738739
bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent))
@@ -1045,7 +1046,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String {
10451046
ItemKind::Const(..) => "const",
10461047
ItemKind::Fn(..) => "fn",
10471048
ItemKind::Mod(..) => "mod",
1048-
ItemKind::ForeignMod(..) => "foreign mod",
1049+
ItemKind::ForeignMod { .. } => "foreign mod",
10491050
ItemKind::GlobalAsm(..) => "global asm",
10501051
ItemKind::TyAlias(..) => "ty",
10511052
ItemKind::OpaqueTy(..) => "opaque type",

compiler/rustc_mir/src/monomorphize/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
993993
match item.kind {
994994
hir::ItemKind::ExternCrate(..)
995995
| hir::ItemKind::Use(..)
996-
| hir::ItemKind::ForeignMod(..)
996+
| hir::ItemKind::ForeignMod { .. }
997997
| hir::ItemKind::TyAlias(..)
998998
| hir::ItemKind::Trait(..)
999999
| hir::ItemKind::TraitAlias(..)

compiler/rustc_passes/src/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
190190

191191
intravisit::walk_item(self, &item);
192192
}
193-
hir::ItemKind::ForeignMod(..) => {}
193+
hir::ItemKind::ForeignMod { .. } => {}
194194
_ => {
195195
intravisit::walk_item(self, &item);
196196
}

compiler/rustc_passes/src/reachable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl<'tcx> ReachableContext<'tcx> {
262262
| hir::ItemKind::TyAlias(..)
263263
| hir::ItemKind::Static(..)
264264
| hir::ItemKind::Mod(..)
265-
| hir::ItemKind::ForeignMod(..)
265+
| hir::ItemKind::ForeignMod { .. }
266266
| hir::ItemKind::Impl { .. }
267267
| hir::ItemKind::Trait(..)
268268
| hir::ItemKind::TraitAlias(..)

compiler/rustc_passes/src/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
326326
// they don't have their own stability. They still can be annotated as unstable
327327
// and propagate this unstability to children, but this annotation is completely
328328
// optional. They inherit stability from their parents when unannotated.
329-
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..) => {
329+
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod { .. } => {
330330
self.in_trait_impl = false;
331331
kind = AnnotationKind::Container;
332332
}
@@ -499,7 +499,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
499499
// optional. They inherit stability from their parents when unannotated.
500500
if !matches!(
501501
i.kind,
502-
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..)
502+
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod{..}
503503
) {
504504
self.check_missing_stability(i.hir_id, i.span);
505505
}

compiler/rustc_privacy/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
592592
Option::<AccessLevel>::of_impl(item.hir_id, self.tcx, &self.access_levels)
593593
}
594594
// Foreign modules inherit level from parents.
595-
hir::ItemKind::ForeignMod(..) => self.prev_level,
595+
hir::ItemKind::ForeignMod { .. } => self.prev_level,
596596
// Other `pub` items inherit levels from parents.
597597
hir::ItemKind::Const(..)
598598
| hir::ItemKind::Enum(..)
@@ -654,8 +654,8 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
654654
}
655655
}
656656
}
657-
hir::ItemKind::ForeignMod(ref foreign_mod) => {
658-
for foreign_item in foreign_mod.items {
657+
hir::ItemKind::ForeignMod { items, .. } => {
658+
for foreign_item in items {
659659
if foreign_item.vis.node.is_pub() {
660660
self.update(foreign_item.id.hir_id, item_level);
661661
}
@@ -770,8 +770,8 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
770770
}
771771
}
772772
// Visit everything, but foreign items have their own levels.
773-
hir::ItemKind::ForeignMod(ref foreign_mod) => {
774-
for foreign_item in foreign_mod.items {
773+
hir::ItemKind::ForeignMod { items, .. } => {
774+
for foreign_item in items {
775775
let foreign_item_level = self.get(foreign_item.id.hir_id);
776776
if foreign_item_level.is_some() {
777777
self.reach(foreign_item.id.hir_id, foreign_item_level)
@@ -1430,7 +1430,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
14301430

14311431
// An `extern {}` doesn't introduce a new privacy
14321432
// namespace (the contents have their own privacies).
1433-
hir::ItemKind::ForeignMod(_) => {}
1433+
hir::ItemKind::ForeignMod { .. } => {}
14341434

14351435
hir::ItemKind::Trait(.., ref bounds, _) => {
14361436
if !self.trait_is_public(item.hir_id) {
@@ -1948,8 +1948,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
19481948
}
19491949
}
19501950
// Subitems of foreign modules have their own publicity.
1951-
hir::ItemKind::ForeignMod(ref foreign_mod) => {
1952-
for foreign_item in foreign_mod.items {
1951+
hir::ItemKind::ForeignMod { items, .. } => {
1952+
for foreign_item in items {
19531953
let vis = tcx.visibility(tcx.hir().local_def_id(foreign_item.id.hir_id));
19541954
self.check(foreign_item.id.hir_id, vis).generics().predicates().ty();
19551955
}

compiler/rustc_resolve/src/late/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
388388
hir::ItemKind::ExternCrate(_)
389389
| hir::ItemKind::Use(..)
390390
| hir::ItemKind::Mod(..)
391-
| hir::ItemKind::ForeignMod(..)
391+
| hir::ItemKind::ForeignMod { .. }
392392
| hir::ItemKind::GlobalAsm(..) => {
393393
// These sorts of items have no lifetime parameters at all.
394394
intravisit::walk_item(self, item);

compiler/rustc_save_analysis/src/sig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'hir> Sig for hir::Item<'hir> {
550550

551551
// FIXME where clause
552552
}
553-
hir::ItemKind::ForeignMod(_) => Err("extern mod"),
553+
hir::ItemKind::ForeignMod { .. } => Err("extern mod"),
554554
hir::ItemKind::GlobalAsm(_) => Err("global asm"),
555555
hir::ItemKind::ExternCrate(_) => Err("extern crate"),
556556
hir::ItemKind::OpaqueTy(..) => Err("opaque type"),

compiler/rustc_typeck/src/check/check.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -746,21 +746,21 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
746746
let generics = tcx.generics_of(def_id);
747747
check_type_params_are_used(tcx, &generics, pty_ty);
748748
}
749-
hir::ItemKind::ForeignMod(ref m) => {
750-
check_abi(tcx, it.span, m.abi);
749+
hir::ItemKind::ForeignMod { abi, items } => {
750+
check_abi(tcx, it.span, abi);
751751

752-
if m.abi == Abi::RustIntrinsic {
753-
for item in m.items {
752+
if abi == Abi::RustIntrinsic {
753+
for item in items {
754754
let item = tcx.hir().foreign_item(item.id);
755755
intrinsic::check_intrinsic_type(tcx, item);
756756
}
757-
} else if m.abi == Abi::PlatformIntrinsic {
758-
for item in m.items {
757+
} else if abi == Abi::PlatformIntrinsic {
758+
for item in items {
759759
let item = tcx.hir().foreign_item(item.id);
760760
intrinsic::check_platform_intrinsic_type(tcx, item);
761761
}
762762
} else {
763-
for item in m.items {
763+
for item in items {
764764
let def_id = tcx.hir().local_def_id(item.id.hir_id);
765765
let generics = tcx.generics_of(def_id);
766766
let own_counts = generics.own_counts();
@@ -796,7 +796,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
796796
let item = tcx.hir().foreign_item(item.id);
797797
match item.kind {
798798
hir::ForeignItemKind::Fn(ref fn_decl, _, _) => {
799-
require_c_abi_if_c_variadic(tcx, fn_decl, m.abi, item.span);
799+
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
800800
}
801801
hir::ForeignItemKind::Static(..) => {
802802
check_static_inhabited(tcx, def_id, item.span);

compiler/rustc_typeck/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
156156
hir::ItemKind::Const(ref ty, ..) => {
157157
check_item_type(tcx, item.hir_id, ty.span, false);
158158
}
159-
hir::ItemKind::ForeignMod(ref module) => {
160-
for it in module.items.iter() {
159+
hir::ItemKind::ForeignMod { items, .. } => {
160+
for it in items.iter() {
161161
let it = tcx.hir().foreign_item(it.id);
162162
match it.kind {
163163
hir::ForeignItemKind::Fn(ref decl, ..) => {

0 commit comments

Comments
 (0)