Skip to content

Commit 08e7188

Browse files
authored
Rollup merge of rust-lang#130954 - workingjubilee:stabilize-const-mut-fn, r=RalfJung
Stabilize const `ptr::write*` and `mem::replace` Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we may now also stabilize the ability to write to places during const evaluation inside our library API. So, we now propose the `const fn` version of `ptr::write` and its variants. This allows us to also stabilize `mem::replace` and `ptr::replace`. - const `mem::replace`: rust-lang#83164 (comment) - const `ptr::write{,_bytes,_unaligned}`: rust-lang#86302 (comment) Their implementation requires an additional internal stabilization of `const_intrinsic_forget`, which is required for `*::write*` and thus `*::replace`. Thus we const-stabilize the internal intrinsics `forget`, `write_bytes`, and `write_via_move`.
2 parents 4f124de + 3b820ee commit 08e7188

File tree

9 files changed

+17
-20
lines changed

9 files changed

+17
-20
lines changed

alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@
173173
#![feature(allow_internal_unstable)]
174174
#![feature(cfg_sanitize)]
175175
#![feature(const_precise_live_drops)]
176-
#![feature(const_ptr_write)]
177176
#![feature(const_try)]
178177
#![feature(decl_macro)]
179178
#![feature(dropck_eyepatch)]

alloc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![feature(const_cow_is_borrowed)]
88
#![feature(const_heap)]
99
#![cfg_attr(bootstrap, feature(const_mut_refs))]
10-
#![feature(const_ptr_write)]
1110
#![feature(const_try)]
1211
#![feature(core_intrinsics)]
1312
#![feature(extract_if)]

