about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2018-04-11 16:28:37 +0200
committerSimon Sapin <simon.sapin@exyr.org>2018-04-12 22:53:22 +0200
commited297777599081d11c4a337cf19c9b1a1112136b (patch)
tree3b0c4fd9a0e9f5e72cc8daf121d1b99b6db23154 /src
parentfddf51ee0b9765484fc316dbf3d4feb8ceea715d (diff)
downloadrust-ed297777599081d11c4a337cf19c9b1a1112136b.tar.gz
rust-ed297777599081d11c4a337cf19c9b1a1112136b.zip
Remove conversions for allocated pointers
One was now unused, and `NonNull::new(…).ok_or(AllocErr)` feels short enough
for the few cases that need the other conversion.
Diffstat (limited to 'src')
-rw-r--r--src/liballoc/alloc.rs6
-rw-r--r--src/liballoc_system/lib.rs16
-rw-r--r--src/libcore/alloc.rs17
3 files changed, 11 insertions, 28 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs
index af48aa7961e..031babe5f6d 100644
--- a/src/liballoc/alloc.rs
+++ b/src/liballoc/alloc.rs
@@ -122,7 +122,7 @@ unsafe impl GlobalAlloc for Global {
 unsafe impl Alloc for Global {
     #[inline]
     unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::alloc(self, layout).into()
+        NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr)
     }
 
     #[inline]
@@ -137,12 +137,12 @@ unsafe impl Alloc for Global {
                       new_size: usize)
                       -> Result<NonNull<Void>, AllocErr>
     {
-        GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size).into()
+        NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
     }
 
     #[inline]
     unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::alloc_zeroed(self, layout).into()
+        NonNull::new(GlobalAlloc::alloc_zeroed(self, layout)).ok_or(AllocErr)
     }
 
     #[inline]
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs
index bf27e972177..7fea6061169 100644
--- a/src/liballoc_system/lib.rs
+++ b/src/liballoc_system/lib.rs
@@ -51,12 +51,12 @@ pub struct System;
 unsafe impl Alloc for System {
     #[inline]
     unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::alloc(self, layout).into()
+        NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr)
     }
 
     #[inline]
     unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::alloc_zeroed(self, layout).into()
+        NonNull::new(GlobalAlloc::alloc_zeroed(self, layout)).ok_or(AllocErr)
     }
 
     #[inline]
@@ -67,9 +67,9 @@ unsafe impl Alloc for System {
     #[inline]
     unsafe fn realloc(&mut self,
                       ptr: NonNull<Void>,
-                      old_layout: Layout,
+                      layout: Layout,
                       new_size: usize) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::realloc(self, ptr.as_ptr(), old_layout, new_size).into()
+        NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
     }
 
     #[inline]
@@ -83,12 +83,12 @@ unsafe impl Alloc for System {
 unsafe impl<'a> Alloc for &'a System {
     #[inline]
     unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::alloc(*self, layout).into()
+        NonNull::new(GlobalAlloc::alloc(*self, layout)).ok_or(AllocErr)
     }
 
     #[inline]
     unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::alloc_zeroed(*self, layout).into()
+        NonNull::new(GlobalAlloc::alloc_zeroed(*self, layout)).ok_or(AllocErr)
     }
 
     #[inline]
@@ -99,9 +99,9 @@ unsafe impl<'a> Alloc for &'a System {
     #[inline]
     unsafe fn realloc(&mut self,
                       ptr: NonNull<Void>,
-                      old_layout: Layout,
+                      layout: Layout,
                       new_size: usize) -> Result<NonNull<Void>, AllocErr> {
-        GlobalAlloc::realloc(*self, ptr.as_ptr(), old_layout, new_size).into()
+        NonNull::new(GlobalAlloc::realloc(*self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
     }
 
     #[inline]
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs
index 632eed96049..97a49703baf 100644
--- a/src/libcore/alloc.rs
+++ b/src/libcore/alloc.rs
@@ -41,23 +41,6 @@ impl Void {
     }
 }
 
-/// Convert from a return value of GlobalAlloc::alloc to that of Alloc::alloc
-impl From<*mut Void> for Result<NonNull<Void>, AllocErr> {
-    fn from(ptr: *mut Void) -> Self {
-        NonNull::new(ptr).ok_or(AllocErr)
-    }
-}
-
-/// Convert from a return value of Alloc::alloc to that of GlobalAlloc::alloc
-impl From<Result<NonNull<Void>, AllocErr>> for *mut Void {
-    fn from(result: Result<NonNull<Void>, AllocErr>) -> Self {
-        match result {
-            Ok(ptr) => ptr.as_ptr(),
-            Err(_) => Void::null_mut(),
-        }
-    }
-}
-
 /// Represents the combination of a starting address and
 /// a total capacity of the returned block.
 #[derive(Debug)]