Skip to content

Commit aa2ae6b

Browse files
committed
Add is_intrinsic helper
1 parent 7606c13 commit aa2ae6b

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed

compiler/rustc_hir_typeck/src/callee.rs

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

546546
if let Some(def_id) = def_id
547547
&& self.tcx.def_kind(def_id) == hir::def::DefKind::Fn
548-
&& matches!(self.tcx.intrinsic(def_id), Some(sym::const_eval_select))
548+
&& self.tcx.is_intrinsic(def_id, sym::const_eval_select)
549549
{
550550
let fn_sig = self.resolve_vars_if_possible(fn_sig);
551551
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
@@ -149,6 +149,7 @@ mod generic_args;
149149
mod generics;
150150
mod impls_ty;
151151
mod instance;
152+
mod intrinsic;
152153
mod list;
153154
mod opaque_types;
154155
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();

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ fn check_terminator<'tcx>(
334334
// within const fns. `transmute` is allowed in all other const contexts.
335335
// This won't really scale to more intrinsics or functions. Let's allow const
336336
// transmutes in const fn before we add more hacks to this.
337-
if matches!(tcx.intrinsic(fn_def_id), Some(sym::transmute)) {
337+
if tcx.is_intrinsic(fn_def_id, sym::transmute) {
338338
return Err((
339339
span,
340340
"can only call `transmute` from const items, not `const fn`".into(),

0 commit comments

Comments
 (0)