Skip to content

Commit

Permalink
adjust enum naming
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 13, 2020
1 parent f32cccc commit f61fb53
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,34 +453,34 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// These are intrinsics that compile to panics so that we can get a message
// which mentions the offending type, even from a const context.
#[derive(Debug, PartialEq)]
enum PanicIntrinsic {
IfUninhabited,
IfZeroInvalid,
IfAnyInvalid,
enum AssertIntrinsic {
Inhabited,
ZeroValid,
UninitValid,
};
let panic_intrinsic = intrinsic.and_then(|i| match i {
// FIXME: Move to symbols instead of strings.
"assert_inhabited" => Some(PanicIntrinsic::IfUninhabited),
"assert_zero_valid" => Some(PanicIntrinsic::IfZeroInvalid),
"assert_uninit_valid" => Some(PanicIntrinsic::IfAnyInvalid),
"assert_inhabited" => Some(AssertIntrinsic::Inhabited),
"assert_zero_valid" => Some(AssertIntrinsic::ZeroValid),
"assert_uninit_valid" => Some(AssertIntrinsic::UninitValid),
_ => None,
});
if let Some(intrinsic) = panic_intrinsic {
use PanicIntrinsic::*;
use AssertIntrinsic::*;
let ty = instance.unwrap().substs.type_at(0);
let layout = bx.layout_of(ty);
let do_panic = match intrinsic {
IfUninhabited => layout.abi.is_uninhabited(),
Inhabited => layout.abi.is_uninhabited(),
// We unwrap as the error type is `!`.
IfZeroInvalid => !layout.might_permit_raw_init(bx, /*zero:*/ true).unwrap(),
ZeroValid => !layout.might_permit_raw_init(bx, /*zero:*/ true).unwrap(),
// We unwrap as the error type is `!`.
IfAnyInvalid => !layout.might_permit_raw_init(bx, /*zero:*/ false).unwrap(),
UninitValid => !layout.might_permit_raw_init(bx, /*zero:*/ false).unwrap(),
};
if do_panic {
let msg_str = if layout.abi.is_uninhabited() {
// Use this error even for the other intrinsics as it is more precise.
format!("attempted to instantiate uninhabited type `{}`", ty)
} else if intrinsic == IfZeroInvalid {
} else if intrinsic == ZeroValid {
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
} else {
format!("attempted to leave type `{}` uninitialized, which is invalid", ty)
Expand Down

0 comments on commit f61fb53

Please sign in to comment.