Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3558b13

Browse files
committed
Add is_intrinsic helper
1 parent 1d447a9 commit 3558b13

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16641664

16651665
let func_ty = func.ty(body, self.infcx.tcx);
16661666
if let ty::FnDef(def_id, _) = *func_ty.kind() {
1667-
if let Some(sym::simd_shuffle) = self.tcx().intrinsic(def_id) {
1667+
if self.tcx().is_intrinsic(def_id, sym::simd_shuffle) {
16681668
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
16691669
self.tcx().dcx().emit_err(SimdShuffleLastConst { span: term.source_info.span });
16701670
}

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +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-
&& matches!(self.tcx.intrinsic(def_id), Some(sym::const_eval_select))
543+
&& self.tcx.is_intrinsic(def_id, sym::const_eval_select)
544544
{
545545
let fn_sig = self.resolve_vars_if_possible(fn_sig);
546546
for idx in 0..=1 {

compiler/rustc_lint/src/builtin.rs

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

12331233
fn def_id_is_transmute(cx: &LateContext<'_>, def_id: DefId) -> bool {
1234-
matches!(cx.tcx.intrinsic(def_id), Some(sym::transmute))
1234+
cx.tcx.is_intrinsic(def_id, sym::transmute)
12351235
}
12361236
}
12371237
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use rustc_span::{def_id::DefId, Symbol};
2+
3+
use super::TyCtxt;
4+
5+
impl TyCtxt<'_> {
6+
pub fn is_intrinsic(self, def_id: DefId, name: Symbol) -> bool {
7+
let Some(i) = self.intrinsic(def_id) else { return false };
8+
i == name
9+
}
10+
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ mod generic_args;
148148
mod generics;
149149
mod impls_ty;
150150
mod instance;
151+
mod intrinsic;
151152
mod list;
152153
mod opaque_types;
153154
mod parameterized;

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn remap_mir_for_const_eval_select<'tcx>(
160160
fn_span,
161161
..
162162
} if let ty::FnDef(def_id, _) = *const_.ty().kind()
163-
&& matches!(tcx.intrinsic(def_id), Some(sym::const_eval_select)) =>
163+
&& tcx.is_intrinsic(def_id, sym::const_eval_select) =>
164164
{
165165
let [tupled_args, called_in_const, called_at_rt]: [_; 3] =
166166
std::mem::take(args).try_into().unwrap();

0 commit comments

Comments
 (0)