|
| 1 | +// run-rustfix |
1 | 2 | #![deny(clippy::trait_duplication_in_bounds)]
|
2 | 3 | #![allow(unused)]
|
3 | 4 |
|
4 |
| -use std::collections::BTreeMap; |
5 |
| -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; |
| 5 | +fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) { |
| 6 | + unimplemented!(); |
| 7 | +} |
6 | 8 |
|
7 |
| -fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z) |
| 9 | +fn bad_bar<T, U>(arg0: T, arg1: U) |
8 | 10 | where
|
9 |
| - T: Clone, |
10 |
| - T: Default, |
| 11 | + T: Clone + Clone + Clone + Copy, |
| 12 | + U: Clone + Copy, |
11 | 13 | {
|
12 | 14 | unimplemented!();
|
13 | 15 | }
|
14 | 16 |
|
15 |
| -fn good_bar<T: Clone + Default>(arg: T) { |
| 17 | +fn good_bar<T: Clone + Copy, U: Clone + Copy>(arg0: T, arg1: U) { |
16 | 18 | unimplemented!();
|
17 | 19 | }
|
18 | 20 |
|
19 |
| -fn good_foo<T>(arg: T) |
| 21 | +fn good_foo<T, U>(arg0: T, arg1: U) |
20 | 22 | where
|
21 |
| - T: Clone + Default, |
| 23 | + T: Clone + Copy, |
| 24 | + U: Clone + Copy, |
22 | 25 | {
|
23 | 26 | unimplemented!();
|
24 | 27 | }
|
25 | 28 |
|
26 |
| -fn good_foobar<T: Default>(arg: T) |
27 |
| -where |
28 |
| - T: Clone, |
29 |
| -{ |
30 |
| - unimplemented!(); |
| 29 | +trait GoodSelfTraitBound: Clone + Copy { |
| 30 | + fn f(); |
31 | 31 | }
|
32 | 32 |
|
33 |
| -trait T: Default { |
| 33 | +trait GoodSelfWhereClause { |
34 | 34 | fn f()
|
35 | 35 | where
|
36 |
| - Self: Default; |
| 36 | + Self: Clone + Copy; |
37 | 37 | }
|
38 | 38 |
|
39 |
| -trait U: Default { |
| 39 | +trait BadSelfTraitBound: Clone + Clone + Clone { |
| 40 | + fn f(); |
| 41 | +} |
| 42 | + |
| 43 | +trait BadSelfWhereClause { |
40 | 44 | fn f()
|
41 | 45 | where
|
42 |
| - Self: Clone; |
| 46 | + Self: Clone + Clone + Clone; |
| 47 | +} |
| 48 | + |
| 49 | +trait GoodTraitBound<T: Clone + Copy, U: Clone + Copy> { |
| 50 | + fn f(); |
43 | 51 | }
|
44 | 52 |
|
45 |
| -trait ZZ: Default { |
46 |
| - fn g(); |
47 |
| - fn h(); |
| 53 | +trait GoodWhereClause<T, U> { |
48 | 54 | fn f()
|
49 | 55 | where
|
50 |
| - Self: Default + Clone; |
| 56 | + T: Clone + Copy, |
| 57 | + U: Clone + Copy; |
51 | 58 | }
|
52 | 59 |
|
53 |
| -trait BadTrait: Default + Clone { |
| 60 | +trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> { |
| 61 | + fn f(); |
| 62 | +} |
| 63 | + |
| 64 | +trait BadWhereClause<T, U> { |
54 | 65 | fn f()
|
55 | 66 | where
|
56 |
| - Self: Default + Clone; |
57 |
| - fn g() |
58 |
| - where |
59 |
| - Self: Default; |
60 |
| - fn h() |
61 |
| - where |
62 |
| - Self: Copy; |
| 67 | + T: Clone + Clone + Clone + Copy, |
| 68 | + U: Clone + Copy; |
63 | 69 | }
|
64 | 70 |
|
65 |
| -#[derive(Default, Clone)] |
66 |
| -struct Life; |
| 71 | +struct GoodStructBound<T: Clone + Copy, U: Clone + Copy> { |
| 72 | + t: T, |
| 73 | + u: U, |
| 74 | +} |
67 | 75 |
|
68 |
| -impl T for Life { |
| 76 | +impl<T: Clone + Copy, U: Clone + Copy> GoodTraitBound<T, U> for GoodStructBound<T, U> { |
69 | 77 | // this should not warn
|
70 | 78 | fn f() {}
|
71 | 79 | }
|
72 | 80 |
|
73 |
| -impl U for Life { |
| 81 | +struct GoodStructWhereClause; |
| 82 | + |
| 83 | +impl<T, U> GoodTraitBound<T, U> for GoodStructWhereClause |
| 84 | +where |
| 85 | + T: Clone + Copy, |
| 86 | + U: Clone + Copy, |
| 87 | +{ |
74 | 88 | // this should not warn
|
75 | 89 | fn f() {}
|
76 | 90 | }
|
77 | 91 |
|
78 |
| -// should not warn |
79 |
| -trait Iter: Iterator { |
80 |
| - fn into_group_btreemap<K, V>(self) -> BTreeMap<K, Vec<V>> |
81 |
| - where |
82 |
| - Self: Iterator<Item = (K, V)> + Sized, |
83 |
| - K: Ord + Eq, |
84 |
| - { |
85 |
| - unimplemented!(); |
86 |
| - } |
87 |
| -} |
| 92 | +fn no_error_separate_arg_bounds(program: impl AsRef<()>, dir: impl AsRef<()>, args: &[impl AsRef<()>]) {} |
88 | 93 |
|
89 |
| -struct Foo; |
| 94 | +trait GenericTrait<T> {} |
90 | 95 |
|
91 |
| -trait FooIter: Iterator<Item = Foo> { |
92 |
| - fn bar() |
93 |
| - where |
94 |
| - Self: Iterator<Item = Foo>, |
95 |
| - { |
96 |
| - } |
| 96 | +fn good_generic<T: GenericTrait<u64> + GenericTrait<u32>>(arg0: T) { |
| 97 | + unimplemented!(); |
97 | 98 | }
|
98 | 99 |
|
99 |
| -// This should not lint |
100 |
| -fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {} |
101 |
| - |
102 |
| -mod repeated_where_clauses_or_trait_bounds { |
103 |
| - fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) { |
104 |
| - unimplemented!(); |
105 |
| - } |
106 |
| - |
107 |
| - fn bad_bar<T, U>(arg0: T, arg1: U) |
108 |
| - where |
109 |
| - T: Clone + Clone + Clone + Copy, |
110 |
| - U: Clone + Copy, |
111 |
| - { |
112 |
| - unimplemented!(); |
113 |
| - } |
114 |
| - |
115 |
| - fn good_bar<T: Clone + Copy, U: Clone + Copy>(arg0: T, arg1: U) { |
116 |
| - unimplemented!(); |
117 |
| - } |
118 |
| - |
119 |
| - fn good_foo<T, U>(arg0: T, arg1: U) |
120 |
| - where |
121 |
| - T: Clone + Copy, |
122 |
| - U: Clone + Copy, |
123 |
| - { |
124 |
| - unimplemented!(); |
125 |
| - } |
126 |
| - |
127 |
| - trait GoodSelfTraitBound: Clone + Copy { |
128 |
| - fn f(); |
129 |
| - } |
130 |
| - |
131 |
| - trait GoodSelfWhereClause { |
132 |
| - fn f() |
133 |
| - where |
134 |
| - Self: Clone + Copy; |
135 |
| - } |
136 |
| - |
137 |
| - trait BadSelfTraitBound: Clone + Clone + Clone { |
138 |
| - fn f(); |
139 |
| - } |
140 |
| - |
141 |
| - trait BadSelfWhereClause { |
142 |
| - fn f() |
143 |
| - where |
144 |
| - Self: Clone + Clone + Clone; |
145 |
| - } |
146 |
| - |
147 |
| - trait GoodTraitBound<T: Clone + Copy, U: Clone + Copy> { |
148 |
| - fn f(); |
149 |
| - } |
150 |
| - |
151 |
| - trait GoodWhereClause<T, U> { |
152 |
| - fn f() |
153 |
| - where |
154 |
| - T: Clone + Copy, |
155 |
| - U: Clone + Copy; |
156 |
| - } |
157 |
| - |
158 |
| - trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> { |
159 |
| - fn f(); |
160 |
| - } |
161 |
| - |
162 |
| - trait BadWhereClause<T, U> { |
163 |
| - fn f() |
164 |
| - where |
165 |
| - T: Clone + Clone + Clone + Copy, |
166 |
| - U: Clone + Copy; |
167 |
| - } |
168 |
| - |
169 |
| - struct GoodStructBound<T: Clone + Copy, U: Clone + Copy> { |
170 |
| - t: T, |
171 |
| - u: U, |
172 |
| - } |
173 |
| - |
174 |
| - impl<T: Clone + Copy, U: Clone + Copy> GoodTraitBound<T, U> for GoodStructBound<T, U> { |
175 |
| - // this should not warn |
176 |
| - fn f() {} |
177 |
| - } |
178 |
| - |
179 |
| - struct GoodStructWhereClause; |
180 |
| - |
181 |
| - impl<T, U> GoodTraitBound<T, U> for GoodStructWhereClause |
182 |
| - where |
183 |
| - T: Clone + Copy, |
184 |
| - U: Clone + Copy, |
185 |
| - { |
186 |
| - // this should not warn |
187 |
| - fn f() {} |
188 |
| - } |
189 |
| - |
190 |
| - fn no_error_separate_arg_bounds(program: impl AsRef<()>, dir: impl AsRef<()>, args: &[impl AsRef<()>]) {} |
191 |
| - |
192 |
| - trait GenericTrait<T> {} |
193 |
| - |
194 |
| - // This should not warn but currently does see #8757 |
195 |
| - fn good_generic<T: GenericTrait<u64> + GenericTrait<u32>>(arg0: T) { |
196 |
| - unimplemented!(); |
197 |
| - } |
198 |
| - |
199 |
| - fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) { |
200 |
| - unimplemented!(); |
201 |
| - } |
| 100 | +fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) { |
| 101 | + unimplemented!(); |
| 102 | +} |
202 | 103 |
|
203 |
| - mod foo { |
204 |
| - pub trait Clone {} |
205 |
| - } |
| 104 | +mod foo { |
| 105 | + pub trait Clone {} |
| 106 | +} |
206 | 107 |
|
207 |
| - fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) { |
208 |
| - unimplemented!(); |
209 |
| - } |
| 108 | +fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) { |
| 109 | + unimplemented!(); |
210 | 110 | }
|
211 | 111 |
|
212 | 112 | fn main() {}
|
0 commit comments