Skip to content

Commit e2d7cdc

Browse files
committed
Add rustc_allow_const_fn_unstable annotations to pre-existing Layout methods
1 parent 585bcc6 commit e2d7cdc

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

library/core/src/alloc/layout.rs

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl Layout {
6565
#[stable(feature = "alloc_layout", since = "1.28.0")]
6666
#[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")]
6767
#[inline]
68+
#[rustc_allow_const_fn_unstable(ptr_alignment_type)]
6869
pub const fn from_size_align(size: usize, align: usize) -> Result<Self, LayoutError> {
6970
if !align.is_power_of_two() {
7071
return Err(LayoutError);
@@ -114,6 +115,7 @@ impl Layout {
114115
#[rustc_const_stable(feature = "const_alloc_layout_unchecked", since = "1.36.0")]
115116
#[must_use]
116117
#[inline]
118+
#[rustc_allow_const_fn_unstable(ptr_alignment_type)]
117119
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
118120
// SAFETY: the caller is required to uphold the preconditions.
119121
unsafe { Layout { size, align: ValidAlign::new_unchecked(align) } }
@@ -134,6 +136,7 @@ impl Layout {
134136
#[must_use = "this returns the minimum alignment, \
135137
without modifying the layout"]
136138
#[inline]
139+
#[rustc_allow_const_fn_unstable(ptr_alignment_type)]
137140
pub const fn align(&self) -> usize {
138141
self.align.as_usize()
139142
}

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
#![feature(core_panic)]
149149
#![feature(duration_consts_float)]
150150
#![feature(maybe_uninit_uninit_array)]
151+
#![feature(ptr_alignment_type)]
151152
#![feature(ptr_metadata)]
152153
#![feature(slice_ptr_get)]
153154
#![feature(slice_split_at_unchecked)]

library/core/src/ptr/alignment.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Alignment {
2424
/// but in an `Alignment` instead of a `usize.
2525
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
2626
#[inline]
27-
pub(crate) fn of<T>() -> Self {
27+
pub const fn of<T>() -> Self {
2828
// SAFETY: rustc ensures that type alignment is always a power of two.
2929
unsafe { Alignment::new_unchecked(mem::align_of::<T>()) }
3030
}
@@ -53,6 +53,7 @@ impl Alignment {
5353
/// Equivalently, it must be `1 << exp` for some `exp` in `0..usize::BITS`.
5454
/// It must *not* be zero.
5555
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
56+
#[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
5657
#[inline]
5758
pub const unsafe fn new_unchecked(align: usize) -> Self {
5859
// SAFETY: Precondition passed to the caller.
@@ -65,6 +66,7 @@ impl Alignment {
6566

6667
/// Returns the alignment as a [`NonZeroUsize`]
6768
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
69+
#[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
6870
#[inline]
6971
pub const fn as_usize(self) -> usize {
7072
self.0 as usize

0 commit comments

Comments
 (0)