Rollup merge of #68424 - estebank:suggest-borrow-for-non-copy-vec, r=davidtwco
Suggest borrowing `Vec<NonCopy>` in for loop Partially address #64167.
This commit is contained in:
commit
eb769ed6b0
6 changed files with 69 additions and 4 deletions
15
src/test/ui/suggestions/for-i-in-vec.fixed
Normal file
15
src/test/ui/suggestions/for-i-in-vec.fixed
Normal file
|
|
@ -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() {}
|
||||
15
src/test/ui/suggestions/for-i-in-vec.rs
Normal file
15
src/test/ui/suggestions/for-i-in-vec.rs
Normal file
|
|
@ -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() {}
|
||||
12
src/test/ui/suggestions/for-i-in-vec.stderr
Normal file
12
src/test/ui/suggestions/for-i-in-vec.stderr
Normal file
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue