summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-40402-ref-hints
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/issues/issue-40402-ref-hints
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/issues/issue-40402-ref-hints')
-rw-r--r--tests/ui/issues/issue-40402-ref-hints/issue-40402-1.rs10
-rw-r--r--tests/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr14
-rw-r--r--tests/ui/issues/issue-40402-ref-hints/issue-40402-2.rs6
-rw-r--r--tests/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr18
4 files changed, 48 insertions, 0 deletions
diff --git a/tests/ui/issues/issue-40402-ref-hints/issue-40402-1.rs b/tests/ui/issues/issue-40402-ref-hints/issue-40402-1.rs
new file mode 100644
index 000000000..254956ae3
--- /dev/null
+++ b/tests/ui/issues/issue-40402-ref-hints/issue-40402-1.rs
@@ -0,0 +1,10 @@
+// Check that we do not suggest `ref f` here in the `main()` function.
+struct Foo {
+ pub v: Vec<String>,
+}
+
+fn main() {
+ let mut f = Foo { v: Vec::new() };
+ f.v.push("hello".to_string());
+ let e = f.v[0]; //~ ERROR cannot move out of index
+}
diff --git a/tests/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr b/tests/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr
new file mode 100644
index 000000000..e15eed656
--- /dev/null
+++ b/tests/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr
@@ -0,0 +1,14 @@
+error[E0507]: cannot move out of index of `Vec<String>`
+ --> $DIR/issue-40402-1.rs:9:13
+ |
+LL | let e = f.v[0];
+ | ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
+ |
+help: consider borrowing here
+ |
+LL | let e = &f.v[0];
+ | +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0507`.
diff --git a/tests/ui/issues/issue-40402-ref-hints/issue-40402-2.rs b/tests/ui/issues/issue-40402-ref-hints/issue-40402-2.rs
new file mode 100644
index 000000000..1fb6e31e9
--- /dev/null
+++ b/tests/ui/issues/issue-40402-ref-hints/issue-40402-2.rs
@@ -0,0 +1,6 @@
+// Check that we do suggest `(ref a, ref b)` here, since `a` and `b`
+// are nested within a pattern
+fn main() {
+ let x = vec![(String::new(), String::new())];
+ let (a, b) = x[0]; //~ ERROR cannot move out of index
+}
diff --git a/tests/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr b/tests/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr
new file mode 100644
index 000000000..1bc554efb
--- /dev/null
+++ b/tests/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr
@@ -0,0 +1,18 @@
+error[E0507]: cannot move out of index of `Vec<(String, String)>`
+ --> $DIR/issue-40402-2.rs:5:18
+ |
+LL | let (a, b) = x[0];
+ | - - ^^^^
+ | | |
+ | | ...and here
+ | data moved here
+ |
+ = note: move occurs because these variables have types that don't implement the `Copy` trait
+help: consider borrowing here
+ |
+LL | let (a, b) = &x[0];
+ | +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0507`.