]> git.lizzy.rs Git - rust.git/commitdiff
Make Layout::new const
authorChristopher Durham <cad97@cad97.com>
Sat, 9 Nov 2019 18:43:11 +0000 (13:43 -0500)
committerCAD97 <cad97@cad97.com>
Thu, 9 Jan 2020 18:41:40 +0000 (13:41 -0500)
src/libcore/alloc.rs

index b2d4b1b5fb91604ed310171da3dde8812a359a65..37672888d012754c5a7dfd0baab9b11cc70f7168 100644 (file)
@@ -17,7 +17,7 @@
 #[derive(Debug)]
 pub struct Excess(pub NonNull<u8>, pub usize);
 
-fn size_align<T>() -> (usize, usize) {
+const fn size_align<T>() -> (usize, usize) {
     (mem::size_of::<T>(), mem::align_of::<T>())
 }
 
@@ -121,13 +121,12 @@ pub fn align(&self) -> usize {
     /// Constructs a `Layout` suitable for holding a value of type `T`.
     #[stable(feature = "alloc_layout", since = "1.28.0")]
     #[inline]
-    pub fn new<T>() -> Self {
+    pub const fn new<T>() -> Self {
         let (size, align) = size_align::<T>();
         // Note that the align is guaranteed by rustc to be a power of two and
         // the size+align combo is guaranteed to fit in our address space. As a
         // result use the unchecked constructor here to avoid inserting code
         // that panics if it isn't optimized well enough.
-        debug_assert!(Layout::from_size_align(size, align).is_ok());
         unsafe { Layout::from_size_align_unchecked(size, align) }
     }