diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-07-31 04:09:30 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-31 04:09:30 +0900 |
| commit | 5e2655d27fdd523285856f8bdacbccdc07b4fc6c (patch) | |
| tree | 62db98846c60bae62b971cc0e4c87185ebe1e12e /src/test | |
| parent | fb27c4cc70bc4b1f01847ca95933849152b4df80 (diff) | |
| parent | 17b2f92e44b65caa5e057c51560336311caf2fb4 (diff) | |
| download | rust-5e2655d27fdd523285856f8bdacbccdc07b4fc6c.tar.gz rust-5e2655d27fdd523285856f8bdacbccdc07b4fc6c.zip | |
Rollup merge of #87559 - estebank:consider-borrowing, r=oli-obk
Tweak borrowing suggestion in `for` loop
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/for-i-in-vec.fixed | 3 | ||||
| -rw-r--r-- | src/test/ui/suggestions/for-i-in-vec.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/suggestions/for-i-in-vec.stderr | 25 | ||||
| -rw-r--r-- | src/test/ui/suggestions/option-content-move.stderr | 20 |
4 files changed, 37 insertions, 14 deletions
diff --git a/src/test/ui/suggestions/for-i-in-vec.fixed b/src/test/ui/suggestions/for-i-in-vec.fixed index ec7358bd08a..223ddf0f0ad 100644 --- a/src/test/ui/suggestions/for-i-in-vec.fixed +++ b/src/test/ui/suggestions/for-i-in-vec.fixed @@ -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 + } } } diff --git a/src/test/ui/suggestions/for-i-in-vec.rs b/src/test/ui/suggestions/for-i-in-vec.rs index 304fe8cc81f..7942698cc8e 100644 --- a/src/test/ui/suggestions/for-i-in-vec.rs +++ b/src/test/ui/suggestions/for-i-in-vec.rs @@ -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 + } } } diff --git a/src/test/ui/suggestions/for-i-in-vec.stderr b/src/test/ui/suggestions/for-i-in-vec.stderr index 48f3f423ac6..011fdf34c28 100644 --- a/src/test/ui/suggestions/for-i-in-vec.stderr +++ b/src/test/ui/suggestions/for-i-in-vec.stderr @@ -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[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 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/suggestions/option-content-move.stderr b/src/test/ui/suggestions/option-content-move.stderr index c00a0f1700b..94766530091 100644 --- a/src/test/ui/suggestions/option-content-move.stderr +++ b/src/test/ui/suggestions/option-content-move.stderr @@ -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 |
