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

Lines changed: 6 additions & 10 deletions
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 10 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 7 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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(..)

0 commit comments

Comments
 (0)