From 36ff2c84d56663592d1b99ac0a56bbd0514477b3 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Thu, 26 Sep 2024 10:36:59 -0700 Subject: [PATCH 1/3] library: Stabilize `const_intrinsic_forget` This is an implicit requirement of stabilizing `const_ptr_write`. Const-stabilizes the internal `core::intrinsics`: - `forget` --- core/src/intrinsics.rs | 2 +- core/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/intrinsics.rs b/core/src/intrinsics.rs index d7a2f1909cabe..3be0765443253 100644 --- a/core/src/intrinsics.rs +++ b/core/src/intrinsics.rs @@ -1084,7 +1084,7 @@ extern "rust-intrinsic" { /// it does not require an `unsafe` block. /// Therefore, implementations must not require the user to uphold /// any safety invariants. - #[rustc_const_unstable(feature = "const_intrinsic_forget", issue = "none")] + #[rustc_const_stable(feature = "const_intrinsic_forget", since = "CURRENT_RUSTC_VERSION")] #[rustc_safe_intrinsic] #[rustc_nounwind] pub fn forget(_: T); diff --git a/core/src/lib.rs b/core/src/lib.rs index f68f19ec6a469..3eacf7261a556 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -124,7 +124,6 @@ #![feature(const_hash)] #![feature(const_heap)] #![feature(const_index_range_slice_index)] -#![feature(const_intrinsic_forget)] #![feature(const_ipv4)] #![feature(const_ipv6)] #![feature(const_likely)] From ee21064fde0b432e23991b36022b21ab9ca0703d Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Thu, 26 Sep 2024 09:30:17 -0700 Subject: [PATCH 2/3] library: Stabilize `const_ptr_write` Const-stabilizes: - `write` - `write_bytes` - `write_unaligned` In the following paths: - `core::ptr` - `core::ptr::NonNull` - pointer `<*mut T>` Const-stabilizes the internal `core::intrinsics`: - `write_bytes` - `write_via_move` --- alloc/src/lib.rs | 1 - alloc/tests/lib.rs | 1 - core/src/intrinsics.rs | 6 +++--- core/src/lib.rs | 1 - core/src/ptr/mod.rs | 5 +++-- core/src/ptr/mut_ptr.rs | 6 +++--- core/src/ptr/non_null.rs | 6 +++--- core/tests/lib.rs | 1 - 8 files changed, 12 insertions(+), 15 deletions(-) diff --git a/alloc/src/lib.rs b/alloc/src/lib.rs index c60c0743c7e12..1d7b7a034541e 100644 --- a/alloc/src/lib.rs +++ b/alloc/src/lib.rs @@ -173,7 +173,6 @@ #![feature(allow_internal_unstable)] #![feature(cfg_sanitize)] #![feature(const_precise_live_drops)] -#![feature(const_ptr_write)] #![feature(const_try)] #![feature(decl_macro)] #![feature(dropck_eyepatch)] diff --git a/alloc/tests/lib.rs b/alloc/tests/lib.rs index f43143c6cef65..4d146f1f5fd68 100644 --- a/alloc/tests/lib.rs +++ b/alloc/tests/lib.rs @@ -7,7 +7,6 @@ #![feature(const_cow_is_borrowed)] #![feature(const_heap)] #![cfg_attr(bootstrap, feature(const_mut_refs))] -#![feature(const_ptr_write)] #![feature(const_try)] #![feature(core_intrinsics)] #![feature(extract_if)] diff --git a/core/src/intrinsics.rs b/core/src/intrinsics.rs index 3be0765443253..f61b675ac4ed8 100644 --- a/core/src/intrinsics.rs +++ b/core/src/intrinsics.rs @@ -2635,7 +2635,7 @@ extern "rust-intrinsic" { /// This intrinsic can *only* be called where the pointer is a local without /// projections (`write_via_move(ptr, x)`, not `write_via_move(*ptr, x)`) so /// that it trivially obeys runtime-MIR rules about derefs in operands. - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[rustc_nounwind] pub fn write_via_move(ptr: *mut T, value: T); @@ -3472,13 +3472,13 @@ pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { #[doc(alias = "memset")] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_allowed_through_unstable_modules] -#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] +#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[rustc_diagnostic_item = "ptr_write_bytes"] pub const unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { extern "rust-intrinsic" { - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[rustc_nounwind] fn write_bytes(dst: *mut T, val: u8, count: usize); } diff --git a/core/src/lib.rs b/core/src/lib.rs index 3eacf7261a556..97df6ccfa5e02 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -137,7 +137,6 @@ #![feature(const_pointer_is_aligned)] #![feature(const_ptr_is_null)] #![feature(const_ptr_sub_ptr)] -#![feature(const_ptr_write)] #![feature(const_raw_ptr_comparison)] #![feature(const_replace)] #![feature(const_size_of_val)] diff --git a/core/src/ptr/mod.rs b/core/src/ptr/mod.rs index 67f1b0cd16de4..6f076caf533d3 100644 --- a/core/src/ptr/mod.rs +++ b/core/src/ptr/mod.rs @@ -1611,7 +1611,7 @@ pub const unsafe fn read_unaligned(src: *const T) -> T { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] +#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[rustc_diagnostic_item = "ptr_write"] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn write(dst: *mut T, src: T) { @@ -1719,7 +1719,8 @@ pub const unsafe fn write(dst: *mut T, src: T) { /// ``` #[inline] #[stable(feature = "ptr_unaligned", since = "1.17.0")] -#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] +#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_refs_to_cell))] +#[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[rustc_diagnostic_item = "ptr_write_unaligned"] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn write_unaligned(dst: *mut T, src: T) { diff --git a/core/src/ptr/mut_ptr.rs b/core/src/ptr/mut_ptr.rs index e458bb4642fc6..ced6cb7d520de 100644 --- a/core/src/ptr/mut_ptr.rs +++ b/core/src/ptr/mut_ptr.rs @@ -1449,7 +1449,7 @@ impl *mut T { /// /// [`ptr::write`]: crate::ptr::write() #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn write(self, val: T) @@ -1468,7 +1468,7 @@ impl *mut T { /// [`ptr::write_bytes`]: crate::ptr::write_bytes() #[doc(alias = "memset")] #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn write_bytes(self, val: u8, count: usize) @@ -1509,7 +1509,7 @@ impl *mut T { /// /// [`ptr::write_unaligned`]: crate::ptr::write_unaligned() #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn write_unaligned(self, val: T) diff --git a/core/src/ptr/non_null.rs b/core/src/ptr/non_null.rs index 6c5834a1ece88..dc1a7c6220ebe 100644 --- a/core/src/ptr/non_null.rs +++ b/core/src/ptr/non_null.rs @@ -1013,7 +1013,7 @@ impl NonNull { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[stable(feature = "non_null_convenience", since = "1.80.0")] - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] pub const unsafe fn write(self, val: T) where T: Sized, @@ -1032,7 +1032,7 @@ impl NonNull { #[doc(alias = "memset")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[stable(feature = "non_null_convenience", since = "1.80.0")] - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] pub const unsafe fn write_bytes(self, val: u8, count: usize) where T: Sized, @@ -1073,7 +1073,7 @@ impl NonNull { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[stable(feature = "non_null_convenience", since = "1.80.0")] - #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")] + #[rustc_const_stable(feature = "const_ptr_write", since = "CURRENT_RUSTC_VERSION")] pub const unsafe fn write_unaligned(self, val: T) where T: Sized, diff --git a/core/tests/lib.rs b/core/tests/lib.rs index 8ee98de2a7b28..5ec1b311a50c4 100644 --- a/core/tests/lib.rs +++ b/core/tests/lib.rs @@ -28,7 +28,6 @@ #![feature(const_option_ext)] #![feature(const_pin)] #![feature(const_pointer_is_aligned)] -#![feature(const_ptr_write)] #![feature(const_three_way_compare)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] From 3b820ee5e0155ebc9d3d70eb3523a26c1f4d947e Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Thu, 26 Sep 2024 11:49:53 -0700 Subject: [PATCH 3/3] library: Stabilize `const_replace` Depends on stabilizing `const_ptr_write`. Const-stabilizes: - `core::mem::replace` - `core::ptr::replace` --- core/src/lib.rs | 1 - core/src/mem/mod.rs | 3 ++- core/src/ptr/mod.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 97df6ccfa5e02..d407efa069b60 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -138,7 +138,6 @@ #![feature(const_ptr_is_null)] #![feature(const_ptr_sub_ptr)] #![feature(const_raw_ptr_comparison)] -#![feature(const_replace)] #![feature(const_size_of_val)] #![feature(const_size_of_val_raw)] #![feature(const_strict_overflow_ops)] diff --git a/core/src/mem/mod.rs b/core/src/mem/mod.rs index 414262fcf5ab1..9bf2aa594c047 100644 --- a/core/src/mem/mod.rs +++ b/core/src/mem/mod.rs @@ -857,7 +857,8 @@ pub fn take(dest: &mut T) -> T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "if you don't need the old value, you can just assign the new value directly"] -#[rustc_const_unstable(feature = "const_replace", issue = "83164")] +#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] +#[rustc_const_stable(feature = "const_replace", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(not(test), rustc_diagnostic_item = "mem_replace")] pub const fn replace(dest: &mut T, src: T) -> T { // It may be tempting to use `swap` to avoid `unsafe` here. Don't! diff --git a/core/src/ptr/mod.rs b/core/src/ptr/mod.rs index 6f076caf533d3..6b07449292417 100644 --- a/core/src/ptr/mod.rs +++ b/core/src/ptr/mod.rs @@ -1263,7 +1263,8 @@ const unsafe fn swap_nonoverlapping_simple_untyped(x: *mut T, y: *mut T, coun /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_replace", issue = "83164")] +#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] +#[rustc_const_stable(feature = "const_replace", since = "CURRENT_RUSTC_VERSION")] #[rustc_diagnostic_item = "ptr_replace"] pub const unsafe fn replace(dst: *mut T, src: T) -> T { // SAFETY: the caller must guarantee that `dst` is valid to be