Skip to content

Commit d53f4ab

Browse files
committed
Make is_intrinsic query return the intrinsic name
1 parent 5c9c3c7 commit d53f4ab

File tree

22 files changed

+38
-43
lines changed

22 files changed

+38
-43
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,16 +1639,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16391639

16401640
let func_ty = func.ty(body, self.infcx.tcx);
16411641
if let ty::FnDef(def_id, _) = *func_ty.kind() {
1642-
if self.tcx().is_intrinsic(def_id) {
1643-
match self.tcx().item_name(def_id) {
1644-
sym::simd_shuffle => {
1645-
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
1646-
self.tcx()
1647-
.dcx()
1648-
.emit_err(SimdShuffleLastConst { span: term.source_info.span });
1649-
}
1650-
}
1651-
_ => {}
1642+
if let Some(sym::simd_shuffle) = self.tcx().intrinsic(def_id) {
1643+
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
1644+
self.tcx().dcx().emit_err(SimdShuffleLastConst { span: term.source_info.span });
16521645
}
16531646
}
16541647
}

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
4949
hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => {
5050
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
5151
// foreign items cannot be evaluated at compile-time.
52-
let is_const = if tcx.is_intrinsic(def_id) {
52+
let is_const = if tcx.intrinsic(def_id).is_some() {
5353
tcx.lookup_const_stability(def_id).is_some()
5454
} else {
5555
false

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
527527

528528
match instance.def {
529529
ty::InstanceDef::Intrinsic(def_id) => {
530-
assert!(self.tcx.is_intrinsic(def_id));
530+
assert!(self.tcx.intrinsic(def_id).is_some());
531531
// FIXME: Should `InPlace` arguments be reset to uninit?
532532
M::call_intrinsic(
533533
self,

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
891891
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
892892
// `extern` functions, and these have no way to get marked `const`. So instead we
893893
// use `rustc_const_(un)stable` attributes to mean that the intrinsic is `const`
894-
if self.ccx.is_const_stable_const_fn() || tcx.is_intrinsic(callee) {
894+
if self.ccx.is_const_stable_const_fn() || tcx.intrinsic(callee).is_some() {
895895
self.check_op(ops::FnCallUnstable(callee, None));
896896
return;
897897
}

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
494494

495495
if let Some(def_id) = def_id
496496
&& self.tcx.def_kind(def_id) == hir::def::DefKind::Fn
497-
&& self.tcx.is_intrinsic(def_id)
498-
&& self.tcx.item_name(def_id) == sym::const_eval_select
497+
&& matches!(self.tcx.intrinsic(def_id), Some(sym::const_eval_select))
499498
{
500499
let fn_sig = self.resolve_vars_if_possible(fn_sig);
501500
for idx in 0..=1 {

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
875875
let a_sig = a.fn_sig(self.tcx);
876876
if let ty::FnDef(def_id, _) = *a.kind() {
877877
// Intrinsics are not coercible to function pointers
878-
if self.tcx.is_intrinsic(def_id) {
878+
if self.tcx.intrinsic(def_id).is_some() {
879879
return Err(TypeError::IntrinsicCast);
880880
}
881881

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
313313

314314
if !self.same_type_modulo_infer(*found_sig, *expected_sig)
315315
|| !sig.is_suggestable(self.tcx, true)
316-
|| self.tcx.is_intrinsic(*did)
316+
|| self.tcx.intrinsic(*did).is_some()
317317
{
318318
return;
319319
}
@@ -345,8 +345,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
345345
if !self.same_type_modulo_infer(*found_sig, *expected_sig)
346346
|| !found_sig.is_suggestable(self.tcx, true)
347347
|| !expected_sig.is_suggestable(self.tcx, true)
348-
|| self.tcx.is_intrinsic(*did1)
349-
|| self.tcx.is_intrinsic(*did2)
348+
|| self.tcx.intrinsic(*did1).is_some()
349+
|| self.tcx.intrinsic(*did2).is_some()
350350
{
351351
return;
352352
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
12271227
}
12281228

12291229
fn def_id_is_transmute(cx: &LateContext<'_>, def_id: DefId) -> bool {
1230-
cx.tcx.is_intrinsic(def_id) && cx.tcx.item_name(def_id) == sym::transmute
1230+
matches!(cx.tcx.intrinsic(def_id), Some(sym::transmute))
12311231
}
12321232
}
12331233
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,8 +1744,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17441744
self.root.tables.attr_flags.get(self, index)
17451745
}
17461746

1747-
fn get_is_intrinsic(self, index: DefIndex) -> bool {
1748-
self.root.tables.is_intrinsic.get(self, index)
1747+
fn get_intrinsic(self, index: DefIndex) -> bool {
1748+
self.root.tables.intrinsic.get(self, index)
17491749
}
17501750

17511751
fn get_doc_link_resolutions(self, index: DefIndex) -> DocLinkResMap {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ provide! { tcx, def_id, other, cdata,
346346
cdata.get_stability_implications(tcx).iter().copied().collect()
347347
}
348348
stripped_cfg_items => { cdata.get_stripped_cfg_items(cdata.cnum, tcx) }
349-
is_intrinsic => { cdata.get_is_intrinsic(def_id.index) }
349+
intrinsic => { cdata.get_intrinsic(def_id.index).then(|| tcx.item_name(def_id)) }
350350
defined_lang_items => { cdata.get_lang_items(tcx) }
351351
diagnostic_items => { cdata.get_diagnostic_items() }
352352
missing_lang_items => { cdata.get_missing_lang_items(tcx) }

0 commit comments

Comments
 (0)