about summary refs log tree commit diff
path: root/tests/ui/closures
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-07-01 02:07:53 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-07-05 00:48:10 +0500
commit7f2e37fc5cdca01d4e140921f59fad398862606d (patch)
tree6355a44c3596dd25a7376e3bd8b850b4b15a9c22 /tests/ui/closures
parent5ca574e85b67cec0a6fc3fddfe398cbe676c9c69 (diff)
downloadrust-7f2e37fc5cdca01d4e140921f59fad398862606d.tar.gz
rust-7f2e37fc5cdca01d4e140921f59fad398862606d.zip
moved & deleted tests
opeq.rs was removed as duplicating test logic in other tests
Diffstat (limited to 'tests/ui/closures')
-rw-r--r--tests/ui/closures/fnonce-call-twice-error.rs17
-rw-r--r--tests/ui/closures/fnonce-call-twice-error.stderr21
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/closures/fnonce-call-twice-error.rs b/tests/ui/closures/fnonce-call-twice-error.rs
new file mode 100644
index 00000000000..3fd8c5cadca
--- /dev/null
+++ b/tests/ui/closures/fnonce-call-twice-error.rs
@@ -0,0 +1,17 @@
+// Testing guarantees provided by once functions.
+// This program would segfault if it were legal.
+
+use std::sync::Arc;
+
+fn foo<F:FnOnce()>(blk: F) {
+    blk();
+    blk(); //~ ERROR use of moved value
+}
+
+fn main() {
+    let x = Arc::new(true);
+    foo(move|| {
+        assert!(*x);
+        drop(x);
+    });
+}
diff --git a/tests/ui/closures/fnonce-call-twice-error.stderr b/tests/ui/closures/fnonce-call-twice-error.stderr
new file mode 100644
index 00000000000..42697374115
--- /dev/null
+++ b/tests/ui/closures/fnonce-call-twice-error.stderr
@@ -0,0 +1,21 @@
+error[E0382]: use of moved value: `blk`
+  --> $DIR/once-cant-call-twice-on-heap.rs:8:5
+   |
+LL | fn foo<F:FnOnce()>(blk: F) {
+   |                    --- move occurs because `blk` has type `F`, which does not implement the `Copy` trait
+LL |     blk();
+   |     ----- `blk` moved due to this call
+LL |     blk();
+   |     ^^^ value used here after move
+   |
+note: `FnOnce` closures can only be called once
+  --> $DIR/once-cant-call-twice-on-heap.rs:6:10
+   |
+LL | fn foo<F:FnOnce()>(blk: F) {
+   |          ^^^^^^^^ `F` is made to be an `FnOnce` closure here
+LL |     blk();
+   |     ----- this value implements `FnOnce`, which causes it to be moved when called
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0382`.