about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-05-01 01:18:36 +0800
committerGitHub <noreply@github.com>2018-05-01 01:18:36 +0800
commitb88c152784f36825a2a75b062db6cc55ff02297f (patch)
treed46a6974a13307856ecbbfd711ac1be5c3032893 /src/libcore
parent64e6dda0bce96da47e52f7f3e278d05f7a09473c (diff)
parentf9f992379de4a82637ec4bf717ff42f27872bc48 (diff)
downloadrust-b88c152784f36825a2a75b062db6cc55ff02297f.tar.gz
rust-b88c152784f36825a2a75b062db6cc55ff02297f.zip
Rollup merge of #50233 - mark-i-m:const_vec, r=kennytm
Make `Vec::new` a `const fn`

`RawVec::empty/_in` are a hack. They're there because `if size_of::<T> == 0 { !0 } else { 0 }` is not allowed in `const` yet. However, because `RawVec` is unstable, the `empty/empty_in` constructors can be removed when #49146 is done...
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ptr.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index c61bdfc9c4f..5d0b675e8e4 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -2552,10 +2552,9 @@ impl<T: Sized> Unique<T> {
     /// This is useful for initializing types which lazily allocate, like
     /// `Vec::new` does.
     // FIXME: rename to dangling() to match NonNull?
-    pub fn empty() -> Self {
+    pub const fn empty() -> Self {
         unsafe {
-            let ptr = mem::align_of::<T>() as *mut T;
-            Unique::new_unchecked(ptr)
+            Unique::new_unchecked(mem::align_of::<T>() as *mut T)
         }
     }
 }