1
Fork 0

rename panic_if_ intrinsics to assert_

This commit is contained in:
Ralf Jung 2020-03-12 19:38:09 +01:00
parent 23de8275c9
commit f32cccc05e
5 changed files with 27 additions and 9 deletions

View file

@ -1005,17 +1005,23 @@ extern "rust-intrinsic" {
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
/// This will statically either panic, or do nothing. /// This will statically either panic, or do nothing.
#[cfg(bootstrap)]
pub fn panic_if_uninhabited<T>(); pub fn panic_if_uninhabited<T>();
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
/// This will statically either panic, or do nothing.
#[cfg(not(bootstrap))]
pub fn assert_inhabited<T>();
/// A guard for unsafe functions that cannot ever be executed if `T` does not permit /// A guard for unsafe functions that cannot ever be executed if `T` does not permit
/// zero-initialization: This will statically either panic, or do nothing. /// zero-initialization: This will statically either panic, or do nothing.
#[cfg(not(bootstrap))] #[cfg(not(bootstrap))]
pub fn panic_if_zero_invalid<T>(); pub fn assert_zero_valid<T>();
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
/// bit patterns: This will statically either panic, or do nothing. /// bit patterns: This will statically either panic, or do nothing.
#[cfg(not(bootstrap))] #[cfg(not(bootstrap))]
pub fn panic_if_any_invalid<T>(); pub fn assert_uninit_valid<T>();
/// Gets a reference to a static `Location` indicating where it was called. /// Gets a reference to a static `Location` indicating where it was called.
#[rustc_const_unstable(feature = "const_caller_location", issue = "47809")] #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]

View file

@ -495,7 +495,10 @@ impl<T> MaybeUninit<T> {
#[inline(always)] #[inline(always)]
#[rustc_diagnostic_item = "assume_init"] #[rustc_diagnostic_item = "assume_init"]
pub unsafe fn assume_init(self) -> T { pub unsafe fn assume_init(self) -> T {
#[cfg(bootstrap)]
intrinsics::panic_if_uninhabited::<T>(); intrinsics::panic_if_uninhabited::<T>();
#[cfg(not(bootstrap))]
intrinsics::assert_inhabited::<T>();
ManuallyDrop::into_inner(self.value) ManuallyDrop::into_inner(self.value)
} }
@ -559,7 +562,10 @@ impl<T> MaybeUninit<T> {
#[unstable(feature = "maybe_uninit_extra", issue = "63567")] #[unstable(feature = "maybe_uninit_extra", issue = "63567")]
#[inline(always)] #[inline(always)]
pub unsafe fn read(&self) -> T { pub unsafe fn read(&self) -> T {
#[cfg(bootstrap)]
intrinsics::panic_if_uninhabited::<T>(); intrinsics::panic_if_uninhabited::<T>();
#[cfg(not(bootstrap))]
intrinsics::assert_inhabited::<T>();
self.as_ptr().read() self.as_ptr().read()
} }
@ -621,7 +627,10 @@ impl<T> MaybeUninit<T> {
#[unstable(feature = "maybe_uninit_ref", issue = "63568")] #[unstable(feature = "maybe_uninit_ref", issue = "63568")]
#[inline(always)] #[inline(always)]
pub unsafe fn get_ref(&self) -> &T { pub unsafe fn get_ref(&self) -> &T {
#[cfg(bootstrap)]
intrinsics::panic_if_uninhabited::<T>(); intrinsics::panic_if_uninhabited::<T>();
#[cfg(not(bootstrap))]
intrinsics::assert_inhabited::<T>();
&*self.value &*self.value
} }
@ -739,7 +748,10 @@ impl<T> MaybeUninit<T> {
#[unstable(feature = "maybe_uninit_ref", issue = "63568")] #[unstable(feature = "maybe_uninit_ref", issue = "63568")]
#[inline(always)] #[inline(always)]
pub unsafe fn get_mut(&mut self) -> &mut T { pub unsafe fn get_mut(&mut self) -> &mut T {
#[cfg(bootstrap)]
intrinsics::panic_if_uninhabited::<T>(); intrinsics::panic_if_uninhabited::<T>();
#[cfg(not(bootstrap))]
intrinsics::assert_inhabited::<T>();
&mut *self.value &mut *self.value
} }

View file

@ -497,7 +497,7 @@ pub const fn needs_drop<T>() -> bool {
#[rustc_diagnostic_item = "mem_zeroed"] #[rustc_diagnostic_item = "mem_zeroed"]
pub unsafe fn zeroed<T>() -> T { pub unsafe fn zeroed<T>() -> T {
#[cfg(not(bootstrap))] #[cfg(not(bootstrap))]
intrinsics::panic_if_zero_invalid::<T>(); intrinsics::assert_zero_valid::<T>();
#[cfg(bootstrap)] #[cfg(bootstrap)]
intrinsics::panic_if_uninhabited::<T>(); intrinsics::panic_if_uninhabited::<T>();
intrinsics::init() intrinsics::init()
@ -533,7 +533,7 @@ pub unsafe fn zeroed<T>() -> T {
#[rustc_diagnostic_item = "mem_uninitialized"] #[rustc_diagnostic_item = "mem_uninitialized"]
pub unsafe fn uninitialized<T>() -> T { pub unsafe fn uninitialized<T>() -> T {
#[cfg(not(bootstrap))] #[cfg(not(bootstrap))]
intrinsics::panic_if_any_invalid::<T>(); intrinsics::assert_uninit_valid::<T>();
#[cfg(bootstrap)] #[cfg(bootstrap)]
intrinsics::panic_if_uninhabited::<T>(); intrinsics::panic_if_uninhabited::<T>();
intrinsics::uninit() intrinsics::uninit()

View file

@ -449,7 +449,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
destination: &Option<(mir::Place<'tcx>, mir::BasicBlock)>, destination: &Option<(mir::Place<'tcx>, mir::BasicBlock)>,
cleanup: Option<mir::BasicBlock>, cleanup: Option<mir::BasicBlock>,
) -> bool { ) -> bool {
// Emit a panic or a no-op for `panic_if_uninhabited`. // Emit a panic or a no-op for `assert_*` intrinsics.
// These are intrinsics that compile to panics so that we can get a message // These are intrinsics that compile to panics so that we can get a message
// which mentions the offending type, even from a const context. // which mentions the offending type, even from a const context.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -460,9 +460,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}; };
let panic_intrinsic = intrinsic.and_then(|i| match i { let panic_intrinsic = intrinsic.and_then(|i| match i {
// FIXME: Move to symbols instead of strings. // FIXME: Move to symbols instead of strings.
"panic_if_uninhabited" => Some(PanicIntrinsic::IfUninhabited), "assert_inhabited" => Some(PanicIntrinsic::IfUninhabited),
"panic_if_zero_invalid" => Some(PanicIntrinsic::IfZeroInvalid), "assert_zero_valid" => Some(PanicIntrinsic::IfZeroInvalid),
"panic_if_any_invalid" => Some(PanicIntrinsic::IfAnyInvalid), "assert_uninit_valid" => Some(PanicIntrinsic::IfAnyInvalid),
_ => None, _ => None,
}); });
if let Some(intrinsic) = panic_intrinsic { if let Some(intrinsic) = panic_intrinsic {

View file

@ -147,7 +147,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
), ),
"rustc_peek" => (1, vec![param(0)], param(0)), "rustc_peek" => (1, vec![param(0)], param(0)),
"caller_location" => (0, vec![], tcx.caller_location_ty()), "caller_location" => (0, vec![], tcx.caller_location_ty()),
"panic_if_uninhabited" | "panic_if_zero_invalid" | "panic_if_any_invalid" => { "assert_inhabited" | "assert_zero_valid" | "assert_uninit_valid" => {
(1, Vec::new(), tcx.mk_unit()) (1, Vec::new(), tcx.mk_unit())
} }
"init" => (1, Vec::new(), param(0)), "init" => (1, Vec::new(), param(0)),