1
Fork 0

stabilize const_swap

This commit is contained in:
Ralf Jung 2024-12-25 10:36:32 +01:00
parent 68b9e4f5f5
commit 6de3a2e3a9
13 changed files with 20 additions and 26 deletions

View file

@ -3954,7 +3954,8 @@ pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
#[inline]
#[rustc_intrinsic]
// Const-unstable because `swap_nonoverlapping` is const-unstable.
#[rustc_const_unstable(feature = "const_typed_swap", issue = "none")]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_allow_const_fn_unstable(const_swap_nonoverlapping)] // this is anyway not called since CTFE implements the intrinsic
pub const unsafe fn typed_swap<T>(x: *mut T, y: *mut T) {
// SAFETY: The caller provided single non-overlapping items behind
// pointers, so swapping them with `count: 1` is fine.

View file

@ -111,7 +111,6 @@
#![feature(array_ptr_get)]
#![feature(asm_experimental_arch)]
#![feature(const_eval_select)]
#![feature(const_typed_swap)]
#![feature(core_intrinsics)]
#![feature(coverage_attribute)]
#![feature(internal_impls_macro)]

View file

@ -725,7 +725,7 @@ pub unsafe fn uninitialized<T>() -> T {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
#[rustc_diagnostic_item = "mem_swap"]
pub const fn swap<T>(x: &mut T, y: &mut T) {
// SAFETY: `&mut` guarantees these are typed readable and writable

View file

@ -1009,9 +1009,8 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
#[rustc_diagnostic_item = "ptr_swap"]
#[rustc_const_stable_indirect]
pub const unsafe fn swap<T>(x: *mut T, y: *mut T) {
// Give ourselves some scratch space to work with.
// We do not have to worry about drops: `MaybeUninit` does nothing when dropped.

View file

@ -1594,7 +1594,7 @@ impl<T: ?Sized> *mut T {
///
/// [`ptr::swap`]: crate::ptr::swap()
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
#[inline(always)]
pub const unsafe fn swap(self, with: *mut T)
where

View file

@ -1146,7 +1146,7 @@ impl<T: ?Sized> NonNull<T> {
/// [`ptr::swap`]: crate::ptr::swap()
#[inline(always)]
#[stable(feature = "non_null_convenience", since = "1.80.0")]
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
pub const unsafe fn swap(self, with: NonNull<T>)
where
T: Sized,

View file

@ -913,7 +913,7 @@ impl<T> [T] {
/// assert!(v == ["a", "b", "e", "d", "c"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
#[inline]
#[track_caller]
pub const fn swap(&mut self, a: usize, b: usize) {

View file

@ -15,7 +15,6 @@
#![feature(clone_to_uninit)]
#![feature(const_black_box)]
#![feature(const_eval_select)]
#![feature(const_swap)]
#![feature(const_swap_nonoverlapping)]
#![feature(const_trait_impl)]
#![feature(core_intrinsics)]

View file

@ -1,7 +1,5 @@
//@ check-pass
#![feature(const_swap)]
#[repr(C)]
struct Demo(u64, bool, u64, u32, u64, u64, u64);

View file

@ -1,6 +1,5 @@
//@ compile-flags: --crate-type=lib
#![feature(const_precise_live_drops)]
#![feature(const_swap)]
// Mutable borrow of a field with drop impl.
pub const fn f() {

View file

@ -1,5 +1,5 @@
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:13:9
--> $DIR/qualif-indirect-mutation-fail.rs:12:9
|
LL | let mut x = None;
| ^^^^^ the destructor for this type cannot be evaluated in constants
@ -19,13 +19,13 @@ note: inside `std::ptr::drop_in_place::<String> - shim(Some(String))`
note: inside `std::ptr::drop_in_place::<Option<String>> - shim(Some(Option<String>))`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
note: inside `A1`
--> $DIR/qualif-indirect-mutation-fail.rs:19:1
--> $DIR/qualif-indirect-mutation-fail.rs:18:1
|
LL | };
| ^
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:29:9
--> $DIR/qualif-indirect-mutation-fail.rs:28:9
|
LL | let _z = x;
| ^^ the destructor for this type cannot be evaluated in constants
@ -44,13 +44,13 @@ note: inside `std::ptr::drop_in_place::<String> - shim(Some(String))`
note: inside `std::ptr::drop_in_place::<Option<String>> - shim(Some(Option<String>))`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
note: inside `A2`
--> $DIR/qualif-indirect-mutation-fail.rs:30:1
--> $DIR/qualif-indirect-mutation-fail.rs:29:1
|
LL | };
| ^
error[E0493]: destructor of `(u32, Option<String>)` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:7:9
--> $DIR/qualif-indirect-mutation-fail.rs:6:9
|
LL | let mut a: (u32, Option<String>) = (0, None);
| ^^^^^ the destructor for this type cannot be evaluated in constant functions
@ -59,7 +59,7 @@ LL | }
| - value is dropped here
error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:34:9
--> $DIR/qualif-indirect-mutation-fail.rs:33:9
|
LL | let x: Option<T> = None;
| ^ the destructor for this type cannot be evaluated in constant functions
@ -68,7 +68,7 @@ LL | }
| - value is dropped here
error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:42:9
--> $DIR/qualif-indirect-mutation-fail.rs:41:9
|
LL | let _y = x;
| ^^ the destructor for this type cannot be evaluated in constant functions
@ -76,7 +76,7 @@ LL | }
| - value is dropped here
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:50:9
--> $DIR/qualif-indirect-mutation-fail.rs:49:9
|
LL | let mut y: Option<String> = None;
| ^^^^^ the destructor for this type cannot be evaluated in constant functions
@ -85,7 +85,7 @@ LL | }
| - value is dropped here
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:47:9
--> $DIR/qualif-indirect-mutation-fail.rs:46:9
|
LL | let mut x: Option<String> = None;
| ^^^^^ the destructor for this type cannot be evaluated in constant functions
@ -94,7 +94,7 @@ LL | }
| - value is dropped here
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:60:9
--> $DIR/qualif-indirect-mutation-fail.rs:59:9
|
LL | let y: Option<String> = None;
| ^ the destructor for this type cannot be evaluated in constant functions
@ -103,7 +103,7 @@ LL | }
| - value is dropped here
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:57:9
--> $DIR/qualif-indirect-mutation-fail.rs:56:9
|
LL | let x: Option<String> = None;
| ^ the destructor for this type cannot be evaluated in constant functions

View file

@ -1,7 +1,6 @@
//@ edition:2018
#![feature(thread_local)]
#![feature(const_swap)]
#![allow(static_mut_refs)]
#[thread_local]

View file

@ -1,5 +1,5 @@
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
--> $DIR/thread-local-static.rs:10:28
--> $DIR/thread-local-static.rs:9:28
|
LL | std::mem::swap(x, &mut STATIC_VAR_2)
| ^^^^^^^^^^^^ use of mutable static
@ -7,7 +7,7 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2)
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
error[E0625]: thread-local statics cannot be accessed at compile-time
--> $DIR/thread-local-static.rs:10:28
--> $DIR/thread-local-static.rs:9:28
|
LL | std::mem::swap(x, &mut STATIC_VAR_2)
| ^^^^^^^^^^^^