diff --git a/library/alloc/src/boxed/thin.rs b/library/alloc/src/boxed/thin.rs index 40d0b12d53624..38eac27b47a9d 100644 --- a/library/alloc/src/boxed/thin.rs +++ b/library/alloc/src/boxed/thin.rs @@ -6,7 +6,10 @@ use safety::requires; #[cfg(kani)] #[unstable(feature="kani", issue="none")] use core::kani; +#[cfg(kani)] use core::ub_checks; +#[cfg(kani)] +use crate::boxed::Box; use core::error::Error; use core::fmt::{self, Debug, Display, Formatter}; @@ -370,7 +373,7 @@ impl WithHeader { // - Assumes that either `value` can be dereferenced, or is the // `NonNull::dangling()` we use when both `T` and `H` are ZSTs. #[requires((mem::size_of_val_raw(value) == 0 && size_of::() == 0) || - ub_checks::can_dereference(value))] + ub_checks::can_dereference(value as *const u8))] unsafe fn drop(&self, value: *mut T) { struct DropGuard { ptr: NonNull, @@ -452,9 +455,11 @@ mod verify { // unsafe fn drop(&self, value: *mut T) #[kani::proof_for_contract(WithHeader::drop)] pub fn check_drop() { - let w = WithHeader::new(kani::any::(), kani::any::()); - let mut x : usize = kani::any(); - let xptr = &mut x; + let v = Box::::into_raw(Box::new(kani::any::())); + let w = WithHeader::new(kani::any::(), v); + // TODO: this harness is not the most generic possible as we are currently unable to + // express the precondition that the pointer is heap-allocated. + let xptr = Box::::into_raw(Box::new(kani::any::())); unsafe { let _ = w.drop(xptr); }