From 5c8a00923bc435cec37820c32768871b9e8a9ca1 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sun, 7 May 2023 10:10:44 +0100 Subject: [PATCH] Comments --- clippy_lints/src/trait_bounds.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 5acd44dccaf..c4e4410e9fd 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -174,15 +174,11 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { if let TyKind::TraitObject(bounds, ..) = mut_ty.ty.kind; if bounds.len() > 2; then { - let mut bounds_span = bounds[0].span; - - for bound in bounds.iter().skip(1) { - bounds_span = bounds_span.to(bound.span); - } - let mut seen_def_ids = FxHashSet::default(); let mut fixed_traits = Vec::new(); + // Iterate the bounds and add them to our seen hash + // If we haven't yet seen it, add it to the fixed traits for bound in bounds.iter() { let Some(def_id) = bound.trait_ref.trait_def_id() else { continue; }; @@ -193,7 +189,15 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { } } + // If the number added to fixed (which are not duplicates) isn't the same as the number found, + // there must be 1 or more duplicates if bounds.len() != fixed_traits.len() { + let mut bounds_span = bounds[0].span; + + for bound in bounds.iter().skip(1) { + bounds_span = bounds_span.to(bound.span); + } + let fixed_trait_snippet = fixed_traits .iter() .filter_map(|b| snippet_opt(cx, b.span))