Skip to content

Commit

Permalink
Use rustfix in copy suggestion test
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Mar 1, 2022
1 parent 879efa8 commit f0a16b8
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/test/ui/moves/use_of_moved_value_clone_suggestions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// `Rc` is not ever `Copy`, we should not suggest adding `T: Copy` constraint
fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
(t, t) //~ use of moved value: `t`
}

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/moves/use_of_moved_value_clone_suggestions.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_clone_suggestions.rs:3:9
|
LL | fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
| - move occurs because `t` has type `Rc<T>`, which does not implement the `Copy` trait
LL | (t, t)
| - ^ value used here after move
| |
| value moved here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.
72 changes: 72 additions & 0 deletions src/test/ui/moves/use_of_moved_value_copy_suggestions.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// run-rustfix
#![allow(dead_code)]

fn duplicate_t<T: Copy>(t: T) -> (T, T) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_opt<T: Copy>(t: Option<T>) -> (Option<T>, Option<T>) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_tup1<T: Copy>(t: (T,)) -> ((T,), (T,)) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_tup2<A: Copy, B: Copy>(t: (A, B)) -> ((A, B), (A, B)) {
//~^ HELP consider restricting type parameters
(t, t) //~ use of moved value: `t`
}

fn duplicate_custom<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

struct S<T>(T);
trait Trait {}
impl<T: Trait + Clone> Clone for S<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<T: Trait + Copy> Copy for S<T> {}

trait A {}
trait B {}

