diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/issues/issue-40402-ref-hints | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/issues/issue-40402-ref-hints')
4 files changed, 42 insertions, 0 deletions
diff --git a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.rs b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.rs new file mode 100644 index 000000000..254956ae3 --- /dev/null +++ b/src/test/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/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr new file mode 100644 index 000000000..0a5a6b80e --- /dev/null +++ b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-1.stderr @@ -0,0 +1,12 @@ +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: `&f.v[0]` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.rs b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.rs new file mode 100644 index 000000000..1fb6e31e9 --- /dev/null +++ b/src/test/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/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr new file mode 100644 index 000000000..b6049f967 --- /dev/null +++ b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr @@ -0,0 +1,14 @@ +error[E0507]: cannot move out of index of `Vec<(String, String)>` + --> $DIR/issue-40402-2.rs:5:18 + | +LL | let (a, b) = x[0]; + | - - ^^^^ help: consider borrowing here: `&x[0]` + | | | + | | ...and here + | data moved here + | + = note: move occurs because these variables have types that don't implement the `Copy` trait + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. |