Skip to content

Commit

Permalink
Bless tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Mar 19, 2022
1 parent 9b7f17f commit 4c5de71
Show file tree
Hide file tree
Showing 19 changed files with 294 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/test/ui/moves/issue-46099-move-in-macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ LL | let b = Box::new(true);
| - move occurs because `b` has type `Box<bool>`, which does not implement the `Copy` trait
LL | test!({b});
| ^ value used here after move
|
help: consider cloning `b`
|
LL | test!({b.clone()});
| ++++++++

error: aborting due to previous error

Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/moves/move-fn-self-receiver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ note: this function takes ownership of the receiver `self`, which moves `val.0`
LL | fn into_iter(self) -> Self::IntoIter;
| ^^^^
= note: move occurs because `val.0` has type `Vec<bool>`, which does not implement the `Copy` trait
help: consider cloning `val.0`
|
LL | val.0.clone().into_iter().next();
| ++++++++

error[E0382]: use of moved value: `foo`
--> $DIR/move-fn-self-receiver.rs:34:5
Expand Down Expand Up @@ -96,6 +100,10 @@ note: this function takes ownership of the receiver `self`, which moves `rc_foo`
|
LL | fn use_rc_self(self: Rc<Self>) {}
| ^^^^
help: consider cloning `rc_foo`
|
LL | rc_foo.clone().use_rc_self();
| ++++++++

error[E0382]: use of moved value: `foo_add`
--> $DIR/move-fn-self-receiver.rs:59:5
Expand Down Expand Up @@ -127,6 +135,10 @@ help: consider iterating over a slice of the `Vec<bool>`'s content to avoid movi
|
LL | for _val in &implicit_into_iter {}
| +
help: consider cloning `implicit_into_iter`
|
LL | for _val in implicit_into_iter.clone() {}
| ++++++++

error[E0382]: use of moved value: `explicit_into_iter`
--> $DIR/move-fn-self-receiver.rs:67:5
Expand All @@ -137,6 +149,11 @@ LL | for _val in explicit_into_iter.into_iter() {}
| ----------- `explicit_into_iter` moved due to this method call
LL | explicit_into_iter;
| ^^^^^^^^^^^^^^^^^^ value used here after move
|
help: consider cloning `explicit_into_iter`
|
LL | for _val in explicit_into_iter.clone().into_iter() {}
| ++++++++

error[E0382]: use of moved value: `container`
--> $DIR/move-fn-self-receiver.rs:71:5
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/moves/move-guard-same-consts.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ LL | (1, 2) if take(x) => (),
| - value moved here
LL | (1, 2) if take(x) => (),
| ^ value used here after move
|
help: consider cloning `x`
|
LL | (1, 2) if take(x.clone()) => (),
| ++++++++

error: aborting due to previous error

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/moves/move-in-guard-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ LL | (1, _) if take(x) => (),
| - value moved here
LL | (_, 2) if take(x) => (),
| ^ value used here after move
|
help: consider cloning `x`
|
LL | (1, _) if take(x.clone()) => (),
| ++++++++

error: aborting due to previous error

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/moves/move-in-guard-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ LL | let x: Box<_> = Box::new(1);
...
LL | (_, 2) if take(x) => (),
| ^ value used here after move
|
help: consider cloning `x`
|
LL | (_, 2) if take(x.clone()) => (),
| ++++++++

error: aborting due to previous error

Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/moves/move-out-of-tuple-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ LL | let z = x.0;
| ^^^ value used here after move
|
= note: move occurs because `x.0` has type `Box<i32>`, which does not implement the `Copy` trait
help: consider cloning `x.0`
|
LL | let y = x.0.clone();
| ++++++++

error[E0382]: use of moved value: `x.0`
--> $DIR/move-out-of-tuple-field.rs:12:13
Expand All @@ -17,6 +21,10 @@ LL | let z = x.0;
| ^^^ value used here after move
|
= note: move occurs because `x.0` has type `Box<isize>`, which does not implement the `Copy` trait
help: consider cloning `x.0`
|
LL | let y = x.0.clone();
| ++++++++

error: aborting due to 2 previous errors

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/moves/moves-based-on-type-access-to-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ note: this function takes ownership of the receiver `self`, which moves `x`
|
LL | fn into_iter(self) -> Self::IntoIter;
| ^^^^
help: consider cloning `x`
|
LL | consume(x.clone().into_iter().next().unwrap());
| ++++++++

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ LL | println!("{}", x);
| ^ value borrowed here after move
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning `x`
|
LL | println!("{}", x.clone());
| ++++++++

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ LL | let _y = Foo { f:x };
LL |
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | let _y = Foo { f:x.clone() };
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-distribute-copy-over-paren.rs:21:11
Expand All @@ -21,6 +26,11 @@ LL | let _y = Foo { f:(((x))) };
LL |
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | let _y = Foo { f:(((x))).clone() };
| ++++++++

error: aborting due to 2 previous errors

