diff options
| author | Caio <c410.f3r@gmail.com> | 2024-04-21 15:43:43 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2024-04-21 15:43:43 -0300 |
| commit | 3aaa3941fd62fb4aeea559eafe8a6aa6472eb87d (patch) | |
| tree | 370d74ef8239f923cae41848afd9e71648850de3 /tests/ui/binding | |
| parent | fecb7b43093e4fa59e2d366e88bf0085ce350f29 (diff) | |
| download | rust-3aaa3941fd62fb4aeea559eafe8a6aa6472eb87d.tar.gz rust-3aaa3941fd62fb4aeea559eafe8a6aa6472eb87d.zip | |
Move some tests
Diffstat (limited to 'tests/ui/binding')
| -rw-r--r-- | tests/ui/binding/issue-40402-1.rs | 10 | ||||
| -rw-r--r-- | tests/ui/binding/issue-40402-1.stderr | 18 | ||||
| -rw-r--r-- | tests/ui/binding/issue-40402-2.rs | 6 | ||||
| -rw-r--r-- | tests/ui/binding/issue-40402-2.stderr | 18 |
4 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/binding/issue-40402-1.rs b/tests/ui/binding/issue-40402-1.rs new file mode 100644 index 00000000000..254956ae306 --- /dev/null +++ b/tests/ui/binding/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/binding/issue-40402-1.stderr b/tests/ui/binding/issue-40402-1.stderr new file mode 100644 index 00000000000..d27b6e6324f --- /dev/null +++ b/tests/ui/binding/issue-40402-1.stderr @@ -0,0 +1,18 @@ +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]; + | + +help: consider cloning the value if the performance cost is acceptable + | +LL | let e = f.v[0].clone(); + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/binding/issue-40402-2.rs b/tests/ui/binding/issue-40402-2.rs new file mode 100644 index 00000000000..1fb6e31e964 --- /dev/null +++ b/tests/ui/binding/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/binding/issue-40402-2.stderr b/tests/ui/binding/issue-40402-2.stderr new file mode 100644 index 00000000000..987558903ee --- /dev/null +++ b/tests/ui/binding/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 1 previous error + +For more information about this error, try `rustc --explain E0507`. |
