Skip to content

Commit a1b2e19

Browse files
authored
Unrolled build for rust-lang#136877
Rollup merge of rust-lang#136877 - Sky9x:const-inherent-ptr-replace, r=jhpratt Fix missing const for inherent pointer `replace` methods `ptr::replace` (the free fn) is already const stable. However, there are inherent convenience methods on `*mut T` and `NonNull<T>`, allowing you to write eg. `unsafe { foo.replace(bar) }` where `foo` is `*mut T` or `NonNull<T>`. It seems const was never added to the inherent method (likely oversight), so this PR adds it. I don't believe this needs another[^1] FCP as the inherent methods are already stable and `ptr::replace` is already const stable, so this adds no new API. Original tracking issue: rust-lang#83164 `ptr::replace` constified in rust-lang#83091 `ptr::replace` const stabilized in rust-lang#130954 [^1]: `const_replace` FCP completed: rust-lang#83164 (comment)
2 parents 0c478fd + 7bca1f2 commit a1b2e19

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

library/core/src/ptr/mut_ptr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,9 @@ impl<T: ?Sized> *mut T {
15741574
///
15751575
/// [`ptr::replace`]: crate::ptr::replace()
15761576
#[stable(feature = "pointer_methods", since = "1.26.0")]
1577+
#[rustc_const_stable(feature = "const_inherent_ptr_replace", since = "CURRENT_RUSTC_VERSION")]
15771578
#[inline(always)]
1578-
pub unsafe fn replace(self, src: T) -> T
1579+
pub const unsafe fn replace(self, src: T) -> T
15791580
where
15801581
T: Sized,
15811582
{

library/core/src/ptr/non_null.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,8 @@ impl<T: ?Sized> NonNull<T> {
11661166
/// [`ptr::replace`]: crate::ptr::replace()
11671167
#[inline(always)]
11681168
#[stable(feature = "non_null_convenience", since = "1.80.0")]
1169-
pub unsafe fn replace(self, src: T) -> T
1169+
#[rustc_const_stable(feature = "const_inherent_ptr_replace", since = "CURRENT_RUSTC_VERSION")]
1170+
pub const unsafe fn replace(self, src: T) -> T
11701171
where
11711172
T: Sized,
11721173
{

0 commit comments

Comments
 (0)