From f0a16b856011c8e63fac98fd6c127c2a0bbd532e Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 1 Mar 2022 14:11:42 +0300 Subject: [PATCH] Use rustfix in copy suggestion test --- .../use_of_moved_value_clone_suggestions.rs | 6 ++ ...se_of_moved_value_clone_suggestions.stderr | 13 ++++ .../use_of_moved_value_copy_suggestions.fixed | 72 +++++++++++++++++++ .../use_of_moved_value_copy_suggestions.rs | 17 +++-- ...use_of_moved_value_copy_suggestions.stderr | 36 +++++----- 5 files changed, 119 insertions(+), 25 deletions(-) create mode 100644 src/test/ui/moves/use_of_moved_value_clone_suggestions.rs create mode 100644 src/test/ui/moves/use_of_moved_value_clone_suggestions.stderr create mode 100644 src/test/ui/moves/use_of_moved_value_copy_suggestions.fixed diff --git a/src/test/ui/moves/use_of_moved_value_clone_suggestions.rs b/src/test/ui/moves/use_of_moved_value_clone_suggestions.rs new file mode 100644 index 0000000000000..d5c8d4e6bdf2b --- /dev/null +++ b/src/test/ui/moves/use_of_moved_value_clone_suggestions.rs @@ -0,0 +1,6 @@ +// `Rc` is not ever `Copy`, we should not suggest adding `T: Copy` constraint +fn duplicate_rc(t: std::rc::Rc) -> (std::rc::Rc, std::rc::Rc) { + (t, t) //~ use of moved value: `t` +} + +fn main() {} diff --git a/src/test/ui/moves/use_of_moved_value_clone_suggestions.stderr b/src/test/ui/moves/use_of_moved_value_clone_suggestions.stderr new file mode 100644 index 0000000000000..c25981e6f8063 --- /dev/null +++ b/src/test/ui/moves/use_of_moved_value_clone_suggestions.stderr @@ -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: std::rc::Rc) -> (std::rc::Rc, std::rc::Rc) { + | - move occurs because `t` has type `Rc`, 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`. diff --git a/src/test/ui/moves/use_of_moved_value_copy_suggestions.fixed b/src/test/ui/moves/use_of_moved_value_copy_suggestions.fixed new file mode 100644 index 0000000000000..d31046c77006e --- /dev/null +++ b/src/test/ui/moves/use_of_moved_value_copy_suggestions.fixed @@ -0,0 +1,72 @@ +// run-rustfix +#![allow(dead_code)] + +fn duplicate_t(t: T) -> (T, T) { + //~^ HELP consider restricting type parameter `T` + (t, t) //~ use of moved value: `t` +} + +fn duplicate_opt(t: Option) -> (Option, Option) { + //~^ HELP consider restricting type parameter `T` + (t, t) //~ use of moved value: `t` +} + +fn duplicate_tup1(t: (T,)) -> ((T,), (T,)) { + //~^ HELP consider restricting type parameter `T` + (t, t) //~ use of moved value: `t` +} + +fn duplicate_tup2(t: (A, B)) -> ((A, B), (A, B)) { + //~^ HELP consider restricting type parameters + (t, t) //~ use of moved value: `t` +} + +fn duplicate_custom(t: S) -> (S, S) { + //~^ HELP consider restricting type parameter `T` + (t, t) //~ use of moved value: `t` +} + +struct S(T); +trait Trait {} +impl Clone for S { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} +impl Copy for S {} + +trait A {} +trait B {} + +// Test where bounds are added with different bound placements +fn duplicate_custom_1(t: S) -> (S, S) where { + //~^ HELP consider restricting type parameter `T` + (t, t) //~ use of moved value: `t` +} + +fn duplicate_custom_2(t: S) -> (S, S) +where + T: A + Trait + Copy, + //~^ HELP consider further restricting this bound +{ + (t, t) //~ use of moved value: `t` +} + +fn duplicate_custom_3(t: S) -> (S, S) +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: S) -> (S, S) +where + T: B + Trait + Copy, + //~^ HELP consider further restricting this bound +{ + (t, t) //~ use of moved value: `t` +} + +fn main() {} diff --git a/src/test/ui/moves/use_of_moved_value_copy_suggestions.rs b/src/test/ui/moves/use_of_moved_value_copy_suggestions.rs index 0930927c49d66..7cc5189fac017 100644 --- a/src/test/ui/moves/use_of_moved_value_copy_suggestions.rs +++ b/src/test/ui/moves/use_of_moved_value_copy_suggestions.rs @@ -1,20 +1,28 @@ +// run-rustfix +#![allow(dead_code)] + fn duplicate_t(t: T) -> (T, T) { + //~^ HELP consider restricting type parameter `T` (t, t) //~ use of moved value: `t` } fn duplicate_opt(t: Option) -> (Option, Option) { + //~^ HELP consider restricting type parameter `T` (t, t) //~ use of moved value: `t` } fn duplicate_tup1(t: (T,)) -> ((T,), (T,)) { + //~^ HELP consider restricting type parameter `T` (t, t) //~ use of moved value: `t` } fn duplicate_tup2(t: (A, B)) -> ((A, B), (A, B)) { + //~^ HELP consider restricting type parameters (t, t) //~ use of moved value: `t` } fn duplicate_custom(t: S) -> (S, S) { + //~^ HELP consider restricting type parameter `T` (t, t) //~ use of moved value: `t` } @@ -32,12 +40,14 @@ trait B {} // Test where bounds are added with different bound placements fn duplicate_custom_1(t: S) -> (S, S) where { + //~^ HELP consider restricting type parameter `T` (t, t) //~ use of moved value: `t` } fn duplicate_custom_2(t: S) -> (S, S) where T: A, + //~^ HELP consider further restricting this bound { (t, t) //~ use of moved value: `t` } @@ -46,6 +56,7 @@ fn duplicate_custom_3(t: S) -> (S, S) where T: A, T: B, + //~^ HELP consider further restricting type parameter `T` { (t, t) //~ use of moved value: `t` } @@ -53,13 +64,9 @@ where fn duplicate_custom_4(t: S) -> (S, S) 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: std::rc::Rc) -> (std::rc::Rc, std::rc::Rc) { - (t, t) //~ use of moved value: `t` -} - fn main() {} diff --git a/src/test/ui/moves/use_of_moved_value_copy_suggestions.stderr b/src/test/ui/moves/use_of_moved_value_copy_suggestions.stderr index c32ac2cd78aa0..8e72697ca30bb 100644 --- a/src/test/ui/moves/use_of_moved_value_copy_suggestions.stderr +++ b/src/test/ui/moves/use_of_moved_value_copy_suggestions.stderr @@ -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) { | - move occurs because `t` has type `T`, which does not implement the `Copy` trait +LL | LL | (t, t) | - ^ value used here after move | | @@ -14,10 +15,11 @@ LL | fn duplicate_t(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: Option) -> (Option, Option) { | - move occurs because `t` has type `Option`, which does not implement the `Copy` trait +LL | LL | (t, t) | - ^ value used here after move | | @@ -29,10 +31,11 @@ LL | fn duplicate_opt(t: Option) -> (Option, Option) { | ++++++ 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,)) { | - move occurs because `t` has type `(T,)`, which does not implement the `Copy` trait +LL | LL | (t, t) | - ^ value used here after move | | @@ -44,10 +47,11 @@ LL | fn duplicate_tup1(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(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 | | @@ -59,10 +63,11 @@ LL | fn duplicate_tup2(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: S) -> (S, S) { | - move occurs because `t` has type `S`, which does not implement the `Copy` trait +LL | LL | (t, t) | - ^ value used here after move | | @@ -74,10 +79,11 @@ LL | fn duplicate_custom(t: S) -> (S, S) { | ++++++++++++++ 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: S) -> (S, S) where { | - move occurs because `t` has type `S`, which does not implement the `Copy` trait +LL | LL | (t, t) | - ^ value used here after move | | @@ -89,7 +95,7 @@ LL | fn duplicate_custom_1(t: S) -> (S, S) 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: S) -> (S, S) | - move occurs because `t` has type `S`, which does not implement the `Copy` trait @@ -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: S) -> (S, S) | - move occurs because `t` has type `S`, which does not implement the `Copy` trait @@ -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: S) -> (S, S) | - move occurs because `t` has type `S`, which does not implement the `Copy` trait @@ -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: std::rc::Rc) -> (std::rc::Rc, std::rc::Rc) { - | - move occurs because `t` has type `Rc`, 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`.