@@ -12,7 +12,6 @@ use std::cmp::Ordering;
12
12
use std:: fmt:: { self , Display , Write } ;
13
13
use std:: iter:: { self , once} ;
14
14
15
- use itertools:: Itertools ;
16
15
use rustc_abi:: ExternAbi ;
17
16
use rustc_attr_parsing:: { ConstStability , StabilityLevel , StableSince } ;
18
17
use rustc_data_structures:: captures:: Captures ;
@@ -34,6 +33,7 @@ use crate::formats::cache::Cache;
34
33
use crate :: formats:: item_type:: ItemType ;
35
34
use crate :: html:: escape:: { Escape , EscapeBodyText } ;
36
35
use crate :: html:: render:: Context ;
36
+ use crate :: join:: Join as _;
37
37
use crate :: passes:: collect_intra_doc_links:: UrlFragment ;
38
38
39
39
pub ( crate ) trait Print {
@@ -150,14 +150,13 @@ pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>(
150
150
cx : & ' a Context < ' tcx > ,
151
151
) -> impl Display + ' a + Captures < ' tcx > {
152
152
fmt:: from_fn ( move |f| {
153
- let mut bounds_dup = FxHashSet :: default ( ) ;
153
+ ( || {
154
+ let mut bounds_dup = FxHashSet :: default ( ) ;
154
155
155
- bounds
156
- . iter ( )
157
- . filter ( |b| bounds_dup. insert ( * b) )
158
- . map ( |bound| bound. print ( cx) )
159
- . format ( " + " )
160
- . fmt ( f)
156
+ bounds. iter ( ) . filter ( move |b| bounds_dup. insert ( * b) ) . map ( |bound| bound. print ( cx) )
157
+ } )
158
+ . join ( " + " )
159
+ . fmt ( f)
161
160
} )
162
161
}
163
162
@@ -172,7 +171,7 @@ impl clean::GenericParamDef {
172
171
173
172
if !outlives. is_empty ( ) {
174
173
f. write_str ( ": " ) ?;
175
- write ! ( f, "{}" , outlives. iter( ) . map( |lt| lt. print( ) ) . format ( " + " ) ) ?;
174
+ write ! ( f, "{}" , ( || outlives. iter( ) . map( |lt| lt. print( ) ) ) . join ( " + " ) ) ?;
176
175
}
177
176
178
177
Ok ( ( ) )
@@ -222,10 +221,11 @@ impl clean::Generics {
222
221
return Ok ( ( ) ) ;
223
222
}
224
223
224
+ let real_params = ( || real_params. clone ( ) . map ( |g| g. print ( cx) ) ) . join ( ", " ) ;
225
225
if f. alternate ( ) {
226
- write ! ( f, "<{:#}>" , real_params. map ( |g| g . print ( cx ) ) . format ( ", " ) )
226
+ write ! ( f, "<{:#}>" , real_params)
227
227
} else {
228
- write ! ( f, "<{}>" , real_params. map ( |g| g . print ( cx ) ) . format ( ", " ) )
228
+ write ! ( f, "<{}>" , real_params)
229
229
}
230
230
} )
231
231
}
@@ -247,10 +247,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
247
247
ending : Ending ,
248
248
) -> impl Display + ' a + Captures < ' tcx > {
249
249
fmt:: from_fn ( move |f| {
250
- let mut where_predicates = gens
251
- . where_predicates
252
- . iter ( )
253
- . map ( |pred| {
250
+ if gens. where_predicates . is_empty ( ) {
251
+ return Ok ( ( ) ) ;
252
+ }
253
+
254
+ let where_predicates = || {
255
+ gens. where_predicates . iter ( ) . map ( |pred| {
254
256
fmt:: from_fn ( move |f| {
255
257
if f. alternate ( ) {
256
258
f. write_str ( " " ) ?;
@@ -289,13 +291,9 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
289
291
}
290
292
} )
291
293
} )
292
- . peekable ( ) ;
293
-
294
- if where_predicates. peek ( ) . is_none ( ) {
295
- return Ok ( ( ) ) ;
296
- }
294
+ } ;
297
295
298
- let where_preds = where_predicates. format ( "," ) ;
296
+ let where_preds = where_predicates. join ( "," ) ;
299
297
let clause = if f. alternate ( ) {
300
298
if ending == Ending :: Newline {
301
299
format ! ( " where{where_preds}," )
@@ -392,7 +390,7 @@ impl clean::GenericBound {
392
390
} else {
393
391
f. write_str ( "use<" ) ?;
394
392
}
395
- args. iter ( ) . format ( ", " ) . fmt ( f) ?;
393
+ ( || args. iter ( ) ) . join ( ", " ) . fmt ( f) ?;
396
394
if f. alternate ( ) { f. write_str ( ">" ) } else { f. write_str ( ">" ) }
397
395
}
398
396
} )
@@ -496,7 +494,7 @@ pub(crate) enum HrefError {
496
494
// Panics if `syms` is empty.
497
495
pub ( crate ) fn join_with_double_colon ( syms : & [ Symbol ] ) -> String {
498
496
let mut s = String :: with_capacity ( estimate_item_path_byte_length ( syms. len ( ) ) ) ;
499
- write ! ( s, "{}" , syms. iter( ) . format ( "::" ) ) . unwrap ( ) ;
497
+ write ! ( s, "{}" , ( || syms. iter( ) ) . join ( "::" ) ) . unwrap ( ) ;
500
498
s
501
499
}
502
500
@@ -546,14 +544,14 @@ fn generate_macro_def_id_path(
546
544
let url = match cache. extern_locations [ & def_id. krate ] {
547
545
ExternalLocation :: Remote ( ref s) => {
548
546
// `ExternalLocation::Remote` always end with a `/`.
549
- format ! ( "{s}{path}" , path = path. iter( ) . format ( "/" ) )
547
+ format ! ( "{s}{path}" , path = ( || path. iter( ) ) . join ( "/" ) )
550
548
}
551
549
ExternalLocation :: Local => {
552
550
// `root_path` always end with a `/`.
553
551
format ! (
554
552
"{root_path}{path}" ,
555
553
root_path = root_path. unwrap_or( "" ) ,
556
- path = path. iter( ) . format ( "/" )
554
+ path = ( || path. iter( ) ) . join ( "/" )
557
555
)
558
556
}
559
557
ExternalLocation :: Unknown => {
@@ -917,7 +915,7 @@ fn tybounds<'a, 'tcx: 'a>(
917
915
cx : & ' a Context < ' tcx > ,
918
916
) -> impl Display + ' a + Captures < ' tcx > {
919
917
fmt:: from_fn ( move |f| {
920
- bounds. iter ( ) . map ( |bound| bound. print ( cx) ) . format ( " + " ) . fmt ( f) ?;
918
+ ( || bounds. iter ( ) . map ( |bound| bound. print ( cx) ) ) . join ( " + " ) . fmt ( f) ?;
921
919
if let Some ( lt) = lt {
922
920
// We don't need to check `alternate` since we can be certain that
923
921
// the lifetime doesn't contain any characters which need escaping.
@@ -936,7 +934,7 @@ fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>(
936
934
if !params. is_empty ( ) {
937
935
f. write_str ( keyword) ?;
938
936
f. write_str ( if f. alternate ( ) { "<" } else { "<" } ) ?;
939
- params. iter ( ) . map ( |lt| lt. print ( cx) ) . format ( ", " ) . fmt ( f) ?;
937
+ ( || params. iter ( ) . map ( |lt| lt. print ( cx) ) ) . join ( ", " ) . fmt ( f) ?;
940
938
f. write_str ( if f. alternate ( ) { "> " } else { "> " } ) ?;
941
939
}
942
940
Ok ( ( ) )
@@ -1027,12 +1025,12 @@ fn fmt_type(
1027
1025
primitive_link (
1028
1026
f,
1029
1027
PrimitiveType :: Tuple ,
1030
- format_args ! ( "({})" , generic_names. iter( ) . format ( ", " ) ) ,
1028
+ format_args ! ( "({})" , ( || generic_names. iter( ) ) . join ( ", " ) ) ,
1031
1029
cx,
1032
1030
)
1033
1031
} else {
1034
1032
f. write_str ( "(" ) ?;
1035
- many. iter ( ) . map ( |item| item. print ( cx) ) . format ( ", " ) . fmt ( f) ?;
1033
+ ( || many. iter ( ) . map ( |item| item. print ( cx) ) ) . join ( ", " ) . fmt ( f) ?;
1036
1034
f. write_str ( ")" )
1037
1035
}
1038
1036
}
@@ -1362,16 +1360,16 @@ impl clean::Arguments {
1362
1360
cx : & ' a Context < ' tcx > ,
1363
1361
) -> impl Display + ' a + Captures < ' tcx > {
1364
1362
fmt:: from_fn ( move |f| {
1365
- self . values
1366
- . iter ( )
1367
- . map ( |input| {
1363
+ ( || {
1364
+ self . values . iter ( ) . map ( |input| {
1368
1365
fmt:: from_fn ( |f| {
1369
1366
write ! ( f, "{}: " , input. name) ?;
1370
1367
input. type_ . print ( cx) . fmt ( f)
1371
1368
} )
1372
1369
} )
1373
- . format ( ", " )
1374
- . fmt ( f)
1370
+ } )
1371
+ . join ( ", " )
1372
+ . fmt ( f)
1375
1373
} )
1376
1374
}
1377
1375
}
0 commit comments