Skip to content

Commit 5c8a009

Browse files
committed
Comments
1 parent 122793b commit 5c8a009

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: clippy_lints/src/trait_bounds.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,11 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
174174
if let TyKind::TraitObject(bounds, ..) = mut_ty.ty.kind;
175175
if bounds.len() > 2;
176176
then {
177-
let mut bounds_span = bounds[0].span;
178-
179-
for bound in bounds.iter().skip(1) {
180-
bounds_span = bounds_span.to(bound.span);
181-
}
182-
183177
let mut seen_def_ids = FxHashSet::default();
184178
let mut fixed_traits = Vec::new();
185179

180+
// Iterate the bounds and add them to our seen hash
181+
// If we haven't yet seen it, add it to the fixed traits
186182
for bound in bounds.iter() {
187183
let Some(def_id) = bound.trait_ref.trait_def_id() else { continue; };
188184

@@ -193,7 +189,15 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
193189
}
194190
}
195191

192+
// If the number added to fixed (which are not duplicates) isn't the same as the number found,
193+
// there must be 1 or more duplicates
196194
if bounds.len() != fixed_traits.len() {
195+
let mut bounds_span = bounds[0].span;
196+
197+
for bound in bounds.iter().skip(1) {
198+
bounds_span = bounds_span.to(bound.span);
199+
}
200+
197201
let fixed_trait_snippet = fixed_traits
198202
.iter()
199203
.filter_map(|b| snippet_opt(cx, b.span))

0 commit comments

Comments
 (0)