]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs
Auto merge of #97944 - nikic:freebsd-update, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / trait_duplication_in_bounds.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 // This should not lint
99 fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {}
100
101 fn main() {}