@@ -9,6 +9,7 @@ use std::borrow::Cow;
9
9
use std:: fmt;
10
10
11
11
use rustc:: hir:: def_id:: DefId ;
12
+ use rustc:: util:: nodemap:: FxHashSet ;
12
13
use rustc_target:: spec:: abi:: Abi ;
13
14
use rustc:: hir;
14
15
@@ -106,8 +107,10 @@ impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> {
106
107
107
108
impl < ' a > fmt:: Display for GenericBounds < ' a > {
108
109
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
110
+ let mut bounds_dup = FxHashSet :: default ( ) ;
109
111
let & GenericBounds ( bounds) = self ;
110
- for ( i, bound) in bounds. iter ( ) . enumerate ( ) {
112
+
113
+ for ( i, bound) in bounds. iter ( ) . filter ( |b| bounds_dup. insert ( b. to_string ( ) ) ) . enumerate ( ) {
111
114
if i > 0 {
112
115
f. write_str ( " + " ) ?;
113
116
}
@@ -205,16 +208,13 @@ impl<'a> fmt::Display for WhereClause<'a> {
205
208
clause. push_str ( & format ! ( "{}: {}" , ty, GenericBounds ( bounds) ) ) ;
206
209
}
207
210
}
208
- & clean:: WherePredicate :: RegionPredicate { ref lifetime,
209
- ref bounds } => {
210
- clause. push_str ( & format ! ( "{}: " , lifetime) ) ;
211
- for ( i, lifetime) in bounds. iter ( ) . enumerate ( ) {
212
- if i > 0 {
213
- clause. push_str ( " + " ) ;
214
- }
215
-
216
- clause. push_str ( & lifetime. to_string ( ) ) ;
217
- }
211
+ & clean:: WherePredicate :: RegionPredicate { ref lifetime, ref bounds } => {
212
+ clause. push_str ( & format ! ( "{}: {}" ,
213
+ lifetime,
214
+ bounds. iter( )
215
+ . map( |b| b. to_string( ) )
216
+ . collect:: <Vec <_>>( )
217
+ . join( " + " ) ) ) ;
218
218
}
219
219
& clean:: WherePredicate :: EqPredicate { ref lhs, ref rhs } => {
220
220
if f. alternate ( ) {
0 commit comments