Skip to content

Commit f0a16b8

Browse files
committed
Use rustfix in copy suggestion test
1 parent 879efa8 commit f0a16b8

5 files changed

+119
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// `Rc` is not ever `Copy`, we should not suggest adding `T: Copy` constraint
2+
fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
3+
(t, t) //~ use of moved value: `t`
4+
}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0382]: use of moved value: `t`
2+
--> $DIR/use_of_moved_value_clone_suggestions.rs:3:9
3+
|
4+
LL | fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
5+
| - move occurs because `t` has type `Rc<T>`, which does not implement the `Copy` trait
6+
LL | (t, t)
7+
| - ^ value used here after move
8+
| |
9+
| value moved here
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0382`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// run-rustfix
2+
#![allow(dead_code)]
3+
4+
fn duplicate_t<T: Copy>(t: T) -> (T, T) {
5+
//~^ HELP consider restricting type parameter `T`
6+
(t, t) //~ use of moved value: `t`
7+
}
8+
9+
fn duplicate_opt<T: Copy>(t: Option<T>) -> (Option<T>, Option<T>) {
10+
//~^ HELP consider restricting type parameter `T`
11+
(t, t) //~ use of moved value: `t`
12+
}
13+
14+
fn duplicate_tup1<T: Copy>(t: (T,)) -> ((T,), (T,)) {
15+
//~^ HELP consider restricting type parameter `T`
16+
(t, t) //~ use of moved value: `t`
17+
}
18+
19+
fn duplicate_tup2<A: Copy, B: Copy>(t: (A, B)) -> ((A, B), (A, B)) {
20+
//~^ HELP consider restricting type parameters
21+
(t, t) //~ use of moved value: `t`
22+
}
23+
24+
fn duplicate_custom<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) {
25+
//~^ HELP consider restricting type parameter `T`
26+
(t, t) //~ use of moved value: `t`
27+
}
28+
29+
struct S<T>(T);
30+
trait Trait {}
31+
impl<T: Trait + Clone> Clone for S<T> {
32+
fn clone(&self) -> Self {
33+
Self(self.0.clone())
34+
}
35+
}
36+
impl<T: Trait + Copy> Copy for S<T> {}
37+
38+
trait A {}
39+
trait B {}
40+
41+
// Test where bounds are added with different bound placements
42+
fn duplicate_custom_1<T: Trait + Copy>(t: S<T>) -> (S<T>, S<T>) where {
43+
//~^ HELP consider restricting type parameter `T`
44+
(t, t) //~ use of moved value: `t`
45+
}
46+
47+
fn duplicate_custom_2<T>(t: S<T>) -> (S<T>, S<T>)
48+
where
49+
T: A + Trait + Copy,
50+
//~^ HELP consider further restricting this bound
51+
{
52+
(t, t) //~ use of moved value: `t`
53+
}
54+
55+
fn duplicate_custom_3<T>(t: S<T>) -> (S<T>, S<T>)
56+
where
57+
T: A,
58+
T: B, T: Trait, T: Copy
59+
//~^ HELP consider further restricting type parameter `T`
60+
{
61+
(t, t) //~ use of moved value: `t`
62+
}
63+
64+
fn duplicate_custom_4<T: A>(t: S<T>) -> (S<T>, S<T>)
65+
where
66+
T: B + Trait + Copy,
67+
//~^ HELP consider further restricting this bound
68+
{
69+
(t, t) //~ use of moved value: `t`
70+
}
71+
72+
fn main() {}

src/test/ui/moves/use_of_moved_value_copy_suggestions.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
// run-rustfix
2+
#![allow(dead_code)]
3+
14
fn duplicate_t<T>(t: T) -> (T, T) {
5+
//~^ HELP consider restricting type parameter `T`
26
(t, t) //~ use of moved value: `t`
37
}
48

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

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

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

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

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

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

3847
fn duplicate_custom_2<T>(t: S<T>) -> (S<T>, S<T>)
3948
where
4049
T: A,
50+
//~^ HELP consider further restricting this bound
4151
{
4252
(t, t) //~ use of moved value: `t`
4353
}
@@ -46,20 +56,17 @@ fn duplicate_custom_3<T>(t: S<T>) -> (S<T>, S<T>)
4656
where
4757
T: A,
4858
T: B,
59+
//~^ HELP consider further restricting type parameter `T`
4960
{
5061
(t, t) //~ use of moved value: `t`
5162
}
5263

5364
fn duplicate_custom_4<T: A>(t: S<T>) -> (S<T>, S<T>)
5465
where
5566
T: B,
67+
//~^ HELP consider further restricting this bound
5668
{
5769
(t, t) //~ use of moved value: `t`
5870
}
5971

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

src/test/ui/moves/use_of_moved_value_copy_suggestions.stderr

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
error[E0382]: use of moved value: `t`
2-
--> $DIR/use_of_moved_value_copy_suggestions.rs:2:9
2+
--> $DIR/use_of_moved_value_copy_suggestions.rs:6:9
33
|
44
LL | fn duplicate_t<T>(t: T) -> (T, T) {
55
| - move occurs because `t` has type `T`, which does not implement the `Copy` trait
6+
LL |
67
LL | (t, t)
78
| - ^ value used here after move
89
| |
@@ -14,10 +15,11 @@ LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) {
1415
| ++++++
1516

1617
error[E0382]: use of moved value: `t`
17-
--> $DIR/use_of_moved_value_copy_suggestions.rs:6:9
18+
--> $DIR/use_of_moved_value_copy_suggestions.rs:11:9
1819
|
1920
LL | fn duplicate_opt<T>(t: Option<T>) -> (Option<T>, Option<T>) {
2021
| - move occurs because `t` has type `Option<T>`, which does not implement the `Copy` trait
22+
LL |
2123
LL | (t, t)
2224
| - ^ value used here after move
2325
| |
@@ -29,10 +31,11 @@ LL | fn duplicate_opt<T: Copy>(t: Option<T>) -> (Option<T>, Option<T>) {
2931
| ++++++
3032

3133
error[E0382]: use of moved value: `t`
32-
--> $DIR/use_of_moved_value_copy_suggestions.rs:10:9
34+
--> $DIR/use_of_moved_value_copy_suggestions.rs:16:9
3335
|
3436
LL | fn duplicate_tup1<T>(t: (T,)) -> ((T,), (T,)) {
3537
| - move occurs because `t` has type `(T,)`, which does not implement the `Copy` trait
38+
LL |
3639
LL | (t, t)
3740
| - ^ value used here after move
3841
| |
@@ -44,10 +47,11 @@ LL | fn duplicate_tup1<T: Copy>(t: (T,)) -> ((T,), (T,)) {
4447
| ++++++
4548

4649
error[E0382]: use of moved value: `t`
47-
--> $DIR/use_of_moved_value_copy_suggestions.rs:14:9
50+
--> $DIR/use_of_moved_value_copy_suggestions.rs:21:9
4851
|
4952
LL | fn duplicate_tup2<A, B>(t: (A, B)) -> ((A, B), (A, B)) {
5053
| - move occurs because `t` has type `(A, B)`, which does not implement the `Copy` trait
54+
LL |
5155
LL | (t, t)
5256
| - ^ value used here after move
5357
| |
@@ -59,10 +63,11 @@ LL | fn duplicate_tup2<A: Copy, B: Copy>(t: (A, B)) -> ((A, B), (A, B)) {
5963
| ++++++ ++++++
6064

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

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

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

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

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

139-
error[E0382]: use of moved value: `t`
140-
--> $DIR/use_of_moved_value_copy_suggestions.rs:62:9
141-
|
142-
LL | fn duplicate_rc<T>(t: std::rc::Rc<T>) -> (std::rc::Rc<T>, std::rc::Rc<T>) {
143-
| - move occurs because `t` has type `Rc<T>`, which does not implement the `Copy` trait
144-
LL | (t, t)
145-
| - ^ value used here after move
146-
| |
147-
| value moved here
148-
149-
error: aborting due to 10 previous errors
145+
error: aborting due to 9 previous errors
150146

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

0 commit comments

Comments
 (0)