Skip to content

Commit 4cc1973

Browse files
committed
Retire hir::ForeignItemRef.
1 parent 8ef69d9 commit 4cc1973

File tree

11 files changed

+27
-55
lines changed

11 files changed

+27
-55
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
397397
self.visit_nested_impl_item(id);
398398
}
399399

400-
fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef) {
401-
// Do not visit the duplicate information in ForeignItemRef. We want to
402-
// map the actual nodes, not the duplicate ones in the *Ref.
403-
let ForeignItemRef { id, ident: _, span: _ } = *fi;
404-
405-
self.visit_nested_foreign_item(id);
400+
fn visit_foreign_item_ref(&mut self, id: &'hir ForeignItemId) {
401+
self.visit_nested_foreign_item(*id);
406402
}
407403

408404
fn visit_where_predicate(&mut self, predicate: &'hir WherePredicate<'hir>) {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
703703
self.arena.alloc(item)
704704
}
705705

706-
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
707-
hir::ForeignItemRef {
708-
id: hir::ForeignItemId { owner_id: self.owner_id(i.id) },
709-
// `unwrap` is safe because `ForeignItemKind::MacCall` is the only foreign item kind
710-
// without an identifier and it cannot reach here.
711-
ident: self.lower_ident(i.kind.ident().unwrap()),
712-
span: self.lower_span(i.span),
713-
}
706+
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemId {
707+
hir::ForeignItemId { owner_id: self.owner_id(i.id) }
714708
}
715709

716710
fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> {

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,7 +4137,7 @@ impl<'hir> Item<'hir> {
41374137

41384138
expect_mod, (Ident, &'hir Mod<'hir>), ItemKind::Mod(ident, m), (*ident, m);
41394139

4140-
expect_foreign_mod, (ExternAbi, &'hir [ForeignItemRef]),
4140+
expect_foreign_mod, (ExternAbi, &'hir [ForeignItemId]),
41414141
ItemKind::ForeignMod { abi, items }, (*abi, items);
41424142

41434143
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm { asm, .. }, asm;
@@ -4314,7 +4314,7 @@ pub enum ItemKind<'hir> {
43144314
/// A module.
43154315
Mod(Ident, &'hir Mod<'hir>),
43164316
/// An external module, e.g. `extern { .. }`.
4317-
ForeignMod { abi: ExternAbi, items: &'hir [ForeignItemRef] },
4317+
ForeignMod { abi: ExternAbi, items: &'hir [ForeignItemId] },
43184318
/// Module-level inline assembly (from `global_asm!`).
43194319
GlobalAsm {
43204320
asm: &'hir InlineAsm<'hir>,
@@ -4467,19 +4467,6 @@ impl ForeignItemId {
44674467
}
44684468
}
44694469

4470-
/// A reference from a foreign block to one of its items. This
4471-
/// contains the item's ID, naturally, but also the item's name and
4472-
/// some other high-level details (like whether it is an associated
4473-
/// type or method, and whether it is public). This allows other
4474-
/// passes to find the impl they want without loading the ID (which
4475-
/// means fewer edges in the incremental compilation graph).
4476-
#[derive(Debug, Clone, Copy, HashStable_Generic)]
4477-
pub struct ForeignItemRef {
4478-
pub id: ForeignItemId,
4479-
pub ident: Ident,
4480-
pub span: Span,
4481-
}
4482-
44834470
#[derive(Debug, Clone, Copy, HashStable_Generic)]
44844471
pub struct ForeignItem<'hir> {
44854472
pub ident: Ident,

compiler/rustc_hir/src/intravisit.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ pub trait Visitor<'v>: Sized {
441441
fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) -> Self::Result {
442442
walk_impl_item(self, ii)
443443
}
444-
fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef) -> Self::Result {
445-
walk_foreign_item_ref(self, ii)
444+
fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemId) -> Self::Result {
445+
walk_foreign_item_ref(self, *ii)
446446
}
447447
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) -> Self::Result {
448448
walk_impl_item_ref(self, ii)
@@ -1290,13 +1290,8 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(
12901290
}
12911291
}
12921292

1293-
pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(
1294-
visitor: &mut V,
1295-
foreign_item_ref: &'v ForeignItemRef,
1296-
) -> V::Result {
1297-
let ForeignItemRef { id, ident, span: _ } = *foreign_item_ref;
1298-
try_visit!(visitor.visit_nested_foreign_item(id));
1299-
visitor.visit_ident(ident)
1293+
pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: ForeignItemId) -> V::Result {
1294+
visitor.visit_nested_foreign_item(id)
13001295
}
13011296

13021297
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,9 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
870870
};
871871
check_abi(tcx, it.hir_id(), it.span, abi);
872872

873-
for item in items {
874-
let def_id = item.id.owner_id.def_id;
873+
for &item in items {
874+
let def_id = item.owner_id.def_id;
875+
let item = tcx.hir_foreign_item(item);
875876

876877
let generics = tcx.generics_of(def_id);
877878
let own_counts = generics.own_counts();
@@ -903,7 +904,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
903904
.emit();
904905
}
905906

906-
let item = tcx.hir_foreign_item(item.id);
907907
match &item.kind {
908908
hir::ForeignItemKind::Fn(sig, _, _) => {
909909
require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span);

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,8 @@ pub(super) fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
661661
| hir::ItemKind::Mod(..)
662662
| hir::ItemKind::GlobalAsm { .. } => {}
663663
hir::ItemKind::ForeignMod { items, .. } => {
664-
for item in *items {
665-
let item = tcx.hir_foreign_item(item.id);
664+
for &item in *items {
665+
let item = tcx.hir_foreign_item(item);
666666
tcx.ensure_ok().generics_of(item.owner_id);
667667
tcx.ensure_ok().type_of(item.owner_id);
668668
tcx.ensure_ok().predicates_of(item.owner_id);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ impl<'a> State<'a> {
655655
let (cb, ib) = self.head("extern");
656656
self.word_nbsp(abi.to_string());
657657
self.bopen(ib);
658-
for item in items {
659-
self.ann.nested(self, Nested::ForeignItem(item.id));
658+
for &foreign_item in items {
659+
self.ann.nested(self, Nested::ForeignItem(foreign_item));
660660
}
661661
self.bclose(item.span, cb);
662662
}

compiler/rustc_metadata/src/foreign_modules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn collect(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> FxIndexMap<Def
1919
let item = tcx.hir_item(id);
2020

2121
if let hir::ItemKind::ForeignMod { abi, items } = item.kind {
22-
let foreign_items = items.iter().map(|it| it.id.owner_id.to_def_id()).collect();
22+
let foreign_items = items.iter().map(|it| it.owner_id.to_def_id()).collect();
2323
modules.insert(def_id, ForeignModule { def_id, abi, foreign_items });
2424
}
2525
}

compiler/rustc_passes/src/input_stats.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
459459
hir_visit::walk_impl_item(self, ii)
460460
}
461461

462-
fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemRef) {
463-
self.record("ForeignItemRef", Some(fi.id.hir_id()), fi);
464-
hir_visit::walk_foreign_item_ref(self, fi)
462+
fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemId) {
463+
self.record("ForeignItemId", Some(fi.hir_id()), fi);
464+
hir_visit::walk_foreign_item_ref(self, *fi)
465465
}
466466

467467
fn visit_impl_item_ref(&mut self, ii: &'v hir::ImplItemRef) {

compiler/rustc_privacy/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
755755
}
756756
hir::ItemKind::ForeignMod { items, .. } => {
757757
for foreign_item in items {
758-
if let Some(foreign_item_ev) = self.get(foreign_item.id.owner_id.def_id) {
759-
self.reach(foreign_item.id.owner_id.def_id, foreign_item_ev)
758+
if let Some(foreign_item_ev) = self.get(foreign_item.owner_id.def_id) {
759+
self.reach(foreign_item.owner_id.def_id, foreign_item_ev)
760760
.generics()
761761
.predicates()
762762
.ty();
@@ -1658,8 +1658,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
16581658
DefKind::ForeignMod => {
16591659
let item = tcx.hir_item(id);
16601660
if let hir::ItemKind::ForeignMod { items, .. } = item.kind {
1661-
for foreign_item in items {
1662-
let foreign_item = tcx.hir_foreign_item(foreign_item.id);
1661+
for &foreign_item in items {
1662+
let foreign_item = tcx.hir_foreign_item(foreign_item);
16631663

16641664
let ev = self.get(foreign_item.owner_id.def_id);
16651665
let vis = tcx.local_visibility(foreign_item.owner_id.def_id);

src/librustdoc/visit_ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
430430

431431
match item.kind {
432432
hir::ItemKind::ForeignMod { items, .. } => {
433-
for item in items {
434-
let item = tcx.hir_foreign_item(item.id);
433+
for &item in items {
434+
let item = tcx.hir_foreign_item(item);
435435
self.visit_foreign_item_inner(item, None);
436436
}
437437
}

0 commit comments

Comments
 (0)