diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /tests/ui/moves | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/moves')
36 files changed, 251 insertions, 29 deletions
diff --git a/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.fixed b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.fixed new file mode 100644 index 000000000..e88ca6079 --- /dev/null +++ b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.fixed @@ -0,0 +1,30 @@ +// run-rustfix +#![allow(unused_variables, dead_code)] +use std::collections::BTreeMap; +use std::collections::HashSet; + +#[derive(Debug,Eq,PartialEq,Hash)] +#[derive(Clone)] +enum Day { + Mon, +} + +struct Class { + days: BTreeMap<u32, HashSet<Day>> +} + +impl Class { + fn do_stuff(&self) { + for (_, v) in &self.days { + let mut x: HashSet<Day> = v.clone(); //~ ERROR + let y: Vec<Day> = x.drain().collect(); + println!("{:?}", x); + } + } +} + +fn fail() { + let c = Class { days: BTreeMap::new() }; + c.do_stuff(); +} +fn main() {} diff --git a/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.rs b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.rs new file mode 100644 index 000000000..ba277c4a9 --- /dev/null +++ b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.rs @@ -0,0 +1,29 @@ +// run-rustfix +#![allow(unused_variables, dead_code)] +use std::collections::BTreeMap; +use std::collections::HashSet; + +#[derive(Debug,Eq,PartialEq,Hash)] +enum Day { + Mon, +} + +struct Class { + days: BTreeMap<u32, HashSet<Day>> +} + +impl Class { + fn do_stuff(&self) { + for (_, v) in &self.days { + let mut x: HashSet<Day> = v.clone(); //~ ERROR + let y: Vec<Day> = x.drain().collect(); + println!("{:?}", x); + } + } +} + +fn fail() { + let c = Class { days: BTreeMap::new() }; + c.do_stuff(); +} +fn main() {} diff --git a/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.stderr b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.stderr new file mode 100644 index 000000000..6a9d76f79 --- /dev/null +++ b/tests/ui/moves/assignment-of-clone-call-on-ref-due-to-missing-bound.stderr @@ -0,0 +1,25 @@ +error[E0308]: mismatched types + --> $DIR/assignment-of-clone-call-on-ref-due-to-missing-bound.rs:18:39 + | +LL | let mut x: HashSet<Day> = v.clone(); + | ------------ ^^^^^^^^^ expected `HashSet<Day>`, found `&HashSet<Day>` + | | + | expected due to this + | + = note: expected struct `HashSet<_>` + found reference `&HashSet<_>` +note: `HashSet<Day>` does not implement `Clone`, so `&HashSet<Day>` was cloned instead + --> $DIR/assignment-of-clone-call-on-ref-due-to-missing-bound.rs:18:39 + | +LL | let mut x: HashSet<Day> = v.clone(); + | ^ + = help: `Clone` is not implemented because the trait bound `Day: Clone` is not satisfied +help: consider annotating `Day` with `#[derive(Clone)]` + | +LL + #[derive(Clone)] +LL | enum Day { + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/moves/issue-34721.stderr b/tests/ui/moves/issue-34721.stderr index f2bf22227..94780a04c 100644 --- a/tests/ui/moves/issue-34721.stderr +++ b/tests/ui/moves/issue-34721.stderr @@ -23,6 +23,6 @@ help: consider further restricting this bound LL | pub fn baz<T: Foo + Copy>(x: T) -> T { | ++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/issue-46099-move-in-macro.stderr b/tests/ui/moves/issue-46099-move-in-macro.stderr index 94bc9e6f4..2865a4e2b 100644 --- a/tests/ui/moves/issue-46099-move-in-macro.stderr +++ b/tests/ui/moves/issue-46099-move-in-macro.stderr @@ -11,6 +11,6 @@ help: consider cloning the value if the performance cost is acceptable LL | test!({b.clone()}); | ++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/issue-75904-move-closure-loop.stderr b/tests/ui/moves/issue-75904-move-closure-loop.stderr index 5e427a1fc..6f04105a3 100644 --- a/tests/ui/moves/issue-75904-move-closure-loop.stderr +++ b/tests/ui/moves/issue-75904-move-closure-loop.stderr @@ -10,6 +10,6 @@ LL | &mut a; LL | a; | - use occurs due to use in closure -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/issue-99470-move-out-of-some.stderr b/tests/ui/moves/issue-99470-move-out-of-some.stderr index c5159471f..71ec5adfd 100644 --- a/tests/ui/moves/issue-99470-move-out-of-some.stderr +++ b/tests/ui/moves/issue-99470-move-out-of-some.stderr @@ -16,6 +16,6 @@ LL - &Some(_y) => (), LL + Some(_y) => (), | -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/moves/move-fn-self-receiver.stderr b/tests/ui/moves/move-fn-self-receiver.stderr index c91a8b5ef..462deacbe 100644 --- a/tests/ui/moves/move-fn-self-receiver.stderr +++ b/tests/ui/moves/move-fn-self-receiver.stderr @@ -55,6 +55,10 @@ note: `Foo::use_box_self` takes ownership of the receiver `self`, which moves `b | LL | fn use_box_self(self: Box<Self>) {} | ^^^^ +help: you could `clone` the value and consume it, if the `Box<Foo>: Clone` trait bound could be satisfied + | +LL | boxed_foo.clone().use_box_self(); + | ++++++++ error[E0382]: use of moved value: `pin_box_foo` --> $DIR/move-fn-self-receiver.rs:46:5 @@ -71,6 +75,10 @@ note: `Foo::use_pin_box_self` takes ownership of the receiver `self`, which move | LL | fn use_pin_box_self(self: Pin<Box<Self>>) {} | ^^^^ +help: you could `clone` the value and consume it, if the `Box<Foo>: Clone` trait bound could be satisfied + | +LL | pin_box_foo.clone().use_pin_box_self(); + | ++++++++ error[E0505]: cannot move out of `mut_foo` because it is borrowed --> $DIR/move-fn-self-receiver.rs:50:5 diff --git a/tests/ui/moves/move-guard-same-consts.stderr b/tests/ui/moves/move-guard-same-consts.stderr index 86e5f6524..37ddb831a 100644 --- a/tests/ui/moves/move-guard-same-consts.stderr +++ b/tests/ui/moves/move-guard-same-consts.stderr @@ -21,6 +21,6 @@ help: consider cloning the value if the performance cost is acceptable LL | (1, 2) if take(x.clone()) => (), | ++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/move-in-guard-1.stderr b/tests/ui/moves/move-in-guard-1.stderr index f04cb34d7..0b9082388 100644 --- a/tests/ui/moves/move-in-guard-1.stderr +++ b/tests/ui/moves/move-in-guard-1.stderr @@ -21,6 +21,6 @@ help: consider cloning the value if the performance cost is acceptable LL | (1, _) if take(x.clone()) => (), | ++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/move-in-guard-2.stderr b/tests/ui/moves/move-in-guard-2.stderr index 26047861f..6d1bd4f95 100644 --- a/tests/ui/moves/move-in-guard-2.stderr +++ b/tests/ui/moves/move-in-guard-2.stderr @@ -19,6 +19,6 @@ help: consider cloning the value if the performance cost is acceptable LL | (_, 2) if take(x.clone()) => (), | ++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/move-into-dead-array-1.stderr b/tests/ui/moves/move-into-dead-array-1.stderr index 6db0f0bcb..83779fb16 100644 --- a/tests/ui/moves/move-into-dead-array-1.stderr +++ b/tests/ui/moves/move-into-dead-array-1.stderr @@ -11,6 +11,6 @@ help: consider assigning a value LL | let mut a: [D; 4] = todo!(); | +++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0381`. diff --git a/tests/ui/moves/move-into-dead-array-2.stderr b/tests/ui/moves/move-into-dead-array-2.stderr index 19e476c04..689aecdfc 100644 --- a/tests/ui/moves/move-into-dead-array-2.stderr +++ b/tests/ui/moves/move-into-dead-array-2.stderr @@ -8,6 +8,6 @@ LL | drop(a); LL | a[i] = d(); | ^^^^ value used here after move -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/move-of-addr-of-mut.stderr b/tests/ui/moves/move-of-addr-of-mut.stderr index ddebaa012..706b52d34 100644 --- a/tests/ui/moves/move-of-addr-of-mut.stderr +++ b/tests/ui/moves/move-of-addr-of-mut.stderr @@ -12,6 +12,6 @@ help: consider assigning a value LL | let mut x: S = todo!(); | +++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0381`. diff --git a/tests/ui/moves/move-out-of-array-1.stderr b/tests/ui/moves/move-out-of-array-1.stderr index 0af083e5b..aa0251dbd 100644 --- a/tests/ui/moves/move-out-of-array-1.stderr +++ b/tests/ui/moves/move-out-of-array-1.stderr @@ -7,6 +7,6 @@ LL | a[i] | cannot move out of here | move occurs because `a[_]` has type `D`, which does not implement the `Copy` trait -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0508`. diff --git a/tests/ui/moves/move-out-of-field.rs b/tests/ui/moves/move-out-of-field.rs index 9f697db4f..4166d8dc8 100644 --- a/tests/ui/moves/move-out-of-field.rs +++ b/tests/ui/moves/move-out-of-field.rs @@ -1,7 +1,5 @@ // run-pass -use std::string::String; - struct StringBuffer { s: String, } diff --git a/tests/ui/moves/move-out-of-slice-1.stderr b/tests/ui/moves/move-out-of-slice-1.stderr index 5a0357cf5..865337144 100644 --- a/tests/ui/moves/move-out-of-slice-1.stderr +++ b/tests/ui/moves/move-out-of-slice-1.stderr @@ -14,6 +14,6 @@ help: consider borrowing the pattern binding LL | box [ref a] => {}, | +++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0508`. diff --git a/tests/ui/moves/moves-based-on-type-access-to-field.stderr b/tests/ui/moves/moves-based-on-type-access-to-field.stderr index 739018663..1e656e686 100644 --- a/tests/ui/moves/moves-based-on-type-access-to-field.stderr +++ b/tests/ui/moves/moves-based-on-type-access-to-field.stderr @@ -15,6 +15,6 @@ help: you can `clone` the value and consume it, but this might not be your desir LL | consume(x.clone().into_iter().next().unwrap()); | ++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/moves-based-on-type-block-bad.stderr b/tests/ui/moves/moves-based-on-type-block-bad.stderr index df09ababa..431ee1c0b 100644 --- a/tests/ui/moves/moves-based-on-type-block-bad.stderr +++ b/tests/ui/moves/moves-based-on-type-block-bad.stderr @@ -15,6 +15,6 @@ help: consider borrowing here LL | match &hellothere.x { | + -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/moves/moves-based-on-type-capture-clause-bad.stderr b/tests/ui/moves/moves-based-on-type-capture-clause-bad.stderr index 34b7ea658..5e527bf44 100644 --- a/tests/ui/moves/moves-based-on-type-capture-clause-bad.stderr +++ b/tests/ui/moves/moves-based-on-type-capture-clause-bad.stderr @@ -13,6 +13,6 @@ LL | println!("{}", x); | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr b/tests/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr index db4382b58..ec483cb3d 100644 --- a/tests/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr +++ b/tests/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr @@ -13,6 +13,6 @@ help: borrow this binding in the pattern to avoid moving the value LL | Some(ref right) => consume(right), | +++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/moves-based-on-type-match-bindings.stderr b/tests/ui/moves/moves-based-on-type-match-bindings.stderr index 225935532..b99b2bd9e 100644 --- a/tests/ui/moves/moves-based-on-type-match-bindings.stderr +++ b/tests/ui/moves/moves-based-on-type-match-bindings.stderr @@ -13,6 +13,6 @@ help: borrow this binding in the pattern to avoid moving the value LL | Foo {ref f} => {} | +++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr b/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr index 125e446c3..513631b20 100644 --- a/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr +++ b/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr @@ -8,6 +8,6 @@ LL | let _f = to_fn(|| test(i)); | | | captured by this `Fn` closure -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/moves/moves-based-on-type-tuple.stderr b/tests/ui/moves/moves-based-on-type-tuple.stderr index 0bcce3012..6383e4a82 100644 --- a/tests/ui/moves/moves-based-on-type-tuple.stderr +++ b/tests/ui/moves/moves-based-on-type-tuple.stderr @@ -14,6 +14,6 @@ help: consider cloning the value if the performance cost is acceptable LL | Box::new((x.clone(), x)) | ++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/moves-sru-moved-field.stderr b/tests/ui/moves/moves-sru-moved-field.stderr index cf7213637..f6a5c02ad 100644 --- a/tests/ui/moves/moves-sru-moved-field.stderr +++ b/tests/ui/moves/moves-sru-moved-field.stderr @@ -8,6 +8,6 @@ LL | let _c = Foo {noncopyable: h, ..f}; | = note: move occurs because `f.moved` has type `Box<isize>`, which does not implement the `Copy` trait -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/needs-clone-through-deref.fixed b/tests/ui/moves/needs-clone-through-deref.fixed new file mode 100644 index 000000000..419718175 --- /dev/null +++ b/tests/ui/moves/needs-clone-through-deref.fixed @@ -0,0 +1,18 @@ +// run-rustfix +#![allow(dead_code, noop_method_call)] +use std::ops::Deref; +struct S(Vec<usize>); +impl Deref for S { + type Target = Vec<usize>; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl S { + fn foo(&self) { + // `self.clone()` returns `&S`, not `Vec` + for _ in <Vec<usize> as Clone>::clone(&self.clone()).into_iter() {} //~ ERROR cannot move out of dereference of `S` + } +} +fn main() {} diff --git a/tests/ui/moves/needs-clone-through-deref.rs b/tests/ui/moves/needs-clone-through-deref.rs new file mode 100644 index 000000000..8116008ff --- /dev/null +++ b/tests/ui/moves/needs-clone-through-deref.rs @@ -0,0 +1,18 @@ +// run-rustfix +#![allow(dead_code, noop_method_call)] +use std::ops::Deref; +struct S(Vec<usize>); +impl Deref for S { + type Target = Vec<usize>; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl S { + fn foo(&self) { + // `self.clone()` returns `&S`, not `Vec` + for _ in self.clone().into_iter() {} //~ ERROR cannot move out of dereference of `S` + } +} +fn main() {} diff --git a/tests/ui/moves/needs-clone-through-deref.stderr b/tests/ui/moves/needs-clone-through-deref.stderr new file mode 100644 index 000000000..ff92f32e8 --- /dev/null +++ b/tests/ui/moves/needs-clone-through-deref.stderr @@ -0,0 +1,18 @@ +error[E0507]: cannot move out of dereference of `S` + --> $DIR/needs-clone-through-deref.rs:15:18 + | +LL | for _ in self.clone().into_iter() {} + | ^^^^^^^^^^^^ ----------- value moved due to this method call + | | + | move occurs because value has type `Vec<usize>`, which does not implement the `Copy` trait + | +note: `into_iter` takes ownership of the receiver `self`, which moves value + --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL +help: you can `clone` the value and consume it, but this might not be your desired behavior + | +LL | for _ in <Vec<usize> as Clone>::clone(&self.clone()).into_iter() {} + | ++++++++++++++++++++++++++++++ + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/moves/pin-mut-reborrow-infer-var-issue-107419.stderr b/tests/ui/moves/pin-mut-reborrow-infer-var-issue-107419.stderr index a184482a4..bb179e149 100644 --- a/tests/ui/moves/pin-mut-reborrow-infer-var-issue-107419.stderr +++ b/tests/ui/moves/pin-mut-reborrow-infer-var-issue-107419.stderr @@ -15,6 +15,6 @@ help: consider reborrowing the `Pin` instead of moving it LL | foo(r.as_mut().get_mut()); | +++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/pin-mut-reborrow.stderr b/tests/ui/moves/pin-mut-reborrow.stderr index 4bf207e7e..d3ccb0a65 100644 --- a/tests/ui/moves/pin-mut-reborrow.stderr +++ b/tests/ui/moves/pin-mut-reborrow.stderr @@ -18,6 +18,6 @@ help: consider reborrowing the `Pin` instead of moving it LL | foo.as_mut().foo(); | +++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.fixed b/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.fixed new file mode 100644 index 000000000..a4e219e1c --- /dev/null +++ b/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.fixed @@ -0,0 +1,28 @@ +// run-rustfix +// Issue #109429 +use std::collections::hash_map::DefaultHasher; +use std::collections::HashMap; +use std::hash::BuildHasher; +use std::hash::Hash; + +#[derive(Clone)] +pub struct Hash128_1; + +impl BuildHasher for Hash128_1 { + type Hasher = DefaultHasher; + fn build_hasher(&self) -> DefaultHasher { DefaultHasher::default() } +} + +#[allow(unused)] +pub fn hashmap_copy<T, U>( + map: &HashMap<T, U, Hash128_1>, +) where T: Hash + Clone, U: Clone +{ + let mut copy: Vec<U> = <HashMap<T, U, Hash128_1> as Clone>::clone(&map.clone()).into_values().collect(); //~ ERROR +} + +pub fn make_map() -> HashMap<String, i64, Hash128_1> +{ + HashMap::with_hasher(Hash128_1) +} +fn main() {} diff --git a/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.rs b/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.rs new file mode 100644 index 000000000..efe035eba --- /dev/null +++ b/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.rs @@ -0,0 +1,27 @@ +// run-rustfix +// Issue #109429 +use std::collections::hash_map::DefaultHasher; +use std::collections::HashMap; +use std::hash::BuildHasher; +use std::hash::Hash; + +pub struct Hash128_1; + +impl BuildHasher for Hash128_1 { + type Hasher = DefaultHasher; + fn build_hasher(&self) -> DefaultHasher { DefaultHasher::default() } +} + +#[allow(unused)] +pub fn hashmap_copy<T, U>( + map: &HashMap<T, U, Hash128_1>, +) where T: Hash + Clone, U: Clone +{ + let mut copy: Vec<U> = map.clone().into_values().collect(); //~ ERROR +} + +pub fn make_map() -> HashMap<String, i64, Hash128_1> +{ + HashMap::with_hasher(Hash128_1) +} +fn main() {} diff --git a/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.stderr b/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.stderr new file mode 100644 index 000000000..403daf8ff --- /dev/null +++ b/tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.stderr @@ -0,0 +1,23 @@ +error[E0507]: cannot move out of a shared reference + --> $DIR/suggest-clone-when-some-obligation-is-unmet.rs:20:28 + | +LL | let mut copy: Vec<U> = map.clone().into_values().collect(); + | ^^^^^^^^^^^ ------------- value moved due to this method call + | | + | move occurs because value has type `HashMap<T, U, Hash128_1>`, which does not implement the `Copy` trait + | +note: `HashMap::<K, V, S>::into_values` takes ownership of the receiver `self`, which moves value + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL +help: you could `clone` the value and consume it, if the `Hash128_1: Clone` trait bound could be satisfied + | +LL | let mut copy: Vec<U> = <HashMap<T, U, Hash128_1> as Clone>::clone(&map.clone()).into_values().collect(); + | ++++++++++++++++++++++++++++++++++++++++++++ + +help: consider annotating `Hash128_1` with `#[derive(Clone)]` + | +LL + #[derive(Clone)] +LL | pub struct Hash128_1; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/moves/suggest-clone.fixed b/tests/ui/moves/suggest-clone.fixed index 204bfdb10..0c4a94d77 100644 --- a/tests/ui/moves/suggest-clone.fixed +++ b/tests/ui/moves/suggest-clone.fixed @@ -7,5 +7,5 @@ impl Foo { } fn main() { let foo = &Foo; - foo.clone().foo(); //~ ERROR cannot move out + <Foo as Clone>::clone(&foo).foo(); //~ ERROR cannot move out } diff --git a/tests/ui/moves/suggest-clone.stderr b/tests/ui/moves/suggest-clone.stderr index 065acf904..25e89a589 100644 --- a/tests/ui/moves/suggest-clone.stderr +++ b/tests/ui/moves/suggest-clone.stderr @@ -13,9 +13,9 @@ LL | fn foo(self) {} | ^^^^ help: you can `clone` the value and consume it, but this might not be your desired behavior | -LL | foo.clone().foo(); - | ++++++++ +LL | <Foo as Clone>::clone(&foo).foo(); + | +++++++++++++++++++++++ + -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr b/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr index 0bb486a88..785329565 100644 --- a/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr +++ b/tests/ui/moves/use_of_moved_value_clone_suggestions.stderr @@ -13,6 +13,6 @@ help: clone the value to increment its reference count LL | (t.clone(), t) | ++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0382`. |