about summary refs log tree commit diff
path: root/src/liballoc_system
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/liballoc_system
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/liballoc_system')
-rw-r--r--src/liballoc_system/lib.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs
index c6507282b24..bf27e972177 100644
--- a/src/liballoc_system/lib.rs
+++ b/src/liballoc_system/lib.rs
@@ -42,6 +42,7 @@ const MIN_ALIGN: usize = 8;
 const MIN_ALIGN: usize = 16;
 
 use core::alloc::{Alloc, GlobalAlloc, AllocErr, Layout, Void};
+use core::ptr::NonNull;
 
 #[unstable(feature = "allocator_api", issue = "32838")]
 pub struct System;
@@ -49,26 +50,26 @@ pub struct System;
 #[unstable(feature = "allocator_api", issue = "32838")]
 unsafe impl Alloc for System {
     #[inline]
-    unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
+    unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
         GlobalAlloc::alloc(self, layout).into()
     }
 
     #[inline]
-    unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
+    unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
         GlobalAlloc::alloc_zeroed(self, layout).into()
     }
 
     #[inline]
-    unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
-        GlobalAlloc::dealloc(self, ptr as *mut Void, layout)
+    unsafe fn dealloc(&mut self, ptr: NonNull<Void>, layout: Layout) {
+        GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
     }
 
     #[inline]
     unsafe fn realloc(&mut self,
-                      ptr: *mut u8,
+                      ptr: NonNull<Void>,
                       old_layout: Layout,
-                      new_size: usize) -> Result<*mut u8, AllocErr> {
-        GlobalAlloc::realloc(self, ptr as *mut Void, old_layout, new_size).into()
+                      new_size: usize) -> Result<NonNull<Void>, AllocErr> {
+        GlobalAlloc::realloc(self, ptr.as_ptr(), old_layout, new_size).into()
     }
 
     #[inline]
@@ -81,26 +82,26 @@ unsafe impl Alloc for System {
 #[unstable(feature = "allocator_api", issue = "32838")]
 unsafe impl<'a> Alloc for &'a System {
     #[inline]
-    unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
+    unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
         GlobalAlloc::alloc(*self, layout).into()
     }
 
     #[inline]
-    unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
+    unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
         GlobalAlloc::alloc_zeroed(*self, layout).into()
     }
 
     #[inline]
-    unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
-        GlobalAlloc::dealloc(*self, ptr as *mut Void, layout)
+    unsafe fn dealloc(&mut self, ptr: NonNull<Void>, layout: Layout) {
+        GlobalAlloc::dealloc(*self, ptr.as_ptr(), layout)
     }
 
     #[inline]
     unsafe fn realloc(&mut self,
-                      ptr: *mut u8,
+                      ptr: NonNull<Void>,
                       old_layout: Layout,
-                      new_size: usize) -> Result<*mut u8, AllocErr> {
-        GlobalAlloc::realloc(*self, ptr as *mut Void, old_layout, new_size).into()
+                      new_size: usize) -> Result<NonNull<Void>, AllocErr> {
+        GlobalAlloc::realloc(*self, ptr.as_ptr(), old_layout, new_size).into()
     }
 
     #[inline]