Use NonNull<Void> instead of *mut u8 in the Alloc trait

Fixes #49608
This commit is contained in:
Mike Hommey
2018-04-03 08:51:02 +09:00
committed by Simon Sapin
parent fd242ee64c
commit fddf51ee0b
18 changed files with 136 additions and 129 deletions

View File

@@ -757,12 +757,10 @@ impl<K, V> RawTable<K, V> {
let buffer = Global.alloc(Layout::from_size_align(size, alignment)
.map_err(|_| CollectionAllocErr::CapacityOverflow)?)?;
let hashes = buffer as *mut HashUint;
Ok(RawTable {
capacity_mask: capacity.wrapping_sub(1),
size: 0,
hashes: TaggedHashUintPtr::new(hashes),
hashes: TaggedHashUintPtr::new(buffer.cast().as_ptr()),
marker: marker::PhantomData,
})
}
@@ -1185,7 +1183,7 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable<K, V> {
debug_assert!(!oflo, "should be impossible");
unsafe {
Global.dealloc(self.hashes.ptr() as *mut u8,
Global.dealloc(NonNull::new_unchecked(self.hashes.ptr()).as_void(),
Layout::from_size_align(size, align).unwrap());
// Remember how everything was allocated out of one buffer
// during initialization? We only need one call to free here.

View File

@@ -275,6 +275,7 @@
#![feature(macro_reexport)]
#![feature(macro_vis_matcher)]
#![feature(needs_panic_runtime)]
#![feature(nonnull_cast)]
#![feature(exhaustive_patterns)]
#![feature(nonzero)]
#![feature(num_bits_bytes)]