core/src/intrinsics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ extern "rust-intrinsic" {
10841084
/// it does not require an `unsafe` block.
10851085
/// Therefore, implementations must not require the user to uphold
10861086
/// any safety invariants.
1087-
#[rustc_const_unstable(feature = "const_intrinsic_forget", issue = "none")]
1087+
#[rustc_const_stable(feature = "const_intrinsic_forget", since = "CURRENT_RUSTC_VERSION")]
10881088
#[rustc_safe_intrinsic]
10891089
#[rustc_nounwind]
10901090
pub fn forget<T: ?Sized>(_: T);
@@ -2688,7 +2688,7 @@ extern "rust-intrinsic" {
26882688
/// This intrinsic can *only* be called where the pointer is a local without
26892689
/// projections (`write_via_move(ptr, x)`, not `write_via_move(*ptr, x)`) so
26902690
/// that it trivially obeys runtime-MIR rules about derefs in operands.
2691-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
2691+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
26922692
#[rustc_nounwind]
26932693
pub fn write_via_move<T>(ptr: *mut T, value: T);
26942694

@@ -3525,13 +3525,13 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
35253525
#[doc(alias = "memset")]
35263526
#[stable(feature = "rust1", since = "1.0.0")]
35273527
#[rustc_allowed_through_unstable_modules]
3528-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
3528+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
35293529
#[inline(always)]
35303530
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
35313531
#[rustc_diagnostic_item = "ptr_write_bytes"]
35323532
pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
35333533
extern "rust-intrinsic" {
3534-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
3534+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
35353535
#[rustc_nounwind]
35363536
fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
35373537
}

core/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
#![feature(const_hash)]
125125
#![feature(const_heap)]
126126
#![feature(const_index_range_slice_index)]
127-
#![feature(const_intrinsic_forget)]
128127
#![feature(const_ipv4)]
129128
#![feature(const_ipv6)]
130129
#![feature(const_likely)]
@@ -138,9 +137,7 @@
138137
#![feature(const_pointer_is_aligned)]
139138
#![feature(const_ptr_is_null)]
140139
#![feature(const_ptr_sub_ptr)]
141-
#![feature(const_ptr_write)]
142140
#![feature(const_raw_ptr_comparison)]
143-
#![feature(const_replace)]
144141
#![feature(const_size_of_val)]
145142
#![feature(const_size_of_val_raw)]
146143
#![feature(const_strict_overflow_ops)]

core/src/mem/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
857857
#[inline]
858858
#[stable(feature = "rust1", since = "1.0.0")]
859859
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
860-
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
860+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
861+
#[rustc_const_stable(feature = "const_replace", since = "CURRENT_RUSTC_VERSION")]
861862
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_replace")]
862863
pub const fn replace<T>(dest: &mut T, src: T) -> T {
863864
// It may be tempting to use `swap` to avoid `unsafe` here. Don't!

core/src/ptr/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,8 @@ const unsafe fn swap_nonoverlapping_simple_untyped<T>(x: *mut T, y: *mut T, coun
12631263
/// ```
12641264
#[inline]
12651265
#[stable(feature = "rust1", since = "1.0.0")]
1266-
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
1266+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
1267+
#[rustc_const_stable(feature = "const_replace", since = "CURRENT_RUSTC_VERSION")]
12671268
#[rustc_diagnostic_item = "ptr_replace"]
12681269
pub const unsafe fn replace<T>(dst: *mut T, src: T) -> T {
12691270
// SAFETY: the caller must guarantee that `dst` is valid to be
@@ -1611,7 +1612,7 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
16111612
/// ```
16121613
#[inline]
16131614
#[stable(feature = "rust1", since = "1.0.0")]
1614-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1615+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
16151616
#[rustc_diagnostic_item = "ptr_write"]
16161617
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
16171618
pub const unsafe fn write<T>(dst: *mut T, src: T) {
@@ -1719,7 +1720,8 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
17191720
/// ```
17201721
#[inline]
17211722
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
1722-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1723+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_refs_to_cell))]
1724+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
17231725
#[rustc_diagnostic_item = "ptr_write_unaligned"]
17241726
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
17251727
pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {

core/src/ptr/mut_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ impl<T: ?Sized> *mut T {
14491449
///
14501450
/// [`ptr::write`]: crate::ptr::write()
14511451
#[stable(feature = "pointer_methods", since = "1.26.0")]
1452-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1452+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
14531453
#[inline(always)]
14541454
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14551455
pub const unsafe fn write(self, val: T)
@@ -1468,7 +1468,7 @@ impl<T: ?Sized> *mut T {
14681468
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
14691469
#[doc(alias = "memset")]
14701470
#[stable(feature = "pointer_methods", since = "1.26.0")]
1471-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1471+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
14721472
#[inline(always)]
14731473
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14741474
pub const unsafe fn write_bytes(self, val: u8, count: usize)
@@ -1509,7 +1509,7 @@ impl<T: ?Sized> *mut T {
15091509
///
15101510
/// [`ptr::write_unaligned`]: crate::ptr::write_unaligned()
15111511
#[stable(feature = "pointer_methods", since = "1.26.0")]
1512-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1512+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
15131513
#[inline(always)]
15141514
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
15151515
pub const unsafe fn write_unaligned(self, val: T)

core/src/ptr/non_null.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ impl<T: ?Sized> NonNull<T> {
10131013
#[inline(always)]
10141014
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10151015
#[stable(feature = "non_null_convenience", since = "1.80.0")]
1016-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1016+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
10171017
pub const unsafe fn write(self, val: T)
10181018
where
10191019
T: Sized,
@@ -1032,7 +1032,7 @@ impl<T: ?Sized> NonNull<T> {
10321032
#[doc(alias = "memset")]
10331033
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10341034
#[stable(feature = "non_null_convenience", since = "1.80.0")]
1035-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1035+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
10361036
pub const unsafe fn write_bytes(self, val: u8, count: usize)
10371037
where
10381038
T: Sized,
@@ -1073,7 +1073,7 @@ impl<T: ?Sized> NonNull<T> {
10731073
#[inline(always)]
10741074
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10751075
#[stable(feature = "non_null_convenience", since = "1.80.0")]
1076-
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1076+
#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")]
10771077
pub const unsafe fn write_unaligned(self, val: T)
10781078
where
10791079
T: Sized,

core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#![feature(const_option_ext)]
2929
#![feature(const_pin)]
3030
#![feature(const_pointer_is_aligned)]
31-
#![feature(const_ptr_write)]
3231
#![feature(const_three_way_compare)]
3332
#![feature(const_trait_impl)]
3433
#![feature(core_intrinsics)]

0 commit comments

Comments
 (0)