// Test where bounds are added with different bound placements
fn duplicate_custom_1<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) where {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_custom_2<T>(t: S<T>) -> (S<T>, S<T>)
where
T: A + Trait + Copy,
//~^ HELP consider further restricting this bound
{
(t, t) //~ use of moved value: `t`
}

fn duplicate_custom_3<T>(t: S<T>) -> (S<T>, S<T>)
where
T: A,
T: B, T: Trait, T: Copy
//~^ HELP consider further restricting type parameter `T`
{
(t, t) //~ use of moved value: `t`
}

fn duplicate_custom_4<T: A>(t: S<T>) -> (S<T>, S<T>)
where
T: B + Trait + Copy,
//~^ HELP consider further restricting this bound
{
(t, t) //~ use of moved value: `t`
}

fn main() {}
17 changes: 12 additions & 5 deletions src/test/ui/moves/use_of_moved_value_copy_suggestions.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
// run-rustfix
#![allow(dead_code)]

fn duplicate_t<T>(t: T) -> (T, T) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_opt<T>(t: Option<T>) -> (Option<T>, Option<T>) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_tup1<T>(t: (T,)) -> ((T,), (T,)) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_tup2<A, B>(t: (A, B)) -> ((A, B), (A, B)) {
//~^ HELP consider restricting type parameters
(t, t) //~ use of moved value: `t`
}

fn duplicate_custom<T>(t: S<T>) -> (S<T>, S<T>) {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

Expand All @@ -32,12 +40,14 @@ trait B {}

// Test where bounds are added with different bound placements
fn duplicate_custom_1<T>(t: S<T>) -> (S<T>, S<T>) where {
//~^ HELP consider restricting type parameter `T`
(t, t) //~ use of moved value: `t`
}

fn duplicate_custom_2<T>(t: S<T>) -> (S<T>, S<T>)
where
T: A,
//~^ HELP consider further restricting this bound
{
(t, t) //~ use of moved value: `t`
}
Expand All @@ -46,20 +56,17 @@ fn duplicate_custom_3<T>(t: S<T>) -> (S<T>, S<T>)
where
T: A,
T: B,
//~^ HELP consider further restricting type parameter `T`
{
(t, t) //~ use of moved value: `t`
}

fn duplicate_custom_4<T: A>(t: S<T>) -> (S<T>, S<T>)
where
T: B,
//~^ HELP consider further restricting this bound
{
(t, t) //~ use of moved value: `t`
}

// `Rc` is not ever `Copy`, we should not suggest adding `T: Copy` constraint
fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
(t, t) //~ use of moved value: `t`
}

fn main() {}
36 changes: 16 additions & 20 deletions src/test/ui/moves/use_of_moved_value_copy_suggestions.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:2:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:6:9
|
LL | fn duplicate_t<T>(t: T) -> (T, T) {
| - move occurs because `t` has type `T`, which does not implement the `Copy` trait
LL |
LL | (t, t)
| - ^ value used here after move
| |
Expand All @@ -14,10 +15,11 @@ LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) {
| ++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:6:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:11:9
|
LL | fn duplicate_opt<T>(t: Option<T>) -> (Option<T>, Option<T>) {
| - move occurs because `t` has type `Option<T>`, which does not implement the `Copy` trait
LL |
LL | (t, t)
| - ^ value used here after move
| |
Expand All @@ -29,10 +31,11 @@ LL | fn duplicate_opt<T: Copy>(t: Option<T>) -> (Option<T>, Option<T>) {
| ++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:10:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:16:9
|
LL | fn duplicate_tup1<T>(t: (T,)) -> ((T,), (T,)) {
| - move occurs because `t` has type `(T,)`, which does not implement the `Copy` trait
LL |
LL | (t, t)
| - ^ value used here after move
| |
Expand All @@ -44,10 +47,11 @@ LL | fn duplicate_tup1<T: Copy>(t: (T,)) -> ((T,), (T,)) {
| ++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:14:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:21:9
|
LL | fn duplicate_tup2<A, B>(t: (A, B)) -> ((A, B), (A, B)) {
| - move occurs because `t` has type `(A, B)`, which does not implement the `Copy` trait
LL |
LL | (t, t)
| - ^ value used here after move
| |
Expand All @@ -59,10 +63,11 @@ LL | fn duplicate_tup2<A: Copy, B: Copy>(t: (A, B)) -> ((A, B), (A, B)) {
| ++++++ ++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:18:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:26:9
|
LL | fn duplicate_custom<T>(t: S<T>) -> (S<T>, S<T>) {
| - move occurs because `t` has type `S<T>`, which does not implement the `Copy` trait
LL |
LL | (t, t)
| - ^ value used here after move
| |
Expand All @@ -74,10 +79,11 @@ LL | fn duplicate_custom<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) {
| ++++++++++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:35:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:44:9
|
LL | fn duplicate_custom_1<T>(t: S<T>) -> (S<T>, S<T>) where {
| - move occurs because `t` has type `S<T>`, which does not implement the `Copy` trait
LL |
LL | (t, t)
| - ^ value used here after move
| |
Expand All @@ -89,7 +95,7 @@ LL | fn duplicate_custom_1<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) where {
| ++++++++++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:42:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:52:9
|
LL | fn duplicate_custom_2<T>(t: S<T>) -> (S<T>, S<T>)
| - move occurs because `t` has type `S<T>`, which does not implement the `Copy` trait
Expand All @@ -105,7 +111,7 @@ LL | T: A + Trait + Copy,
| ++++++++++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:50:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:61:9
|
LL | fn duplicate_custom_3<T>(t: S<T>) -> (S<T>, S<T>)
| - move occurs because `t` has type `S<T>`, which does not implement the `Copy` trait
Expand All @@ -121,7 +127,7 @@ LL | T: B, T: Trait, T: Copy
| ~~~~~~~~~~~~~~~~~~~

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:57:9
--> $DIR/use_of_moved_value_copy_suggestions.rs:69:9
|
LL | fn duplicate_custom_4<T: A>(t: S<T>) -> (S<T>, S<T>)
| - move occurs because `t` has type `S<T>`, which does not implement the `Copy` trait
Expand All @@ -136,16 +142,6 @@ help: consider further restricting this bound
LL | T: B + Trait + Copy,
| ++++++++++++++

error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:62:9
|
LL | fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
| - move occurs because `t` has type `Rc<T>`, which does not implement the `Copy` trait
LL | (t, t)
| - ^ value used here after move
| |
| value moved here

error: aborting due to 10 previous errors
error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0382`.

0 comments on commit f0a16b8

Please sign in to comment.