diff options
| author | Christopher Durham <cad97@cad97.com> | 2019-11-09 13:43:11 -0500 |
|---|---|---|
| committer | CAD97 <cad97@cad97.com> | 2020-01-09 13:41:40 -0500 |
| commit | e47fec56dd438c416ce45b06c9b3b23103c4ee3a (patch) | |
| tree | 493d459085ad3cebc4040aceeacec705ce6782e2 | |
| parent | c404ce689f7692f2c9b1df51803faf88ba11d2e8 (diff) | |
| download | rust-e47fec56dd438c416ce45b06c9b3b23103c4ee3a.tar.gz rust-e47fec56dd438c416ce45b06c9b3b23103c4ee3a.zip | |
Make Layout::new const
| -rw-r--r-- | src/libcore/alloc.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index b2d4b1b5fb9..37672888d01 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -17,7 +17,7 @@ use crate::usize; #[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 @@ impl Layout { /// 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) } } |
