Skip to content

Commit def005e

Browse files
committed
Fix contract, harness still fails
1 parent e880520 commit def005e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

library/alloc/src/boxed/thin.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use safety::requires;
66
#[cfg(kani)]
77
#[unstable(feature="kani", issue="none")]
88
use core::kani;
9+
#[cfg(kani)]
910
use core::ub_checks;
11+
#[cfg(kani)]
12+
use crate::boxed::Box;
1013

1114
use core::error::Error;
1215
use core::fmt::{self, Debug, Display, Formatter};
@@ -370,7 +373,7 @@ impl<H> WithHeader<H> {
370373
// - Assumes that either `value` can be dereferenced, or is the
371374
// `NonNull::dangling()` we use when both `T` and `H` are ZSTs.
372375
#[requires((mem::size_of_val_raw(value) == 0 && size_of::<H>() == 0) ||
373-
ub_checks::can_dereference(value))]
376+
ub_checks::can_dereference(value as *const u8))]
374377
unsafe fn drop<T: ?Sized>(&self, value: *mut T) {
375378
struct DropGuard<H> {
376379
ptr: NonNull<u8>,
@@ -452,9 +455,11 @@ mod verify {
452455
// unsafe fn drop<T: ?Sized>(&self, value: *mut T)
453456
#[kani::proof_for_contract(WithHeader<T>::drop)]
454457
pub fn check_drop() {
455-
let w = WithHeader::new(kani::any::<usize>(), kani::any::<usize>());
456-
let mut x : usize = kani::any();
457-
let xptr = &mut x;
458+
let v = Box::<usize>::into_raw(Box::new(kani::any::<usize>()));
459+
let w = WithHeader::new(kani::any::<usize>(), v);
460+
// TODO: this harness is not the most generic possible as we are currently unable to
461+
// express the precondition that the pointer is heap-allocated.
462+
let xptr = Box::<usize>::into_raw(Box::new(kani::any::<usize>()));
458463
unsafe {
459464
let _ = w.drop(xptr);
460465
}

0 commit comments

Comments
 (0)