Expand Down
53 changes: 53 additions & 0 deletions src/test/ui/moves/moves-based-on-type-exprs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ LL | let _y = Foo { f:x };
| - value moved here
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | let _y = Foo { f:x.clone() };
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:18:11
Expand All @@ -17,6 +22,11 @@ LL | let _y = (x, 3);
| - value moved here
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | let _y = (x.clone(), 3);
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:35:11
Expand All @@ -29,6 +39,11 @@ LL | x
...
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | x.clone()
| ++++++++

error[E0382]: borrow of moved value: `y`
--> $DIR/moves-based-on-type-exprs.rs:36:11
Expand All @@ -41,6 +56,11 @@ LL | y
...
LL | touch(&y);
| ^^ value borrowed here after move
|
help: consider cloning `y`
|
LL | y.clone()
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:46:11
Expand All @@ -53,6 +73,11 @@ LL | true => x,
...
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | true => x.clone(),
| ++++++++

error[E0382]: borrow of moved value: `y`
--> $DIR/moves-based-on-type-exprs.rs:47:11
Expand All @@ -65,6 +90,11 @@ LL | false => y
...
LL | touch(&y);
| ^^ value borrowed here after move
|
help: consider cloning `y`
|
LL | false => y.clone()
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:58:11
Expand All @@ -77,6 +107,11 @@ LL | _ if guard(x) => 10,
...
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | _ if guard(x.clone()) => 10,
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:65:11
Expand All @@ -87,6 +122,11 @@ LL | let _y = [x];
| - value moved here
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | let _y = [x.clone()];
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:71:11
Expand All @@ -97,6 +137,11 @@ LL | let _y = vec![x];
| - value moved here
LL | touch(&x);
| ^^ value borrowed here after move
|
help: consider cloning `x`
|
LL | let _y = vec![x.clone()];
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:77:11
Expand All @@ -113,6 +158,10 @@ note: this function takes ownership of the receiver `self`, which moves `x`
|
LL | fn into_iter(self) -> Self::IntoIter;
| ^^^^
help: consider cloning `x`
|
LL | let _y = x.clone().into_iter().next().unwrap();
| ++++++++

error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:83:11
Expand All @@ -129,6 +178,10 @@ note: this function takes ownership of the receiver `self`, which moves `x`
|
LL | fn into_iter(self) -> Self::IntoIter;
| ^^^^
help: consider cloning `x`
|
LL | let _y = [x.clone().into_iter().next().unwrap(); 1];
| ++++++++

error: aborting due to 11 previous errors

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/moves/moves-based-on-type-match-bindings.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ LL | touch(&x);
| ^^ value borrowed here after partial move
|
= note: partial move occurs because `x.f` has type `String`, which does not implement the `Copy` trait
help: consider cloning `x.f`
|
LL | Foo {f.clone()} => {}
| ++++++++

error: aborting due to previous error

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/moves/moves-based-on-type-tuple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ LL | Box::new((x, x))
| - ^ value used here after move
| |
| value moved here
|
help: consider cloning `x`
|
LL | Box::new((x.clone(), x))
| ++++++++

error: aborting due to previous error

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/moves/moves-sru-moved-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ LL | let _c = Foo {noncopyable: h, ..f};
| ^^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
|
= note: move occurs because `f.moved` has type `Box<isize>`, which does not implement the `Copy` trait
help: consider cloning `f.moved`
|
LL | let _b = Foo {noncopyable: g, ..f}.clone();
| ++++++++

error: aborting due to previous error

Expand Down
33 changes: 33 additions & 0 deletions src/test/ui/moves/use_of_moved_value_clone_suggestions.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// run-rustfix
#![allow(dead_code)]

// `Rc` is not ever `Copy`, we should not suggest adding `T: Copy` constraint.
// But should suggest adding `.clone()`.
fn move_rc<T>(t: std::rc::Rc<T>) {
[t.clone(), t]; //~ use of moved value: `t`
}

// Even though `T` could be `Copy` it's already `Clone`
// so don't suggest adding `T: Copy` constraint,
// instead suggest adding `.clone()`.
fn move_clone_already<T: Clone>(t: T) {
[t.clone(), t]; //~ use of moved value: `t`
}

// Same as `Rc`
fn move_clone_only<T: Clone>(t: (T, String)) {
[t.clone(), t]; //~ use of moved value: `t`
}

// loop
fn move_in_a_loop<T: Clone>(t: T) {
loop {
if true {
drop(t.clone()); //~ use of moved value: `t`
} else {
drop(t.clone());
}
}
}

fn main() {}
3 changes: 2 additions & 1 deletion src/test/ui/moves/use_of_moved_value_clone_suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ fn move_rc<T>(t: std::rc::Rc<T>) {
[t, t]; //~ use of moved value: `t`
}

// Even though `T` could be `Copy` it's already `Clone` so don't suggest adding `T: Copy` constraint,
// Even though `T` could be `Copy` it's already `Clone`
// so don't suggest adding `T: Copy` constraint,
// instead suggest adding `.clone()`.
fn move_clone_already<T: Clone>(t: T) {
[t, t]; //~ use of moved value: `t`
Expand Down
Loading

0 comments on commit 4c5de71

Please sign in to comment.