Skip to content

Retire is_foreign_item query. #111686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub fn provide(providers: &mut Providers) {
fn_sig,
impl_trait_ref,
impl_polarity,
is_foreign_item,
generator_kind,
collect_mod_item_types,
is_type_alias_impl_trait,
Expand Down Expand Up @@ -1466,10 +1465,6 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
fty
}

fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
matches!(tcx.hir().get_by_def_id(def_id), Node::ForeignItem(..))
}

fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> {
match tcx.hir().get_by_def_id(def_id) {
Node::Expr(&rustc_hir::Expr {
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,14 +1254,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

fn is_foreign_item(self, id: DefIndex) -> bool {
if let Some(parent) = self.def_key(id).parent {
matches!(self.def_kind(parent), DefKind::ForeignMod)
} else {
false
}
}

#[inline]
fn def_key(self, index: DefIndex) -> DefKey {
*self
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ provide! { tcx, def_id, other, cdata,
}
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::query::Providers;
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::{par_for_each_in, DynSend, DynSync};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::*;
use rustc_query_system::ich::StableHashingContext;
Expand Down Expand Up @@ -110,6 +111,12 @@ impl<'tcx> TyCtxt<'tcx> {
None => self.type_of(def_id).map_bound(ImplSubject::Inherent),
}
}

/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
self.opt_parent(def_id.into())
.map_or(false, |parent| matches!(self.def_kind(parent), DefKind::ForeignMod))
}
}

pub fn provide(providers: &mut Providers) {
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,6 @@ rustc_queries! {
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
}

/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
query is_foreign_item(key: DefId) -> bool {
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
separate_provide_extern
}

/// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
Expand Down