diff options
| author | Kivooeo <Kivooeo123@gmail.com> | 2025-07-01 00:41:51 +0500 |
|---|---|---|
| committer | Kivooeo <Kivooeo123@gmail.com> | 2025-07-05 00:39:50 +0500 |
| commit | 9ad98f78d4485f6f7f9615c1961bb75b281bfceb (patch) | |
| tree | daadbde2637ad72e2b6a55e61b2870110c55c16e /tests/ui/closures | |
| parent | 5ca574e85b67cec0a6fc3fddfe398cbe676c9c69 (diff) | |
| download | rust-9ad98f78d4485f6f7f9615c1961bb75b281bfceb.tar.gz rust-9ad98f78d4485f6f7f9615c1961bb75b281bfceb.zip | |
moved tests
Diffstat (limited to 'tests/ui/closures')
| -rw-r--r-- | tests/ui/closures/closure-no-copy-mut-env.rs | 11 | ||||
| -rw-r--r-- | tests/ui/closures/closure-no-copy-mut-env.stderr | 17 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/ui/closures/closure-no-copy-mut-env.rs b/tests/ui/closures/closure-no-copy-mut-env.rs new file mode 100644 index 00000000000..f6530f9a410 --- /dev/null +++ b/tests/ui/closures/closure-no-copy-mut-env.rs @@ -0,0 +1,11 @@ +// Check that closures do not implement `Copy` if their environment is not `Copy`. + +fn main() { + let mut a = 5; + let hello = || { + a += 1; + }; + + let b = hello; + let c = hello; //~ ERROR use of moved value: `hello` [E0382] +} diff --git a/tests/ui/closures/closure-no-copy-mut-env.stderr b/tests/ui/closures/closure-no-copy-mut-env.stderr new file mode 100644 index 00000000000..60cb1352313 --- /dev/null +++ b/tests/ui/closures/closure-no-copy-mut-env.stderr @@ -0,0 +1,17 @@ +error[E0382]: use of moved value: `hello` + --> $DIR/not-copy-closure.rs:10:13 + | +LL | let b = hello; + | ----- value moved here +LL | let c = hello; + | ^^^^^ value used here after move + | +note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `a` out of its environment + --> $DIR/not-copy-closure.rs:6:9 + | +LL | a += 1; + | ^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. |
