1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#![deny(clippy::trait_duplication_in_bounds)]
#![allow(unused)]
#![feature(associated_const_equality, const_trait_impl)]
use std::any::Any;
fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
//~^ trait_duplication_in_bounds
unimplemented!();
}
fn bad_bar<T, U>(arg0: T, arg1: U)
where
T: Clone + Clone + Clone + Copy,
//~^ trait_duplication_in_bounds
U: Clone + Copy,
{
unimplemented!();
}
fn good_bar<T: Clone + Copy, U: Clone + Copy>(arg0: T, arg1: U) {
unimplemented!();
}
fn good_foo<T, U>(arg0: T, arg1: U)
where
T: Clone + Copy,
U: Clone + Copy,
{
unimplemented!();
}
trait GoodSelfTraitBound: Clone + Copy {
fn f();
}
trait GoodSelfWhereClause {
fn f()
where
Self: Clone + Copy;
}
trait BadSelfTraitBound: Clone + Clone + Clone {
//~^ trait_duplication_in_bounds
fn f();
}
trait BadSelfWhereClause {
fn f()
where
Self: Clone + Clone + Clone;
//~^ trait_duplication_in_bounds
}
trait GoodTraitBound<T: Clone + Copy, U: Clone + Copy> {
fn f();
}
trait GoodWhereClause<T, U> {
fn f()
where
T: Clone + Copy,
U: Clone + Copy;
}
trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> {
//~^ trait_duplication_in_bounds
fn f();
}
trait BadWhereClause<T, U> {
fn f()
where
T: Clone + Clone + Clone + Copy,
//~^ trait_duplication_in_bounds
U: Clone + Copy;
}
struct GoodStructBound<T: Clone + Copy, U: Clone + Copy> {
t: T,
u: U,
}
impl<T: Clone + Copy, U: Clone + Copy> GoodTraitBound<T, U> for GoodStructBound<T, U> {
// this should not warn
fn f() {}
}
struct GoodStructWhereClause;
impl<T, U> GoodTraitBound<T, U> for GoodStructWhereClause
where
T: Clone + Copy,
U: Clone + Copy,
{
// this should not warn
fn f() {}
}
fn no_error_separate_arg_bounds(program: impl AsRef<()>, dir: impl AsRef<()>, args: &[impl AsRef<()>]) {}
trait GenericTrait<T> {}
fn good_generic<T: GenericTrait<u64> + GenericTrait<u32>>(arg0: T) {
unimplemented!();
}
fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) {
//~^ trait_duplication_in_bounds
unimplemented!();
}
mod foo {
pub trait Clone {}
}
fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) {
//~^ trait_duplication_in_bounds
unimplemented!();
}
fn good_trait_object(arg0: &(dyn Any + Send)) {
unimplemented!();
}
fn bad_trait_object(arg0: &(dyn Any + Send + Send)) {
//~^ trait_duplication_in_bounds
unimplemented!();
}
trait Proj {
type S;
}
impl Proj for () {
type S = ();
}
impl Proj for i32 {
type S = i32;
}
trait Base<T> {
fn is_base(&self);
}
trait Derived<B: Proj>: Base<B::S> + Base<()> {
fn is_derived(&self);
}
fn f<P: Proj>(obj: &dyn Derived<P>) {
obj.is_derived();
Base::<P::S>::is_base(obj);
Base::<()>::is_base(obj);
}
// #13476
trait Value<const N: usize> {}
fn const_generic<T: Value<0> + Value<1>>() {}
// #11067 and #9626
fn assoc_tys_generics<'a, 'b, T, U>()
where
T: IntoIterator<Item = ()> + IntoIterator<Item = i32>,
U: From<&'a str> + From<&'b [u16]>,
{
}
// #13476
const trait ConstTrait {}
const fn const_trait_bounds_good<T: ConstTrait + [const] ConstTrait>() {}
const fn const_trait_bounds_bad<T: [const] ConstTrait + [const] ConstTrait>() {}
//~^ trait_duplication_in_bounds
fn projections<T, U, V>()
where
U: ToOwned,
V: ToOwned,
T: IntoIterator<Item = U::Owned> + IntoIterator<Item = U::Owned>,
//~^ trait_duplication_in_bounds
V: IntoIterator<Item = U::Owned> + IntoIterator<Item = V::Owned>,
{
}
fn main() {
let _x: fn(_) = f::<()>;
let _x: fn(_) = f::<i32>;
}
// #13706
fn assoc_tys_bounds<T>()
where
T: Iterator<Item: Clone> + Iterator<Item: Clone>,
{
}
trait AssocConstTrait {
const ASSOC: usize;
}
fn assoc_const_args<T>()
where
T: AssocConstTrait<ASSOC = 0> + AssocConstTrait<ASSOC = 0>,
//~^ trait_duplication_in_bounds
{
}
|