about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2018-04-03 08:51:02 +0900
committerSimon Sapin <simon.sapin@exyr.org>2018-04-12 22:53:22 +0200
commitfddf51ee0b9765484fc316dbf3d4feb8ceea715d (patch)
tree52814590ab7288801f78e8ee5493e156f3181017 /src/libstd
parentfd242ee64c5488e64e2bb677d90f2460e017b7cb (diff)
downloadrust-fddf51ee0b9765484fc316dbf3d4feb8ceea715d.tar.gz
rust-fddf51ee0b9765484fc316dbf3d4feb8ceea715d.zip
Use NonNull<Void> instead of *mut u8 in the Alloc trait
Fixes #49608
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/table.rs6
-rw-r--r--src/libstd/lib.rs1
2 files changed, 3 insertions, 4 deletions
diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs
index 50263705143..38c99373788 100644
--- a/src/libstd/collections/hash/table.rs
+++ b/src/libstd/collections/hash/table.rs
@@ -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.
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 25ba75fd35e..a34fcb5a7f9 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -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)]