Skip to content

Commit c04f0ca

Browse files
committed
make intrinsic query legal for any DefId
1 parent bf5fc6e commit c04f0ca

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1051,17 +1051,15 @@ fn should_encode_mir(
10511051
// Coroutines require optimized MIR to compute layout.
10521052
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
10531053
// Full-fledged functions + closures
1054-
def_kind @ (DefKind::AssocFn | DefKind::Fn | DefKind::Closure) => {
1054+
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
10551055
let generics = tcx.generics_of(def_id);
10561056
let mut opt = tcx.sess.opts.unstable_opts.always_encode_mir
10571057
|| (tcx.sess.opts.output_types.should_codegen()
10581058
&& reachable_set.contains(&def_id)
10591059
&& (generics.requires_monomorphization(tcx)
10601060
|| tcx.cross_crate_inlinable(def_id)));
1061-
if matches!(def_kind, DefKind::AssocFn | DefKind::Fn) {
1062-
if let Some(intrinsic) = tcx.intrinsic(def_id) {
1063-
opt &= !intrinsic.must_be_overridden;
1064-
}
1061+
if let Some(intrinsic) = tcx.intrinsic(def_id) {
1062+
opt &= !intrinsic.must_be_overridden;
10651063
}
10661064
// The function has a `const` modifier or is in a `#[const_trait]`.
10671065
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
@@ -1414,9 +1412,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14141412
if let DefKind::Fn | DefKind::AssocFn = def_kind {
14151413
self.tables.asyncness.set_some(def_id.index, tcx.asyncness(def_id));
14161414
record_array!(self.tables.fn_arg_names[def_id] <- tcx.fn_arg_names(def_id));
1417-
if let Some(name) = tcx.intrinsic(def_id) {
1418-
record!(self.tables.intrinsic[def_id] <- name);
1419-
}
1415+
}
1416+
if let Some(name) = tcx.intrinsic(def_id) {
1417+
record!(self.tables.intrinsic[def_id] <- name);
14201418
}
14211419
if let DefKind::TyParam = def_kind {
14221420
let default = self.tcx.object_lifetime_default(def_id);

compiler/rustc_middle/src/ty/util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,10 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
16431643

16441644
/// Determines whether an item is an intrinsic (which may be via Abi or via the `rustc_intrinsic` attribute)
16451645
pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
1646+
match tcx.def_kind(def_id) {
1647+
DefKind::Fn | DefKind::AssocFn => {}
1648+
_ => return None,
1649+
}
16461650
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
16471651
|| tcx.has_attr(def_id, sym::rustc_intrinsic)
16481652
{

compiler/rustc_ty_utils/src/instance.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_errors::ErrorGuaranteed;
2-
use rustc_hir::def::DefKind;
32
use rustc_hir::def_id::DefId;
43
use rustc_infer::infer::TyCtxtInferExt;
54
use rustc_middle::query::Providers;
@@ -28,8 +27,7 @@ fn resolve_instance<'tcx>(
2827
tcx.normalize_erasing_regions(param_env, args),
2928
)
3029
} else {
31-
let def = if matches!(tcx.def_kind(def_id), DefKind::Fn) && tcx.intrinsic(def_id).is_some()
32-
{
30+
let def = if tcx.intrinsic(def_id).is_some() {
3331
debug!(" => intrinsic");
3432
ty::InstanceDef::Intrinsic(def_id)
3533
} else if Some(def_id) == tcx.lang_items().drop_in_place_fn() {

0 commit comments

Comments
 (0)