Skip to content

Commit eb74096

Browse files
Avoid calling fn_sig query during is_const_fn_raw
1 parent e8b270a commit eb74096

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/librustc_mir/const_eval/fn_queries.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,16 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
9999

100100
let node = tcx.hir().get(hir_id);
101101

102-
if let Some(whitelisted) = is_const_intrinsic(tcx, def_id) {
103-
whitelisted
102+
if let hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) =
103+
node
104+
{
105+
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
106+
// foreign items cannot be evaluated at compile-time.
107+
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = tcx.hir().get_foreign_abi(hir_id) {
108+
tcx.lookup_const_stability(def_id).is_some()
109+
} else {
110+
false
111+
}
104112
} else if let Some(fn_like) = FnLikeNode::from_node(node) {
105113
if fn_like.constness() == hir::Constness::Const {
106114
return true;
@@ -116,21 +124,6 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
116124
}
117125
}
118126

119-
/// Const evaluability whitelist is here to check evaluability at the
120-
/// top level beforehand.
121-
fn is_const_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> Option<bool> {
122-
if tcx.is_closure(def_id) {
123-
return None;
124-
}
125-
126-
match tcx.fn_sig(def_id).abi() {
127-
Abi::RustIntrinsic | Abi::PlatformIntrinsic => {
128-
Some(tcx.lookup_const_stability(def_id).is_some())
129-
}
130-
_ => None,
131-
}
132-
}
133-
134127
/// Checks whether the given item is an `impl` that has a `const` modifier.
135128
fn is_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
136129
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

0 commit comments

Comments
 (0)