Skip to content

Commit a37db46

Browse files
committed
Retire hir::ForeignItemRef.
1 parent 999adc1 commit a37db46

File tree

11 files changed

+40
-66
lines changed

11 files changed

+40
-66
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>,
@@ -4446,19 +4446,6 @@ impl ForeignItemId {
44464446
}
44474447
}
44484448

4449-
/// A reference from a foreign block to one of its items. This
4450-
/// contains the item's ID, naturally, but also the item's name and
4451-
/// some other high-level details (like whether it is an associated
4452-
/// type or method, and whether it is public). This allows other
4453-
/// passes to find the impl they want without loading the ID (which
4454-
/// means fewer edges in the incremental compilation graph).
4455-
#[derive(Debug, Clone, Copy, HashStable_Generic)]
4456-
pub struct ForeignItemRef {
4457-
pub id: ForeignItemId,
4458-
pub ident: Ident,
4459-
pub span: Span,
4460-
}
4461-
44624449
#[derive(Debug, Clone, Copy, HashStable_Generic)]
44634450
pub struct ForeignItem<'hir> {
44644451
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: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
931931

932932
check_abi(tcx, it.hir_id(), it.span, abi);
933933

934-
for item in items {
935-
let def_id = item.id.owner_id.def_id;
934+
for &item in items {
935+
let def_id = item.owner_id.def_id;
936936

937937
let generics = tcx.generics_of(def_id);
938938
let own_counts = generics.own_counts();
@@ -944,13 +944,14 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
944944
(0, _) => ("const", "consts", None),
945945
_ => ("type or const", "types or consts", None),
946946
};
947+
let span = tcx.def_span(def_id);
947948
struct_span_code_err!(
948949
tcx.dcx(),
949-
item.span,
950+
span,
950951
E0044,
951952
"foreign items may not have {kinds} parameters",
952953
)
953-
.with_span_label(item.span, format!("can't have {kinds} parameters"))
954+
.with_span_label(span, format!("can't have {kinds} parameters"))
954955
.with_help(
955956
// FIXME: once we start storing spans for type arguments, turn this
956957
// into a suggestion.
@@ -964,22 +965,23 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
964965
.emit();
965966
}
966967

967-
let item = tcx.hir_foreign_item(item.id);
968-
tcx.ensure_ok().generics_of(item.owner_id);
969-
tcx.ensure_ok().type_of(item.owner_id);
970-
tcx.ensure_ok().predicates_of(item.owner_id);
968+
tcx.ensure_ok().generics_of(def_id);
969+
tcx.ensure_ok().type_of(def_id);
970+
tcx.ensure_ok().predicates_of(def_id);
971971
if tcx.is_conditionally_const(def_id) {
972972
tcx.ensure_ok().explicit_implied_const_bounds(def_id);
973973
tcx.ensure_ok().const_conditions(def_id);
974974
}
975-
match item.kind {
976-
hir::ForeignItemKind::Fn(sig, ..) => {
977-
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
978-
tcx.ensure_ok().fn_sig(item.owner_id);
975+
match tcx.def_kind(def_id) {
976+
DefKind::Fn => {
977+
tcx.ensure_ok().codegen_fn_attrs(def_id);
978+
tcx.ensure_ok().fn_sig(def_id);
979+
let item = tcx.hir_foreign_item(item);
980+
let hir::ForeignItemKind::Fn(sig, ..) = item.kind else { bug!() };
979981
require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span);
980982
}
981-
hir::ForeignItemKind::Static(..) => {
982-
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
983+
DefKind::Static { .. } => {
984+
tcx.ensure_ok().codegen_fn_attrs(def_id);
983985
}
984986
_ => (),
985987
}

compiler/rustc_hir_pretty/src/lib.rs

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

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
@@ -480,9 +480,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
480480
hir_visit::walk_impl_item(self, ii)
481481
}
482482

483-
fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemRef) {
484-
self.record("ForeignItemRef", Some(fi.id.hir_id()), fi);
485-
hir_visit::walk_foreign_item_ref(self, fi)
483+
fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemId) {
484+
self.record("ForeignItemId", Some(fi.hir_id()), fi);
485+
hir_visit::walk_foreign_item_ref(self, *fi)
486486
}
487487

488488
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
}

tests/ui/stats/input-stats.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ hir-stats ImplItemRef 48 (NN.N%) 2 24
117117
hir-stats ExprField 40 (NN.N%) 1 40
118118
hir-stats Mod 32 (NN.N%) 1 32
119119
hir-stats Lifetime 28 (NN.N%) 1 28
120-
hir-stats ForeignItemRef 24 (NN.N%) 1 24
120+
hir-stats ForeignItemId 4 (NN.N%) 1 4
121121
hir-stats ----------------------------------------------------------------
122-
hir-stats Total 8_684 173
122+
hir-stats Total 8_664 173
123123
hir-stats ================================================================

0 commit comments

Comments
 (0)