Avoid calling fn_sig
query during is_const_fn_raw
This commit is contained in:
parent
e8b270a4b6
commit
eb74096a32
1 changed files with 10 additions and 17 deletions
|
@ -99,8 +99,16 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
|||
|
||||
let node = tcx.hir().get(hir_id);
|
||||
|
||||
if let Some(whitelisted) = is_const_intrinsic(tcx, def_id) {
|
||||
whitelisted
|
||||
if let hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) =
|
||||
node
|
||||
{
|
||||
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
|
||||
// foreign items cannot be evaluated at compile-time.
|
||||
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = tcx.hir().get_foreign_abi(hir_id) {
|
||||
tcx.lookup_const_stability(def_id).is_some()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else if let Some(fn_like) = FnLikeNode::from_node(node) {
|
||||
if fn_like.constness() == hir::Constness::Const {
|
||||
return true;
|
||||
|
@ -116,21 +124,6 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
/// Const evaluability whitelist is here to check evaluability at the
|
||||
/// top level beforehand.
|
||||
fn is_const_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> Option<bool> {
|
||||
if tcx.is_closure(def_id) {
|
||||
return None;
|
||||
}
|
||||
|
||||
match tcx.fn_sig(def_id).abi() {
|
||||
Abi::RustIntrinsic | Abi::PlatformIntrinsic => {
|
||||
Some(tcx.lookup_const_stability(def_id).is_some())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether the given item is an `impl` that has a `const` modifier.
|
||||
fn is_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue