]> git.lizzy.rs Git - rust.git/commitdiff
Add `rustc_allow_const_fn_unstable` annotations to pre-existing `Layout` methods
authorScott McMurray <scottmcm@users.noreply.github.com>
Wed, 21 Sep 2022 20:43:21 +0000 (13:43 -0700)
committerScott McMurray <scottmcm@users.noreply.github.com>
Wed, 21 Sep 2022 20:43:21 +0000 (13:43 -0700)
library/core/src/alloc/layout.rs
library/core/src/lib.rs
library/core/src/ptr/alignment.rs

index f03502429ab21d88049325ee1594dbd273af3036..03681a16b9d2a96653f64113cb1cfc9e0c215e06 100644 (file)
@@ -65,6 +65,7 @@ impl Layout {
     #[stable(feature = "alloc_layout", since = "1.28.0")]
     #[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")]
     #[inline]
+    #[rustc_allow_const_fn_unstable(ptr_alignment_type)]
     pub const fn from_size_align(size: usize, align: usize) -> Result<Self, LayoutError> {
         if !align.is_power_of_two() {
             return Err(LayoutError);
@@ -114,6 +115,7 @@ const fn from_size_valid_align(size: usize, align: ValidAlign) -> Result<Self, L
     #[rustc_const_stable(feature = "const_alloc_layout_unchecked", since = "1.36.0")]
     #[must_use]
     #[inline]
+    #[rustc_allow_const_fn_unstable(ptr_alignment_type)]
     pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
         // SAFETY: the caller is required to uphold the preconditions.
         unsafe { Layout { size, align: ValidAlign::new_unchecked(align) } }
@@ -134,6 +136,7 @@ pub const fn size(&self) -> usize {
     #[must_use = "this returns the minimum alignment, \
                   without modifying the layout"]
     #[inline]
+    #[rustc_allow_const_fn_unstable(ptr_alignment_type)]
     pub const fn align(&self) -> usize {
         self.align.as_usize()
     }
index 5621d15c1cd6f5d90674801fdc93aa40a63c8bf1..eeb5cb45f614fcc67cb67ad1765165a022f692d5 100644 (file)
 #![feature(core_panic)]
 #![feature(duration_consts_float)]
 #![feature(maybe_uninit_uninit_array)]
+#![feature(ptr_alignment_type)]
 #![feature(ptr_metadata)]
 #![feature(slice_ptr_get)]
 #![feature(slice_split_at_unchecked)]
index 5e7628c5a187e61a829bfa81febe4e85fc98fa2e..d0df316c770144fb19c7783398fc8a54aa1b6660 100644 (file)
@@ -24,7 +24,7 @@ impl Alignment {
     /// but in an `Alignment` instead of a `usize.
     #[unstable(feature = "ptr_alignment_type", issue = "102070")]
     #[inline]
-    pub(crate) fn of<T>() -> Self {
+    pub const fn of<T>() -> Self {
         // SAFETY: rustc ensures that type alignment is always a power of two.
         unsafe { Alignment::new_unchecked(mem::align_of::<T>()) }
     }
@@ -53,6 +53,7 @@ pub const fn new(align: usize) -> Option<Self> {
     /// Equivalently, it must be `1 << exp` for some `exp` in `0..usize::BITS`.
     /// It must *not* be zero.
     #[unstable(feature = "ptr_alignment_type", issue = "102070")]
+    #[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
     #[inline]
     pub const unsafe fn new_unchecked(align: usize) -> Self {
         // SAFETY: Precondition passed to the caller.
@@ -65,6 +66,7 @@ pub const fn new(align: usize) -> Option<Self> {
 
     /// Returns the alignment as a [`NonZeroUsize`]
     #[unstable(feature = "ptr_alignment_type", issue = "102070")]
+    #[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
     #[inline]
     pub const fn as_usize(self) -> usize {
         self.0 as usize