Skip to content

Commit f32cccc

Browse files
committed
rename panic_if_ intrinsics to assert_
1 parent 23de827 commit f32cccc

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

src/libcore/intrinsics.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1005,17 +1005,23 @@ extern "rust-intrinsic" {
10051005

10061006
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
10071007
/// This will statically either panic, or do nothing.
1008+
#[cfg(bootstrap)]
10081009
pub fn panic_if_uninhabited<T>();
10091010

1011+
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
1012+
/// This will statically either panic, or do nothing.
1013+
#[cfg(not(bootstrap))]
1014+
pub fn assert_inhabited<T>();
1015+
10101016
/// A guard for unsafe functions that cannot ever be executed if `T` does not permit
10111017
/// zero-initialization: This will statically either panic, or do nothing.
10121018
#[cfg(not(bootstrap))]
1013-
pub fn panic_if_zero_invalid<T>();
1019+
pub fn assert_zero_valid<T>();
10141020

10151021
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
10161022
/// bit patterns: This will statically either panic, or do nothing.
10171023
#[cfg(not(bootstrap))]
1018-
pub fn panic_if_any_invalid<T>();
1024+
pub fn assert_uninit_valid<T>();
10191025

10201026
/// Gets a reference to a static `Location` indicating where it was called.
10211027
#[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]

src/libcore/mem/maybe_uninit.rs

+12
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,10 @@ impl<T> MaybeUninit<T> {
495495
#[inline(always)]
496496
#[rustc_diagnostic_item = "assume_init"]
497497
pub unsafe fn assume_init(self) -> T {
498+
#[cfg(bootstrap)]
498499
intrinsics::panic_if_uninhabited::<T>();
500+
#[cfg(not(bootstrap))]
501+
intrinsics::assert_inhabited::<T>();
499502
ManuallyDrop::into_inner(self.value)
500503
}
501504

@@ -559,7 +562,10 @@ impl<T> MaybeUninit<T> {
559562
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
560563
#[inline(always)]
561564
pub unsafe fn read(&self) -> T {
565+
#[cfg(bootstrap)]
562566
intrinsics::panic_if_uninhabited::<T>();
567+
#[cfg(not(bootstrap))]
568+
intrinsics::assert_inhabited::<T>();
563569
self.as_ptr().read()
564570
}
565571

@@ -621,7 +627,10 @@ impl<T> MaybeUninit<T> {
621627
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
622628
#[inline(always)]
623629
pub unsafe fn get_ref(&self) -> &T {
630+
#[cfg(bootstrap)]
624631
intrinsics::panic_if_uninhabited::<T>();
632+
#[cfg(not(bootstrap))]
633+
intrinsics::assert_inhabited::<T>();
625634
&*self.value
626635
}
627636

@@ -739,7 +748,10 @@ impl<T> MaybeUninit<T> {
739748
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
740749
#[inline(always)]
741750
pub unsafe fn get_mut(&mut self) -> &mut T {
751+
#[cfg(bootstrap)]
742752
intrinsics::panic_if_uninhabited::<T>();
753+
#[cfg(not(bootstrap))]
754+
intrinsics::assert_inhabited::<T>();
743755
&mut *self.value
744756
}
745757

src/libcore/mem/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ pub const fn needs_drop<T>() -> bool {
497497
#[rustc_diagnostic_item = "mem_zeroed"]
498498
pub unsafe fn zeroed<T>() -> T {
499499
#[cfg(not(bootstrap))]
500-
intrinsics::panic_if_zero_invalid::<T>();
500+
intrinsics::assert_zero_valid::<T>();
501501
#[cfg(bootstrap)]
502502
intrinsics::panic_if_uninhabited::<T>();
503503
intrinsics::init()
@@ -533,7 +533,7 @@ pub unsafe fn zeroed<T>() -> T {
533533
#[rustc_diagnostic_item = "mem_uninitialized"]
534534
pub unsafe fn uninitialized<T>() -> T {
535535
#[cfg(not(bootstrap))]
536-
intrinsics::panic_if_any_invalid::<T>();
536+
intrinsics::assert_uninit_valid::<T>();
537537
#[cfg(bootstrap)]
538538
intrinsics::panic_if_uninhabited::<T>();
539539
intrinsics::uninit()

src/librustc_codegen_ssa/mir/block.rs

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

src/librustc_typeck/check/intrinsic.rs

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

0 commit comments

Comments
 (0)