Tweak borrowing suggestion in for loop
This commit is contained in:
parent
eba3228b2a
commit
17b2f92e44
5 changed files with 76 additions and 44 deletions
|
|
@ -3,12 +3,15 @@
|
|||
|
||||
struct Foo {
|
||||
v: Vec<u32>,
|
||||
h: std::collections::HashMap<i32, i32>,
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn bar(&self) {
|
||||
for _ in &self.v { //~ ERROR cannot move out of `self.v` which is behind a shared reference
|
||||
}
|
||||
for _ in &self.h { //~ ERROR cannot move out of `self.h` which is behind a shared reference
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@
|
|||
|
||||
struct Foo {
|
||||
v: Vec<u32>,
|
||||
h: std::collections::HashMap<i32, i32>,
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn bar(&self) {
|
||||
for _ in self.v { //~ ERROR cannot move out of `self.v` which is behind a shared reference
|
||||
}
|
||||
for _ in self.h { //~ ERROR cannot move out of `self.h` which is behind a shared reference
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,25 @@
|
|||
error[E0507]: cannot move out of `self.v` which is behind a shared reference
|
||||
--> $DIR/for-i-in-vec.rs:10:18
|
||||
--> $DIR/for-i-in-vec.rs:11:18
|
||||
|
|
||||
LL | for _ in self.v {
|
||||
| ^^^^^^
|
||||
| |
|
||||
| move occurs because `self.v` has type `Vec<u32>`, which does not implement the `Copy` trait
|
||||
| help: consider iterating over a slice of the `Vec<_>`'s content: `&self.v`
|
||||
| ^^^^^^ move occurs because `self.v` has type `Vec<u32>`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: consider iterating over a slice of the `Vec<u32>`'s content
|
||||
|
|
||||
LL | for _ in &self.v {
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0507]: cannot move out of `self.h` which is behind a shared reference
|
||||
--> $DIR/for-i-in-vec.rs:13:18
|
||||
|
|
||||
LL | for _ in self.h {
|
||||
| ^^^^^^ move occurs because `self.h` has type `HashMap<i32, i32>`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: consider iterating over a slice of the `HashMap<i32, i32>`'s content
|
||||
|
|
||||
LL | for _ in &self.h {
|
||||
| ^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0507`.
|
||||
|
|
|
|||
|
|
@ -2,19 +2,23 @@ error[E0507]: cannot move out of `selection.1` which is behind a shared referenc
|
|||
--> $DIR/option-content-move.rs:11:20
|
||||
|
|
||||
LL | if selection.1.unwrap().contains(selection.0) {
|
||||
| ^^^^^^^^^^^
|
||||
| |
|
||||
| move occurs because `selection.1` has type `Option<String>`, which does not implement the `Copy` trait
|
||||
| help: consider borrowing the `Option`'s content: `selection.1.as_ref()`
|
||||
| ^^^^^^^^^^^ move occurs because `selection.1` has type `Option<String>`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: consider borrowing the `Option`'s content
|
||||
|
|
||||
LL | if selection.1.as_ref().unwrap().contains(selection.0) {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error[E0507]: cannot move out of `selection.1` which is behind a shared reference
|
||||
--> $DIR/option-content-move.rs:29:20
|
||||
|
|
||||
LL | if selection.1.unwrap().contains(selection.0) {
|
||||
| ^^^^^^^^^^^
|
||||
| |
|
||||
| move occurs because `selection.1` has type `Result<String, String>`, which does not implement the `Copy` trait
|
||||
| help: consider borrowing the `Result`'s content: `selection.1.as_ref()`
|
||||
| ^^^^^^^^^^^ move occurs because `selection.1` has type `Result<String, String>`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: consider borrowing the `Result`'s content
|
||||
|
|
||||
LL | if selection.1.as_ref().unwrap().contains(selection.0) {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue