]> git.lizzy.rs Git - rust.git/blob - tests/ui/moves/use_of_moved_value_copy_suggestions.fixed
Move /src/test to /tests
[rust.git] / tests / ui / moves / use_of_moved_value_copy_suggestions.fixed
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: Copy + Trait>(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: Copy + Trait>(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 + Copy + Trait,
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 + Copy + Trait,
58     //~^ HELP consider further restricting this bound
59     T: B,
60 {
61     (t, t) //~ use of moved value: `t`
62 }
63
64 fn duplicate_custom_4<T: A + Copy + Trait>(t: S<T>) -> (S<T>, S<T>)
65 //~^ HELP consider further restricting this bound
66 where
67     T: B,
68 {
69     (t, t) //~ use of moved value: `t`
70 }
71
72 #[rustfmt::skip]
73 fn existing_colon<T: Copy>(t: T) {
74     //~^ HELP consider restricting type parameter `T`
75     [t, t]; //~ use of moved value: `t`
76 }
77
78 fn existing_colon_in_where<T>(t: T)
79 where
80     T:, T: Copy
81     //~^ HELP consider further restricting type parameter `T`
82 {
83     [t, t]; //~ use of moved value: `t`
84 }
85
86 fn main() {}