Skip to content

Commit 0eee945

Browse files
committed
Make is_intrinsic query return the intrinsic name
1 parent de4d615 commit 0eee945

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
@@ -1650,16 +1650,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16501650

16511651
let func_ty = func.ty(body, self.infcx.tcx);
16521652
if let ty::FnDef(def_id, _) = *func_ty.kind() {
1653-
if self.tcx().is_intrinsic(def_id) {
1654-
match self.tcx().item_name(def_id) {
1655-
sym::simd_shuffle => {
1656-
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
1657-
self.tcx()
1658-
.dcx()
1659-
.emit_err(SimdShuffleLastConst { span: term.source_info.span });
1660-
}
1661-
}
1662-
_ => {}
1653+
if let Some(sym::simd_shuffle) = self.tcx().intrinsic(def_id) {
1654+
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
1655+
self.tcx().dcx().emit_err(SimdShuffleLastConst { span: term.source_info.span });
16631656
}
16641657
}
16651658
}

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
@@ -526,7 +526,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
526526

527527
match instance.def {
528528
ty::InstanceDef::Intrinsic(def_id) => {
529-
assert!(self.tcx.is_intrinsic(def_id));
529+
assert!(self.tcx.intrinsic(def_id).is_some());
530530
// FIXME: Should `InPlace` arguments be reset to uninit?
531531
M::call_intrinsic(
532532
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
@@ -859,7 +859,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
859859
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
860860
// `extern` functions, and these have no way to get marked `const`. So instead we
861861
// use `rustc_const_(un)stable` attributes to mean that the intrinsic is `const`
862-
if self.ccx.is_const_stable_const_fn() || tcx.is_intrinsic(callee) {
862+
if self.ccx.is_const_stable_const_fn() || tcx.intrinsic(callee).is_some() {
863863
self.check_op(ops::FnCallUnstable(callee, None));
864864
return;
865865
}

compiler/rustc_hir_typeck/src/callee.rs

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

541541
if let Some(def_id) = def_id
542542
&& self.tcx.def_kind(def_id) == hir::def::DefKind::Fn
543-
&& self.tcx.is_intrinsic(def_id)
544-
&& self.tcx.item_name(def_id) == sym::const_eval_select
543+
&& matches!(self.tcx.intrinsic(def_id), Some(sym::const_eval_select))
545544
{
546545
let fn_sig = self.resolve_vars_if_possible(fn_sig);
547546
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
@@ -864,7 +864,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
864864
let a_sig = a.fn_sig(self.tcx);
865865
if let ty::FnDef(def_id, _) = *a.kind() {
866866
// Intrinsics are not coercible to function pointers
867-
if self.tcx.is_intrinsic(def_id) {
867+
if self.tcx.intrinsic(def_id).is_some() {
868868
return Err(TypeError::IntrinsicCast);
869869
}
870870

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
@@ -1746,8 +1746,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17461746
self.root.tables.attr_flags.get(self, index)
17471747
}
17481748

1749-
fn get_is_intrinsic(self, index: DefIndex) -> bool {
1750-
self.root.tables.is_intrinsic.get(self, index)
1749+
fn get_intrinsic(self, index: DefIndex) -> bool {
1750+
self.root.tables.intrinsic.get(self, index)
17511751
}
17521752

17531753
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
@@ -348,7 +348,7 @@ provide! { tcx, def_id, other, cdata,
348348
cdata.get_stability_implications(tcx).iter().copied().collect()
349349
}
350350
stripped_cfg_items => { cdata.get_stripped_cfg_items(cdata.cnum, tcx) }
351-
is_intrinsic => { cdata.get_is_intrinsic(def_id.index) }
351+
intrinsic => { cdata.get_intrinsic(def_id.index).then(|| tcx.item_name(def_id)) }
352352
defined_lang_items => { cdata.get_lang_items(tcx) }
353353
diagnostic_items => { cdata.get_diagnostic_items() }
354354
missing_lang_items => { cdata.get_missing_lang_items(tcx) }

0 commit comments

Comments
 (0)