Skip to content

Commit c06a746

Browse files
committed
miri: improve errors for type validity assertion failures
1 parent 0cedc03 commit c06a746

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

core/src/intrinsics/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ pub fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T {
472472
}
473473

474474
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
475-
/// This will statically either panic, or do nothing.
475+
/// This will statically either panic, or do nothing. It does not *guarantee* to ever panic,
476+
/// and should only be called if an assertion failure will imply language UB in the following code.
476477
///
477478
/// This intrinsic does not have a stable counterpart.
478479
#[rustc_intrinsic_const_stable_indirect]
@@ -481,15 +482,19 @@ pub fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T {
481482
pub const fn assert_inhabited<T>();
482483

483484
/// A guard for unsafe functions that cannot ever be executed if `T` does not permit
484-
/// zero-initialization: This will statically either panic, or do nothing.
485+
/// zero-initialization: This will statically either panic, or do nothing. It does not *guarantee*
486+
/// to ever panic, and should only be called if an assertion failure will imply language UB in the
487+
/// following code.
485488
///
486489
/// This intrinsic does not have a stable counterpart.
487490
#[rustc_intrinsic_const_stable_indirect]
488491
#[rustc_nounwind]
489492
#[rustc_intrinsic]
490493
pub const fn assert_zero_valid<T>();
491494

492-
/// A guard for `std::mem::uninitialized`. This will statically either panic, or do nothing.
495+
/// A guard for `std::mem::uninitialized`. This will statically either panic, or do nothing. It does
496+
/// not *guarantee* to ever panic, and should only be called if an assertion failure will imply
497+
/// language UB in the following code.
493498
///
494499
/// This intrinsic does not have a stable counterpart.
495500
#[rustc_intrinsic_const_stable_indirect]

core/src/mem/maybe_uninit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,9 @@ impl<T> MaybeUninit<T> {
616616
// This also means that `self` must be a `value` variant.
617617
unsafe {
618618
intrinsics::assert_inhabited::<T>();
619-
ManuallyDrop::into_inner(self.value)
619+
// We do this via a raw ptr read instead of `ManuallyDrop::into_inner` so that there's
620+
// no trace of `ManuallyDrop` in Miri's error messages here.
621+
(&raw const self.value).cast::<T>().read()
620622
}
621623
}
622624

0 commit comments

Comments
 (0)