Skip to content

Commit 6de3a2e

Browse files
committed
stabilize const_swap
1 parent 68b9e4f commit 6de3a2e

File tree

13 files changed

+20
-26
lines changed

13 files changed

+20
-26
lines changed

library/core/src/intrinsics/mod.rs

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

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
#![feature(array_ptr_get)]
112112
#![feature(asm_experimental_arch)]
113113
#![feature(const_eval_select)]
114-
#![feature(const_typed_swap)]
115114
#![feature(core_intrinsics)]
116115
#![feature(coverage_attribute)]
117116
#![feature(internal_impls_macro)]

library/core/src/mem/mod.rs

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

library/core/src/ptr/mod.rs

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

library/core/src/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ impl<T: ?Sized> *mut T {
15941594
///
15951595
/// [`ptr::swap`]: crate::ptr::swap()
15961596
#[stable(feature = "pointer_methods", since = "1.26.0")]
1597-
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
1597+
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
15981598
#[inline(always)]
15991599
pub const unsafe fn swap(self, with: *mut T)
16001600
where

library/core/src/ptr/non_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ impl<T: ?Sized> NonNull<T> {
11461146
/// [`ptr::swap`]: crate::ptr::swap()
11471147
#[inline(always)]
11481148
#[stable(feature = "non_null_convenience", since = "1.80.0")]
1149-
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
1149+
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
11501150
pub const unsafe fn swap(self, with: NonNull<T>)
11511151
where
11521152
T: Sized,

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ impl<T> [T] {
913913
/// assert!(v == ["a", "b", "e", "d", "c"]);
914914
/// ```
915915
#[stable(feature = "rust1", since = "1.0.0")]
916-
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
916+
#[rustc_const_stable(feature = "const_swap", since = "CURRENT_RUSTC_VERSION")]
917917
#[inline]
918918
#[track_caller]
919919
pub const fn swap(&mut self, a: usize, b: usize) {

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(clone_to_uninit)]
1616
#![feature(const_black_box)]
1717
#![feature(const_eval_select)]
18-
#![feature(const_swap)]
1918
#![feature(const_swap_nonoverlapping)]
2019
#![feature(const_trait_impl)]
2120
#![feature(core_intrinsics)]

tests/ui/consts/issue-94371.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(const_swap)]
4-
53
#[repr(C)]
64
struct Demo(u64, bool, u64, u32, u64, u64, u64);
75

tests/ui/consts/qualif-indirect-mutation-fail.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ compile-flags: --crate-type=lib
22
#![feature(const_precise_live_drops)]
3-
#![feature(const_swap)]
43

54
// Mutable borrow of a field with drop impl.
65
pub const fn f() {

tests/ui/consts/qualif-indirect-mutation-fail.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
2-
--> $DIR/qualif-indirect-mutation-fail.rs:13:9
2+
--> $DIR/qualif-indirect-mutation-fail.rs:12:9
33
|
44
LL | let mut x = None;
55
| ^^^^^ 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))`
1919
note: inside `std::ptr::drop_in_place::<Option<String>> - shim(Some(Option<String>))`
2020
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
2121
note: inside `A1`
22-
--> $DIR/qualif-indirect-mutation-fail.rs:19:1
22+
--> $DIR/qualif-indirect-mutation-fail.rs:18:1
2323
|
2424
LL | };
2525
| ^
2626

2727
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
28-
--> $DIR/qualif-indirect-mutation-fail.rs:29:9
28+
--> $DIR/qualif-indirect-mutation-fail.rs:28:9
2929
|
3030
LL | let _z = x;
3131
| ^^ 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))`
4444
note: inside `std::ptr::drop_in_place::<Option<String>> - shim(Some(Option<String>))`
4545
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
4646
note: inside `A2`
47-
--> $DIR/qualif-indirect-mutation-fail.rs:30:1
47+
--> $DIR/qualif-indirect-mutation-fail.rs:29:1
4848
|
4949
LL | };
5050
| ^
5151

5252
error[E0493]: destructor of `(u32, Option<String>)` cannot be evaluated at compile-time
53-
--> $DIR/qualif-indirect-mutation-fail.rs:7:9
53+
--> $DIR/qualif-indirect-mutation-fail.rs:6:9
5454
|
5555
LL | let mut a: (u32, Option<String>) = (0, None);
5656
| ^^^^^ the destructor for this type cannot be evaluated in constant functions
@@ -59,7 +59,7 @@ LL | }
5959
| - value is dropped here
6060

6161
error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
62-
--> $DIR/qualif-indirect-mutation-fail.rs:34:9
62+
--> $DIR/qualif-indirect-mutation-fail.rs:33:9
6363
|
6464
LL | let x: Option<T> = None;
6565
| ^ the destructor for this type cannot be evaluated in constant functions
@@ -68,15 +68,15 @@ LL | }
6868
| - value is dropped here
6969

7070
error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
71-
--> $DIR/qualif-indirect-mutation-fail.rs:42:9
71+
--> $DIR/qualif-indirect-mutation-fail.rs:41:9
7272
|
7373
LL | let _y = x;
7474
| ^^ the destructor for this type cannot be evaluated in constant functions
7575
LL | }
7676
| - value is dropped here
7777

7878
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
79-
--> $DIR/qualif-indirect-mutation-fail.rs:50:9
79+
--> $DIR/qualif-indirect-mutation-fail.rs:49:9
8080
|
8181
LL | let mut y: Option<String> = None;
8282
| ^^^^^ the destructor for this type cannot be evaluated in constant functions
@@ -85,7 +85,7 @@ LL | }
8585
| - value is dropped here
8686

8787
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
88-
--> $DIR/qualif-indirect-mutation-fail.rs:47:9
88+
--> $DIR/qualif-indirect-mutation-fail.rs:46:9
8989
|
9090
LL | let mut x: Option<String> = None;
9191
| ^^^^^ the destructor for this type cannot be evaluated in constant functions
@@ -94,7 +94,7 @@ LL | }
9494
| - value is dropped here
9595

9696
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
97-
--> $DIR/qualif-indirect-mutation-fail.rs:60:9
97+
--> $DIR/qualif-indirect-mutation-fail.rs:59:9
9898
|
9999
LL | let y: Option<String> = None;
100100
| ^ the destructor for this type cannot be evaluated in constant functions
@@ -103,7 +103,7 @@ LL | }
103103
| - value is dropped here
104104

105105
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
106-
--> $DIR/qualif-indirect-mutation-fail.rs:57:9
106+
--> $DIR/qualif-indirect-mutation-fail.rs:56:9
107107
|
108108
LL | let x: Option<String> = None;
109109
| ^ the destructor for this type cannot be evaluated in constant functions

tests/ui/thread-local/thread-local-static.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ edition:2018
22

33
#![feature(thread_local)]
4-
#![feature(const_swap)]
54
#![allow(static_mut_refs)]
65

76
#[thread_local]

tests/ui/thread-local/thread-local-static.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
2-
--> $DIR/thread-local-static.rs:10:28
2+
--> $DIR/thread-local-static.rs:9:28
33
|
44
LL | std::mem::swap(x, &mut STATIC_VAR_2)
55
| ^^^^^^^^^^^^ use of mutable static
66
|
77
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
88

99
error[E0625]: thread-local statics cannot be accessed at compile-time
10-
--> $DIR/thread-local-static.rs:10:28
10+
--> $DIR/thread-local-static.rs:9:28
1111
|
1212
LL | std::mem::swap(x, &mut STATIC_VAR_2)
1313
| ^^^^^^^^^^^^

0 commit comments

Comments
 (0)