diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2020-01-24 00:30:53 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-24 00:30:53 -0800 |
| commit | eb769ed6b09cb9fa007508caef808f5e50264cb0 (patch) | |
| tree | 19390f81a3749210c1c1f86154e697871405c764 /src/test/ui | |
| parent | 62f227b3f822a27bd603acede9137bfb49ca8b68 (diff) | |
| parent | 6eaf59dfc8be4ee5647f9c090c5a7668682f30c0 (diff) | |
Rollup merge of #68424 - estebank:suggest-borrow-for-non-copy-vec, r=davidtwco
Suggest borrowing `Vec<NonCopy>` in for loop Partially address #64167.
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/suggestions/for-i-in-vec.fixed | 15 | ||||
| -rw-r--r-- | src/test/ui/suggestions/for-i-in-vec.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/suggestions/for-i-in-vec.stderr | 12 |
3 files changed, 42 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/for-i-in-vec.fixed b/src/test/ui/suggestions/for-i-in-vec.fixed new file mode 100644 index 00000000000..ec7358bd08a --- /dev/null +++ b/src/test/ui/suggestions/for-i-in-vec.fixed @@ -0,0 +1,15 @@ +// run-rustfix +#![allow(dead_code)] + +struct Foo { + v: Vec<u32>, +} + +impl Foo { + fn bar(&self) { + for _ in &self.v { //~ ERROR cannot move out of `self.v` which is behind a shared reference + } + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/for-i-in-vec.rs b/src/test/ui/suggestions/for-i-in-vec.rs new file mode 100644 index 00000000000..304fe8cc81f --- /dev/null +++ b/src/test/ui/suggestions/for-i-in-vec.rs @@ -0,0 +1,15 @@ +// run-rustfix +#![allow(dead_code)] + +struct Foo { + v: Vec<u32>, +} + +impl Foo { + fn bar(&self) { + for _ in self.v { //~ ERROR cannot move out of `self.v` which is behind a shared reference + } + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/for-i-in-vec.stderr b/src/test/ui/suggestions/for-i-in-vec.stderr new file mode 100644 index 00000000000..576a7cc2f60 --- /dev/null +++ b/src/test/ui/suggestions/for-i-in-vec.stderr @@ -0,0 +1,12 @@ +error[E0507]: cannot move out of `self.v` which is behind a shared reference + --> $DIR/for-i-in-vec.rs:10:18 + | +LL | for _ in self.v { + | ^^^^^^ + | | + | move occurs because `self.v` has type `std::vec::Vec<u32>`, which does not implement the `Copy` trait + | help: consider iterating over a slice of the `Vec<_>`'s content: `&self.v` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. |
