Undo fn -> const fn for all intrinsics but assert_inhabited

This commit is contained in:
Albin Hedman 2020-12-02 21:07:40 +01:00
parent f311db100b
commit 4f9fd2a5d4
2 changed files with 1 additions and 19 deletions

View File

@ -407,29 +407,13 @@ pub fn emulate_intrinsic(
sym::transmute => {
self.copy_op_transmute(args[0], dest)?;
}
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
sym::assert_inhabited => {
let ty = instance.substs.type_at(0);
let layout = self.layout_of(ty)?;
if layout.abi.is_uninhabited() {
throw_ub_format!("attempted to instantiate uninhabited type `{}`", ty);
}
if intrinsic_name == sym::assert_zero_valid
&& !layout.might_permit_raw_init(self, /*zero:*/ true).unwrap()
{
throw_ub_format!(
"attempted to zero-initialize type `{}`, which is invalid",
ty
);
}
if intrinsic_name == sym::assert_uninit_valid
&& !layout.might_permit_raw_init(self, /*zero:*/ false).unwrap()
{
throw_ub_format!(
"attempted to leave type `{}` uninitialized, which is invalid",
ty
);
}
}
sym::simd_insert => {
let index = u64::from(self.read_scalar(args[1])?.to_u32()?);

View File

@ -822,14 +822,12 @@
/// zero-initialization: This will statically either panic, or do nothing.
///
/// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_assert_type", issue = "none")]
pub fn assert_zero_valid<T>();
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
/// bit patterns: This will statically either panic, or do nothing.
///
/// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_assert_type", issue = "none")]
pub fn assert_uninit_valid<T>();
/// Gets a reference to a static `Location` indicating where it was called.