Skip to content

Commit e880520

Browse files
committed
Fix contract (incomplete)
1 parent 4be20fa commit e880520

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

library/alloc/src/boxed/thin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use safety::requires;
66
#[cfg(kani)]
77
#[unstable(feature="kani", issue="none")]
88
use core::kani;
9+
use core::ub_checks;
910

1011
use core::error::Error;
1112
use core::fmt::{self, Debug, Display, Formatter};
@@ -366,9 +367,10 @@ impl<H> WithHeader<H> {
366367
}
367368

368369
// Safety:
369-
#[requires(value.is_null() || value.is_aligned())]
370370
// - Assumes that either `value` can be dereferenced, or is the
371371
// `NonNull::dangling()` we use when both `T` and `H` are ZSTs.
372+
#[requires((mem::size_of_val_raw(value) == 0 && size_of::<H>() == 0) ||
373+
ub_checks::can_dereference(value))]
372374
unsafe fn drop<T: ?Sized>(&self, value: *mut T) {
373375
struct DropGuard<H> {
374376
ptr: NonNull<u8>,

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
// Library features:
9393
// tidy-alphabetical-start
9494
#![cfg_attr(kani, feature(kani))]
95+
#![cfg_attr(kani, feature(ub_checks))]
9596
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
9697
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
9798
#![feature(alloc_layout_extra)]

0 commit comments

Comments
 (0)