@@ -174,8 +174,13 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
174
174
if let TyKind :: TraitObject ( bounds, ..) = mut_ty. ty. kind;
175
175
if bounds. len( ) > 2 ;
176
176
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
+
177
182
let mut seen_def_ids = FxHashSet :: default ( ) ;
178
- let mut fixed_traits = Vec :: new( ) ;
183
+ let mut unique_traits = Vec :: new( ) ;
179
184
180
185
// Iterate the bounds and add them to our seen hash
181
186
// If we haven't yet seen it, add it to the fixed traits
@@ -185,20 +190,20 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
185
190
let new_trait = seen_def_ids. insert( def_id) ;
186
191
187
192
if new_trait {
188
- fixed_traits . push( bound) ;
193
+ unique_traits . push( bound) ;
189
194
}
190
195
}
191
196
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 ,
193
198
// there must be 1 or more duplicates
194
- if bounds. len( ) != fixed_traits . len( ) {
199
+ if bounds. len( ) != unique_traits . len( ) {
195
200
let mut bounds_span = bounds[ 0 ] . span;
196
201
197
202
for bound in bounds. iter( ) . skip( 1 ) {
198
203
bounds_span = bounds_span. to( bound. span) ;
199
204
}
200
205
201
- let fixed_trait_snippet = fixed_traits
206
+ let fixed_trait_snippet = unique_traits
202
207
. iter( )
203
208
. filter_map( |b| snippet_opt( cx, b. span) )
204
209
. collect:: <Vec <_>>( )
0 commit comments