about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-30 23:46:42 +0000
committerbors <bors@rust-lang.org>2024-12-30 23:46:42 +0000
commit4e5fec2f1ea4b1cfecaa14304c9f56de59b344cb (patch)
tree1e4e8feb7ca476d0960112846baf5a49c8028b2a /tests
parent7f75bfa1ad4e9a9d33a179a90603001515e91991 (diff)
parent3c0c1386878812780349be38080470c0b4fcdda2 (diff)
downloadrust-4e5fec2f1ea4b1cfecaa14304c9f56de59b344cb.tar.gz
rust-4e5fec2f1ea4b1cfecaa14304c9f56de59b344cb.zip
Auto merge of #134757 - RalfJung:const_swap, r=scottmcm
stabilize const_swap

libs-api FCP passed in https://github.com/rust-lang/rust/issues/83163.

However, I only just realized that this actually involves an intrinsic. The intrinsic could be implemented entirely with existing stable const functionality, but we choose to make it a primitive to be able to detect more UB. So nominating for `@rust-lang/lang`  to make sure they are aware; I leave it up to them whether they want to FCP this.

While at it I also renamed the intrinsic to make the "nonoverlapping" constraint more clear.

Fixes #83163
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/intrinsics/typed_swap.rs12
-rw-r--r--tests/ui/consts/issue-94371.rs2
-rw-r--r--tests/ui/consts/qualif-indirect-mutation-fail.rs1
-rw-r--r--tests/ui/consts/qualif-indirect-mutation-fail.stderr22
-rw-r--r--tests/ui/thread-local/thread-local-static.rs1
-rw-r--r--tests/ui/thread-local/thread-local-static.stderr4
6 files changed, 19 insertions, 23 deletions
diff --git a/tests/codegen/intrinsics/typed_swap.rs b/tests/codegen/intrinsics/typed_swap.rs
index e73931d1d54..6b55078407a 100644
--- a/tests/codegen/intrinsics/typed_swap.rs
+++ b/tests/codegen/intrinsics/typed_swap.rs
@@ -8,14 +8,14 @@
 #![crate_type = "lib"]
 #![feature(core_intrinsics)]
 
-use std::intrinsics::typed_swap;
+use std::intrinsics::typed_swap_nonoverlapping;
 
 // CHECK-LABEL: @swap_unit(
 #[no_mangle]
 pub unsafe fn swap_unit(x: &mut (), y: &mut ()) {
     // CHECK: start
     // CHECK-NEXT: ret void
-    typed_swap(x, y)
+    typed_swap_nonoverlapping(x, y)
 }
 
 // CHECK-LABEL: @swap_i32(
@@ -32,7 +32,7 @@ pub unsafe fn swap_i32(x: &mut i32, y: &mut i32) {
     // OPT3: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 4, i1 false)
     // CHECK: store i32 %[[TEMP]], ptr %y, align 4
     // CHECK: ret void
-    typed_swap(x, y)
+    typed_swap_nonoverlapping(x, y)
 }
 
 // CHECK-LABEL: @swap_pair(
@@ -47,7 +47,7 @@ pub unsafe fn swap_pair(x: &mut (i32, u32), y: &mut (i32, u32)) {
     // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 8, i1 false)
     // CHECK: store i32
     // CHECK: store i32
-    typed_swap(x, y)
+    typed_swap_nonoverlapping(x, y)
 }
 
 // CHECK-LABEL: @swap_str(
@@ -63,7 +63,7 @@ pub unsafe fn swap_str<'a>(x: &mut &'a str, y: &mut &'a str) {
     // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %x, ptr align 8 %y, i64 16, i1 false)
     // CHECK: store ptr
     // CHECK: store i64
-    typed_swap(x, y)
+    typed_swap_nonoverlapping(x, y)
 }
 
 // OPT0-LABEL: @swap_string(
@@ -73,5 +73,5 @@ pub unsafe fn swap_string(x: &mut String, y: &mut String) {
     // OPT0: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[TEMP]], ptr align 8 %x, i64 24, i1 false)
     // OPT0: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %x, ptr align 8 %y, i64 24, i1 false)
     // OPT0: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %y, ptr align 8 %[[TEMP]], i64 24, i1 false)
-    typed_swap(x, y)
+    typed_swap_nonoverlapping(x, y)
 }
diff --git a/tests/ui/consts/issue-94371.rs b/tests/ui/consts/issue-94371.rs
index ad9ee9a5a3e..b2dd7053c1f 100644
--- a/tests/ui/consts/issue-94371.rs
+++ b/tests/ui/consts/issue-94371.rs
@@ -1,7 +1,5 @@
 //@ check-pass
 
-#![feature(const_swap)]
-
 #[repr(C)]
 struct Demo(u64, bool, u64, u32, u64, u64, u64);
 
diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.rs b/tests/ui/consts/qualif-indirect-mutation-fail.rs
index c6e08a557c8..0f59a86b7cc 100644
--- a/tests/ui/consts/qualif-indirect-mutation-fail.rs
+++ b/tests/ui/consts/qualif-indirect-mutation-fail.rs
@@ -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() {
diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.stderr b/tests/ui/consts/qualif-indirect-mutation-fail.stderr
index f706b7cf699..e76d7d3b670 100644
--- a/tests/ui/consts/qualif-indirect-mutation-fail.stderr
+++ b/tests/ui/consts/qualif-indirect-mutation-fail.stderr
@@ -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
diff --git a/tests/ui/thread-local/thread-local-static.rs b/tests/ui/thread-local/thread-local-static.rs
index af30f538366..422dac41002 100644
--- a/tests/ui/thread-local/thread-local-static.rs
+++ b/tests/ui/thread-local/thread-local-static.rs
@@ -1,7 +1,6 @@
 //@ edition:2018
 
 #![feature(thread_local)]
-#![feature(const_swap)]
 #![allow(static_mut_refs)]
 
 #[thread_local]
diff --git a/tests/ui/thread-local/thread-local-static.stderr b/tests/ui/thread-local/thread-local-static.stderr
index 3bc1aec00c1..bb078b79748 100644
--- a/tests/ui/thread-local/thread-local-static.stderr
+++ b/tests/ui/thread-local/thread-local-static.stderr
@@ -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)
    |                            ^^^^^^^^^^^^