about summary refs log tree commit diff
path: root/src/liballoc/allocator.rs
diff options
context:
space:
mode:
authorMark Simulacrum <mark.simulacrum@gmail.com>2017-07-26 06:15:01 -0600
committerGitHub <noreply@github.com>2017-07-26 06:15:01 -0600
commitb5b7266b786cb953581ba588d400bddcdae4a852 (patch)
treec957402d4bf9f3f60cc718e86bf45ebba616bf4b /src/liballoc/allocator.rs
parentbad58f27916e7e233cc2916dcc9167708077e792 (diff)
parent0d1864b8cf9585e6133aa3da2b06b29cbfb791bd (diff)
downloadrust-b5b7266b786cb953581ba588d400bddcdae4a852.tar.gz
rust-b5b7266b786cb953581ba588d400bddcdae4a852.zip
Rollup merge of #42959 - SimonSapin:nonzero-checked, r=sfackler
Make the "main" constructors of NonZero/Shared/Unique return Option

Per discussion in https://github.com/rust-lang/rust/issues/27730#issuecomment-303939441.

This is a breaking change to unstable APIs.

The old behavior is still available under the name `new_unchecked`. Note that only that one can be `const fn`, since `if` is currently not allowed in constant contexts.

In the case of `NonZero` this requires adding a new `is_zero` method to the `Zeroable` trait. I mildly dislike this, but it’s not much worse than having a `Zeroable` trait in the first place. `Zeroable` and `NonZero` are both unstable, this can be reworked later.
Diffstat (limited to 'src/liballoc/allocator.rs')
-rw-r--r--src/liballoc/allocator.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs
index ca5388b4701..efc59d2cbc8 100644
--- a/src/liballoc/allocator.rs
+++ b/src/liballoc/allocator.rs
@@ -892,7 +892,7 @@ pub unsafe trait Alloc {
     {
         let k = Layout::new::<T>();
         if k.size() > 0 {
-            unsafe { self.alloc(k).map(|p| Unique::new(p as *mut T)) }
+            unsafe { self.alloc(k).map(|p| Unique::new_unchecked(p as *mut T)) }
         } else {
             Err(AllocErr::invalid_input("zero-sized type invalid for alloc_one"))
         }
@@ -963,7 +963,7 @@ pub unsafe trait Alloc {
                 unsafe {
                     self.alloc(layout.clone())
                         .map(|p| {
-                            Unique::new(p as *mut T)
+                            Unique::new_unchecked(p as *mut T)
                         })
                 }
             }
@@ -1012,7 +1012,7 @@ pub unsafe trait Alloc {
         match (Layout::array::<T>(n_old), Layout::array::<T>(n_new), ptr.as_ptr()) {
             (Some(ref k_old), Some(ref k_new), ptr) if k_old.size() > 0 && k_new.size() > 0 => {
                 self.realloc(ptr as *mut u8, k_old.clone(), k_new.clone())
-                    .map(|p|Unique::new(p as *mut T))
+                    .map(|p|Unique::new_unchecked(p as *mut T))
             }
             _ => {
                 Err(AllocErr::invalid_input("invalid layout for realloc_array"))