Skip to content

Commit ea6ac45

Browse files
authored
Rollup merge of #111686 - cjgillot:no-foreign-item, r=compiler-errors
Retire is_foreign_item query. This can be written in terms of `DefKind`. This does not deserve the cost of a query.
2 parents f5a0c63 + 37209dc commit ea6ac45

File tree

5 files changed

+7
-20
lines changed

5 files changed

+7
-20
lines changed

compiler/rustc_hir_analysis/src/collect.rs

-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ pub fn provide(providers: &mut Providers) {
7373
fn_sig,
7474
impl_trait_ref,
7575
impl_polarity,
76-
is_foreign_item,
7776
generator_kind,
7877
collect_mod_item_types,
7978
is_type_alias_impl_trait,
@@ -1466,10 +1465,6 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
14661465
fty
14671466
}
14681467

1469-
fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1470-
matches!(tcx.hir().get_by_def_id(def_id), Node::ForeignItem(..))
1471-
}
1472-
14731468
fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> {
14741469
match tcx.hir().get_by_def_id(def_id) {
14751470
Node::Expr(&rustc_hir::Expr {

compiler/rustc_metadata/src/rmeta/decoder.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1251,14 +1251,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12511251
}
12521252
}
12531253

1254-
fn is_foreign_item(self, id: DefIndex) -> bool {
1255-
if let Some(parent) = self.def_key(id).parent {
1256-
matches!(self.def_kind(parent), DefKind::ForeignMod)
1257-
} else {
1258-
false
1259-
}
1260-
}
1261-
12621254
#[inline]
12631255
fn def_key(self, index: DefIndex) -> DefKey {
12641256
*self

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ provide! { tcx, def_id, other, cdata,
280280
}
281281
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
282282
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
283-
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
284283
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
285284
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
286285
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }

compiler/rustc_middle/src/hir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::query::Providers;
1010
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_data_structures::sync::{par_for_each_in, DynSend, DynSync};
13+
use rustc_hir::def::DefKind;
1314
use rustc_hir::def_id::{DefId, LocalDefId};
1415
use rustc_hir::*;
1516
use rustc_query_system::ich::StableHashingContext;
@@ -110,6 +111,12 @@ impl<'tcx> TyCtxt<'tcx> {
110111
None => self.type_of(def_id).map_bound(ImplSubject::Inherent),
111112
}
112113
}
114+
115+
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
116+
pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
117+
self.opt_parent(def_id.into())
118+
.map_or(false, |parent| matches!(self.def_kind(parent), DefKind::ForeignMod))
119+
}
113120
}
114121

115122
pub fn provide(providers: &mut Providers) {

compiler/rustc_middle/src/query/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,6 @@ rustc_queries! {
726726
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
727727
}
728728

729-
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
730-
query is_foreign_item(key: DefId) -> bool {
731-
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
732-
separate_provide_extern
733-
}
734-
735729
/// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
736730
query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
737731
desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }

0 commit comments

Comments
 (0)