Retire hir::ForeignItemRef.
This commit is contained in:
parent
36bc0948e0
commit
5bd3841668
11 changed files with 40 additions and 66 deletions
|
|
@ -397,12 +397,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
self.visit_nested_impl_item(id);
|
||||
}
|
||||
|
||||
fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef) {
|
||||
// Do not visit the duplicate information in ForeignItemRef. We want to
|
||||
// map the actual nodes, not the duplicate ones in the *Ref.
|
||||
let ForeignItemRef { id, ident: _, span: _ } = *fi;
|
||||
|
||||
self.visit_nested_foreign_item(id);
|
||||
fn visit_foreign_item_ref(&mut self, id: &'hir ForeignItemId) {
|
||||
self.visit_nested_foreign_item(*id);
|
||||
}
|
||||
|
||||
fn visit_where_predicate(&mut self, predicate: &'hir WherePredicate<'hir>) {
|
||||
|
|
|
|||
|
|
@ -704,14 +704,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
self.arena.alloc(item)
|
||||
}
|
||||
|
||||
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
|
||||
hir::ForeignItemRef {
|
||||
id: hir::ForeignItemId { owner_id: self.owner_id(i.id) },
|
||||
// `unwrap` is safe because `ForeignItemKind::MacCall` is the only foreign item kind
|
||||
// without an identifier and it cannot reach here.
|
||||
ident: self.lower_ident(i.kind.ident().unwrap()),
|
||||
span: self.lower_span(i.span),
|
||||
}
|
||||
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemId {
|
||||
hir::ForeignItemId { owner_id: self.owner_id(i.id) }
|
||||
}
|
||||
|
||||
fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> {
|
||||
|
|
|
|||
|
|
@ -4138,7 +4138,7 @@ impl<'hir> Item<'hir> {
|
|||
|
||||
expect_mod, (Ident, &'hir Mod<'hir>), ItemKind::Mod(ident, m), (*ident, m);
|
||||
|
||||
expect_foreign_mod, (ExternAbi, &'hir [ForeignItemRef]),
|
||||
expect_foreign_mod, (ExternAbi, &'hir [ForeignItemId]),
|
||||
ItemKind::ForeignMod { abi, items }, (*abi, items);
|
||||
|
||||
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm { asm, .. }, asm;
|
||||
|
|
@ -4315,7 +4315,7 @@ pub enum ItemKind<'hir> {
|
|||
/// A module.
|
||||
Mod(Ident, &'hir Mod<'hir>),
|
||||
/// An external module, e.g. `extern { .. }`.
|
||||
ForeignMod { abi: ExternAbi, items: &'hir [ForeignItemRef] },
|
||||
ForeignMod { abi: ExternAbi, items: &'hir [ForeignItemId] },
|
||||
/// Module-level inline assembly (from `global_asm!`).
|
||||
GlobalAsm {
|
||||
asm: &'hir InlineAsm<'hir>,
|
||||
|
|
@ -4447,19 +4447,6 @@ impl ForeignItemId {
|
|||
}
|
||||
}
|
||||
|
||||
/// A reference from a foreign block to one of its items. This
|
||||
/// contains the item's ID, naturally, but also the item's name and
|
||||
/// some other high-level details (like whether it is an associated
|
||||
/// type or method, and whether it is public). This allows other
|
||||
/// passes to find the impl they want without loading the ID (which
|
||||
/// means fewer edges in the incremental compilation graph).
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct ForeignItemRef {
|
||||
pub id: ForeignItemId,
|
||||
pub ident: Ident,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct ForeignItem<'hir> {
|
||||
pub ident: Ident,
|
||||
|
|
|
|||
|
|
@ -441,8 +441,8 @@ pub trait Visitor<'v>: Sized {
|
|||
fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) -> Self::Result {
|
||||
walk_impl_item(self, ii)
|
||||
}
|
||||
fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef) -> Self::Result {
|
||||
walk_foreign_item_ref(self, ii)
|
||||
fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemId) -> Self::Result {
|
||||
walk_foreign_item_ref(self, *ii)
|
||||
}
|
||||
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) -> Self::Result {
|
||||
walk_impl_item_ref(self, ii)
|
||||
|
|
@ -1290,13 +1290,8 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(
|
||||
visitor: &mut V,
|
||||
foreign_item_ref: &'v ForeignItemRef,
|
||||
) -> V::Result {
|
||||
let ForeignItemRef { id, ident, span: _ } = *foreign_item_ref;
|
||||
try_visit!(visitor.visit_nested_foreign_item(id));
|
||||
visitor.visit_ident(ident)
|
||||
pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: ForeignItemId) -> V::Result {
|
||||
visitor.visit_nested_foreign_item(id)
|
||||
}
|
||||
|
||||
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(
|
||||
|
|
|
|||
|
|
@ -930,8 +930,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
|
|||
|
||||
check_abi(tcx, it.hir_id(), it.span, abi);
|
||||
|
||||
for item in items {
|
||||
let def_id = item.id.owner_id.def_id;
|
||||
for &item in items {
|
||||
let def_id = item.owner_id.def_id;
|
||||
|
||||
let generics = tcx.generics_of(def_id);
|
||||
let own_counts = generics.own_counts();
|
||||
|
|
@ -943,13 +943,14 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
|
|||
(0, _) => ("const", "consts", None),
|
||||
_ => ("type or const", "types or consts", None),
|
||||
};
|
||||
let span = tcx.def_span(def_id);
|
||||
struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
item.span,
|
||||
span,
|
||||
E0044,
|
||||
"foreign items may not have {kinds} parameters",
|
||||
)
|
||||
.with_span_label(item.span, format!("can't have {kinds} parameters"))
|
||||
.with_span_label(span, format!("can't have {kinds} parameters"))
|
||||
.with_help(
|
||||
// FIXME: once we start storing spans for type arguments, turn this
|
||||
// into a suggestion.
|
||||
|
|
@ -963,22 +964,23 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
|
|||
.emit();
|
||||
}
|
||||
|
||||
let item = tcx.hir_foreign_item(item.id);
|
||||
tcx.ensure_ok().generics_of(item.owner_id);
|
||||
tcx.ensure_ok().type_of(item.owner_id);
|
||||
tcx.ensure_ok().predicates_of(item.owner_id);
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
if tcx.is_conditionally_const(def_id) {
|
||||
tcx.ensure_ok().explicit_implied_const_bounds(def_id);
|
||||
tcx.ensure_ok().const_conditions(def_id);
|
||||
}
|
||||
match item.kind {
|
||||
hir::ForeignItemKind::Fn(sig, ..) => {
|
||||
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
|
||||
tcx.ensure_ok().fn_sig(item.owner_id);
|
||||
match tcx.def_kind(def_id) {
|
||||
DefKind::Fn => {
|
||||
tcx.ensure_ok().codegen_fn_attrs(def_id);
|
||||
tcx.ensure_ok().fn_sig(def_id);
|
||||
let item = tcx.hir_foreign_item(item);
|
||||
let hir::ForeignItemKind::Fn(sig, ..) = item.kind else { bug!() };
|
||||
require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span);
|
||||
}
|
||||
hir::ForeignItemKind::Static(..) => {
|
||||
tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
|
||||
DefKind::Static { .. } => {
|
||||
tcx.ensure_ok().codegen_fn_attrs(def_id);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -654,8 +654,8 @@ impl<'a> State<'a> {
|
|||
let (cb, ib) = self.head("extern");
|
||||
self.word_nbsp(abi.to_string());
|
||||
self.bopen(ib);
|
||||
for item in items {
|
||||
self.ann.nested(self, Nested::ForeignItem(item.id));
|
||||
for &foreign_item in items {
|
||||
self.ann.nested(self, Nested::ForeignItem(foreign_item));
|
||||
}
|
||||
self.bclose(item.span, cb);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub(crate) fn collect(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> FxIndexMap<Def
|
|||
let item = tcx.hir_item(id);
|
||||
|
||||
if let hir::ItemKind::ForeignMod { abi, items } = item.kind {
|
||||
let foreign_items = items.iter().map(|it| it.id.owner_id.to_def_id()).collect();
|
||||
let foreign_items = items.iter().map(|it| it.owner_id.to_def_id()).collect();
|
||||
modules.insert(def_id, ForeignModule { def_id, abi, foreign_items });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -480,9 +480,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
|||
hir_visit::walk_impl_item(self, ii)
|
||||
}
|
||||
|
||||
fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemRef) {
|
||||
self.record("ForeignItemRef", Some(fi.id.hir_id()), fi);
|
||||
hir_visit::walk_foreign_item_ref(self, fi)
|
||||
fn visit_foreign_item_ref(&mut self, fi: &'v hir::ForeignItemId) {
|
||||
self.record("ForeignItemId", Some(fi.hir_id()), fi);
|
||||
hir_visit::walk_foreign_item_ref(self, *fi)
|
||||
}
|
||||
|
||||
fn visit_impl_item_ref(&mut self, ii: &'v hir::ImplItemRef) {
|
||||
|
|
|
|||
|
|
@ -755,8 +755,8 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
|||
}
|
||||
hir::ItemKind::ForeignMod { items, .. } => {
|
||||
for foreign_item in items {
|
||||
if let Some(foreign_item_ev) = self.get(foreign_item.id.owner_id.def_id) {
|
||||
self.reach(foreign_item.id.owner_id.def_id, foreign_item_ev)
|
||||
if let Some(foreign_item_ev) = self.get(foreign_item.owner_id.def_id) {
|
||||
self.reach(foreign_item.owner_id.def_id, foreign_item_ev)
|
||||
.generics()
|
||||
.predicates()
|
||||
.ty();
|
||||
|
|
@ -1658,8 +1658,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
|
|||
DefKind::ForeignMod => {
|
||||
let item = tcx.hir_item(id);
|
||||
if let hir::ItemKind::ForeignMod { items, .. } = item.kind {
|
||||
for foreign_item in items {
|
||||
let foreign_item = tcx.hir_foreign_item(foreign_item.id);
|
||||
for &foreign_item in items {
|
||||
let foreign_item = tcx.hir_foreign_item(foreign_item);
|
||||
|
||||
let ev = self.get(foreign_item.owner_id.def_id);
|
||||
let vis = tcx.local_visibility(foreign_item.owner_id.def_id);
|
||||
|
|
|
|||
|
|
@ -469,8 +469,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
|
||||
match item.kind {
|
||||
hir::ItemKind::ForeignMod { items, .. } => {
|
||||
for item in items {
|
||||
let item = tcx.hir_foreign_item(item.id);
|
||||
for &item in items {
|
||||
let item = tcx.hir_foreign_item(item);
|
||||
self.visit_foreign_item_inner(item, None, None);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ hir-stats ImplItemRef 48 (NN.N%) 2 24
|
|||
hir-stats ExprField 40 (NN.N%) 1 40
|
||||
hir-stats Mod 32 (NN.N%) 1 32
|
||||
hir-stats Lifetime 28 (NN.N%) 1 28
|
||||
hir-stats ForeignItemRef 24 (NN.N%) 1 24
|
||||
hir-stats ForeignItemId 4 (NN.N%) 1 4
|
||||
hir-stats ----------------------------------------------------------------
|
||||
hir-stats Total 8_684 173
|
||||
hir-stats Total 8_664 173
|
||||
hir-stats ================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue