]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs
Merge commit 'fdb84cbfd25908df5683f8f62388f663d9260e39' into clippyup
[rust.git] / src / tools / clippy / tests / ui / trait_duplication_in_bounds.rs
1 #![deny(clippy::trait_duplication_in_bounds)]
2 #![allow(unused)]
3
4 use std::collections::BTreeMap;
5 use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
6
7 fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
8 where
9     T: Clone,
10     T: Default,
11 {
12     unimplemented!();
13 }
14
15 fn good_bar<T: Clone + Default>(arg: T) {
16     unimplemented!();
17 }
18
19 fn good_foo<T>(arg: T)
20 where
21     T: Clone + Default,
22 {
23     unimplemented!();
24 }
25
26 fn good_foobar<T: Default>(arg: T)
27 where
28     T: Clone,
29 {
30     unimplemented!();
31 }
32
33 trait T: Default {
34     fn f()
35     where
36         Self: Default;
37 }
38
39 trait U: Default {
40     fn f()
41     where
42         Self: Clone;
43 }
44
45 trait ZZ: Default {
46     fn g();
47     fn h();
48     fn f()
49     where
50         Self: Default + Clone;
51 }
52
53 trait BadTrait: Default + Clone {
54     fn f()
55     where
56         Self: Default + Clone;
57     fn g()
58     where
59         Self: Default;
60     fn h()
61     where
62         Self: Copy;
63 }
64
65 #[derive(Default, Clone)]
66 struct Life;
67
68 impl T for Life {
69     // this should not warn
70     fn f() {}
71 }
72
73 impl U for Life {
74     // this should not warn
75     fn f() {}
76 }
77
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 }
88
89 struct Foo;
90
91 trait FooIter: Iterator<Item = Foo> {
92     fn bar()
93     where
94         Self: Iterator<Item = Foo>,
95     {
96     }
97 }
98
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     }
202
203     mod foo {
204         pub trait Clone {}
205     }
206
207     fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) {
208         unimplemented!();
209     }
210 }
211
212 fn main() {}