@@ -174,8 +174,13 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
174174 if let TyKind :: TraitObject ( bounds, ..) = mut_ty. ty. kind;
175175 if bounds. len( ) > 2 ;
176176 then {
177+
178+ // Build up a hash of every trait we've seen
179+ // When we see a trait for the first time, add it to unique_traits
180+ // so we can later use it to build a string of all traits exactly once, without duplicates
181+
177182 let mut seen_def_ids = FxHashSet :: default ( ) ;
178- let mut fixed_traits = Vec :: new( ) ;
183+ let mut unique_traits = Vec :: new( ) ;
179184
180185 // Iterate the bounds and add them to our seen hash
181186 // If we haven't yet seen it, add it to the fixed traits
@@ -185,20 +190,20 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
185190 let new_trait = seen_def_ids. insert( def_id) ;
186191
187192 if new_trait {
188- fixed_traits . push( bound) ;
193+ unique_traits . push( bound) ;
189194 }
190195 }
191196
192- // If the number added to fixed (which are not duplicates) isn't the same as the number found ,
197+ // If the number of unique traits isn't the same as the number of traits in the bounds ,
193198 // there must be 1 or more duplicates
194- if bounds. len( ) != fixed_traits . len( ) {
199+ if bounds. len( ) != unique_traits . len( ) {
195200 let mut bounds_span = bounds[ 0 ] . span;
196201
197202 for bound in bounds. iter( ) . skip( 1 ) {
198203 bounds_span = bounds_span. to( bound. span) ;
199204 }
200205
201- let fixed_trait_snippet = fixed_traits
206+ let fixed_trait_snippet = unique_traits
202207 . iter( )
203208 . filter_map( |b| snippet_opt( cx, b. span) )
204209 . collect:: <Vec <_>>( )
0 commit comments