about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-09-23 23:40:30 +0200
committerGitHub <noreply@github.com>2025-09-23 23:40:30 +0200
commit6617536d147d4bb5b3a15aebad265bc847f68b3e (patch)
treeacc9cefb4cf1c59facd4af3d320d2f0bc493c802
parentbba509eb7ee9d20a7300b6d34bcfffbe84e9d31d (diff)
parent60f60127e79672953eb1ccd1ba48a518cd05224d (diff)
downloadrust-6617536d147d4bb5b3a15aebad265bc847f68b3e.tar.gz
rust-6617536d147d4bb5b3a15aebad265bc847f68b3e.zip
Rollup merge of #146907 - cyrgani:146537-test, r=nnethercote
add regression test for issue 146537

Adds a test based on the reduction in https://github.com/rust-lang/rust/issues/146537#issuecomment-3289438439.
This was already fixed in rust-lang/rust#142882 before the issue was even reported, but no test for it was added yet.
-rw-r--r--tests/ui/suggestions/non_copy_move_out_of_tuple.rs8
-rw-r--r--tests/ui/suggestions/non_copy_move_out_of_tuple.stderr26
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/suggestions/non_copy_move_out_of_tuple.rs b/tests/ui/suggestions/non_copy_move_out_of_tuple.rs
new file mode 100644
index 00000000000..baf15dba33a
--- /dev/null
+++ b/tests/ui/suggestions/non_copy_move_out_of_tuple.rs
@@ -0,0 +1,8 @@
+// Regression test for #146537.
+
+struct NonCopy;
+fn main() {
+    let tuple = &(NonCopy,);
+    let b: NonCopy;
+    (b,) = *tuple; //~ ERROR: cannot move out of `tuple.0` which is behind a shared reference [E0507]
+}
diff --git a/tests/ui/suggestions/non_copy_move_out_of_tuple.stderr b/tests/ui/suggestions/non_copy_move_out_of_tuple.stderr
new file mode 100644
index 00000000000..62f24324fcc
--- /dev/null
+++ b/tests/ui/suggestions/non_copy_move_out_of_tuple.stderr
@@ -0,0 +1,26 @@
+error[E0507]: cannot move out of `tuple.0` which is behind a shared reference
+  --> $DIR/non_copy_move_out_of_tuple.rs:7:12
+   |
+LL |     (b,) = *tuple;
+   |      -     ^^^^^^
+   |      |
+   |      data moved here
+   |      move occurs because the place has type `NonCopy`, which does not implement the `Copy` trait
+   |
+note: if `NonCopy` implemented `Clone`, you could clone the value
+  --> $DIR/non_copy_move_out_of_tuple.rs:3:1
+   |
+LL | struct NonCopy;
+   | ^^^^^^^^^^^^^^ consider implementing `Clone` for this type
+...
+LL |     (b,) = *tuple;
+   |      - you could clone this value
+help: consider removing the dereference here
+   |
+LL -     (b,) = *tuple;
+LL +     (b,) = tuple;
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0507`.