@@ -9,7 +9,7 @@ use rustc_data_structures::unhash::UnhashMap;
9
9
use rustc_errors:: Applicability ;
10
10
use rustc_hir:: def:: Res ;
11
11
use rustc_hir:: {
12
- GenericArg , GenericBound , Generics , Item , ItemKind , Node , Path , PathSegment , PredicateOrigin , QPath ,
12
+ GenericArg , GenericBound , Generics , Item , ItemKind , MutTy , Node , Path , PathSegment , PredicateOrigin , QPath ,
13
13
TraitBoundModifier , TraitItem , TraitRef , Ty , TyKind , WherePredicate ,
14
14
} ;
15
15
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -37,12 +37,12 @@ declare_clippy_lint! {
37
37
#[ clippy:: version = "1.38.0" ]
38
38
pub TYPE_REPETITION_IN_BOUNDS ,
39
39
nursery,
40
- "types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`"
40
+ "types are repeated unnecessarily in trait bounds, use `+` instead of using `T: _, T: _`"
41
41
}
42
42
43
43
declare_clippy_lint ! {
44
44
/// ### What it does
45
- /// Checks for cases where generics are being used and multiple
45
+ /// Checks for cases where generics or trait objects are being used and multiple
46
46
/// syntax specifications for trait bounds are used simultaneously.
47
47
///
48
48
/// ### Why is this bad?
@@ -167,6 +167,45 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
167
167
}
168
168
}
169
169
}
170
+
171
+ fn check_ty ( & mut self , cx : & LateContext < ' tcx > , ty : & ' tcx Ty < ' tcx > ) {
172
+ let TyKind :: Ref (
173
+ ..,
174
+ MutTy {
175
+ ty : Ty {
176
+ kind : TyKind :: TraitObject (
177
+ bounds,
178
+ ..
179
+ ) ,
180
+ ..
181
+ } ,
182
+ ..
183
+ }
184
+ ) = ty. kind else { return ; } ;
185
+
186
+ if bounds. len ( ) < 2 {
187
+ return ;
188
+ }
189
+
190
+ let mut seen_def_ids = FxHashSet :: default ( ) ;
191
+
192
+ for bound in bounds. iter ( ) {
193
+ let Some ( def_id) = bound. trait_ref . trait_def_id ( ) else { continue ; } ;
194
+
195
+ let already_seen = !seen_def_ids. insert ( def_id) ;
196
+
197
+ if already_seen {
198
+ span_lint_and_help (
199
+ cx,
200
+ TRAIT_DUPLICATION_IN_BOUNDS ,
201
+ bound. span ,
202
+ "this trait bound is already specified in trait declaration" ,
203
+ None ,
204
+ "consider removing this trait bound" ,
205
+ ) ;
206
+ }
207
+ }
208
+ }
170
209
}
171
210
172
211
impl TraitBounds {
0 commit comments