]> git.lizzy.rs Git - rust.git/blob - tests/ui/trait_duplication_in_bounds_unfixable.rs
Fix `unnecessary_cast` suggestion when taking a reference
[rust.git] / tests / ui / trait_duplication_in_bounds_unfixable.rs
1 #![deny(clippy::trait_duplication_in_bounds)]
2
3 use std::collections::BTreeMap;
4 use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
5
6 fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
7 where
8     T: Clone,
9     T: Default,
10 {
11     unimplemented!();
12 }
13
14 fn good_bar<T: Clone + Default>(arg: T) {
15     unimplemented!();
16 }
17
18 fn good_foo<T>(arg: T)
19 where
20     T: Clone + Default,
21 {
22     unimplemented!();
23 }
24
25 fn good_foobar<T: Default>(arg: T)
26 where
27     T: Clone,
28 {
29     unimplemented!();
30 }
31
32 trait T: Default {
33     fn f()
34     where
35         Self: Default;
36 }
37
38 trait U: Default {
39     fn f()
40     where
41         Self: Clone;
42 }
43
44 trait ZZ: Default {
45     fn g();
46     fn h();
47     fn f()
48     where
49         Self: Default + Clone;
50 }
51
52 trait BadTrait: Default + Clone {
53     fn f()
54     where
55         Self: Default + Clone;
56     fn g()
57     where
58         Self: Default;
59     fn h()
60     where
61         Self: Copy;
62 }
63
64 #[derive(Default, Clone)]
65 struct Life;
66
67 impl T for Life {
68     // this should not warn
69     fn f() {}
70 }
71
72 impl U for Life {
73     // this should not warn
74     fn f() {}
75 }
76
77 // should not warn
78 trait Iter: Iterator {
79     fn into_group_btreemap<K, V>(self) -> BTreeMap<K, Vec<V>>
80     where
81         Self: Iterator<Item = (K, V)> + Sized,
82         K: Ord + Eq,
83     {
84         unimplemented!();
85     }
86 }
87
88 struct Foo;
89
90 trait FooIter: Iterator<Item = Foo> {
91     fn bar()
92     where
93         Self: Iterator<Item = Foo>,
94     {
95     }
96 }
97
98 // The below should not lint and exist to guard against false positives
99 fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {}
100
101 pub mod one {
102     #[derive(Clone, Debug)]
103     struct MultiProductIter<I>
104     where
105         I: Iterator + Clone,
106         I::Item: Clone,
107     {
108         _marker: I,
109     }
110
111     pub struct MultiProduct<I>(Vec<MultiProductIter<I>>)
112     where
113         I: Iterator + Clone,
114         I::Item: Clone;
115
116     pub fn multi_cartesian_product<H>(_: H) -> MultiProduct<<H::Item as IntoIterator>::IntoIter>
117     where
118         H: Iterator,
119         H::Item: IntoIterator,
120         <H::Item as IntoIterator>::IntoIter: Clone,
121         <H::Item as IntoIterator>::Item: Clone,
122     {
123         todo!()
124     }
125 }
126
127 pub mod two {
128     use std::iter::Peekable;
129
130     pub struct MergeBy<I, J, F>
131     where
132         I: Iterator,
133         J: Iterator<Item = I::Item>,
134     {
135         _i: Peekable<I>,
136         _j: Peekable<J>,
137         _f: F,
138     }
139
140     impl<I, J, F> Clone for MergeBy<I, J, F>
141     where
142         I: Iterator,
143         J: Iterator<Item = I::Item>,
144         std::iter::Peekable<I>: Clone,
145         std::iter::Peekable<J>: Clone,
146         F: Clone,
147     {
148         fn clone(&self) -> Self {
149             Self {
150                 _i: self._i.clone(),
151                 _j: self._j.clone(),
152                 _f: self._f.clone(),
153             }
154         }
155     }
156 }
157
158 pub trait Trait {}
159
160 pub fn f(_a: impl Trait, _b: impl Trait) {}
161
162 pub trait ImplTrait<T> {}
163
164 impl<A, B> ImplTrait<(A, B)> for Foo where Foo: ImplTrait<A> + ImplTrait<B> {}
165
166 fn main() {}