Skip to content

Commit 6538656

Browse files
Use is_lang_panic_fn from check_consts in promote_consts
1 parent 748bbf2 commit 6538656

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/librustc_mir/transform/check_consts/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ impl fmt::Display for ConstKind {
117117
}
118118
}
119119

120-
fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
120+
/// Returns `true` if this `DefId` points to one of the official `panic` lang items.
121+
pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
121122
Some(def_id) == tcx.lang_items().panic_fn() ||
122123
Some(def_id) == tcx.lang_items().begin_panic_fn()
123124
}

src/librustc_mir/transform/promote_consts.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_target::spec::abi::Abi;
2929

3030
use std::{iter, mem, usize};
3131

32-
use crate::transform::check_consts::{qualifs, Item, ConstKind};
32+
use crate::transform::check_consts::{qualifs, Item, ConstKind, is_lang_panic_fn};
3333

3434
/// State of a temporary during collection and promotion.
3535
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -250,11 +250,6 @@ impl std::ops::Deref for Validator<'a, 'tcx> {
250250
struct Unpromotable;
251251

252252
impl<'tcx> Validator<'_, 'tcx> {
253-
fn is_const_panic_fn(&self, def_id: DefId) -> bool {
254-
Some(def_id) == self.tcx.lang_items().panic_fn() ||
255-
Some(def_id) == self.tcx.lang_items().begin_panic_fn()
256-
}
257-
258253
fn validate_candidate(&self, candidate: Candidate) -> Result<(), Unpromotable> {
259254
match candidate {
260255
Candidate::Ref(loc) => {
@@ -700,7 +695,7 @@ impl<'tcx> Validator<'_, 'tcx> {
700695
ty::FnDef(def_id, _) => {
701696
self.tcx.is_const_fn(def_id) ||
702697
self.tcx.is_unstable_const_fn(def_id).is_some() ||
703-
self.is_const_panic_fn(def_id)
698+
is_lang_panic_fn(self.tcx, self.def_id)
704699
}
705700
_ => false,
706701
};

0 commit comments

Comments
 (0)