Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use is_lang_panic_fn from check_consts in promote_consts
  • Loading branch information
ecstatic-morse committed Oct 26, 2019
commit 653865658d8ac4001d712fb26f382a84ed36f951
3 changes: 2 additions & 1 deletion src/librustc_mir/transform/check_consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ impl fmt::Display for ConstKind {
}
}

fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
/// Returns `true` if this `DefId` points to one of the official `panic` lang items.
pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
Some(def_id) == tcx.lang_items().panic_fn() ||
Some(def_id) == tcx.lang_items().begin_panic_fn()
}
9 changes: 2 additions & 7 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use rustc_target::spec::abi::Abi;

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

use crate::transform::check_consts::{qualifs, Item, ConstKind};
use crate::transform::check_consts::{qualifs, Item, ConstKind, is_lang_panic_fn};

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

impl<'tcx> Validator<'_, 'tcx> {
fn is_const_panic_fn(&self, def_id: DefId) -> bool {
Some(def_id) == self.tcx.lang_items().panic_fn() ||
Some(def_id) == self.tcx.lang_items().begin_panic_fn()
}

fn validate_candidate(&self, candidate: Candidate) -> Result<(), Unpromotable> {
match candidate {
Candidate::Ref(loc) => {
Expand Down Expand Up @@ -700,7 +695,7 @@ impl<'tcx> Validator<'_, 'tcx> {
ty::FnDef(def_id, _) => {
self.tcx.is_const_fn(def_id) ||
self.tcx.is_unstable_const_fn(def_id).is_some() ||
self.is_const_panic_fn(def_id)
is_lang_panic_fn(self.tcx, self.def_id)
}
_ => false,
};
Expand Down