@@ -12,7 +12,6 @@ use std::cmp::Ordering;
1212use std:: fmt:: { self , Display , Write } ;
1313use std:: iter:: { self , once} ;
1414
15- use itertools:: Itertools ;
1615use rustc_abi:: ExternAbi ;
1716use rustc_attr_parsing:: { ConstStability , StabilityLevel , StableSince } ;
1817use rustc_data_structures:: captures:: Captures ;
@@ -34,6 +33,7 @@ use crate::formats::cache::Cache;
3433use crate :: formats:: item_type:: ItemType ;
3534use crate :: html:: escape:: { Escape , EscapeBodyText } ;
3635use crate :: html:: render:: Context ;
36+ use crate :: join:: Join as _;
3737use crate :: passes:: collect_intra_doc_links:: UrlFragment ;
3838
3939pub ( crate ) trait Print {
@@ -150,14 +150,13 @@ pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>(
150150 cx : & ' a Context < ' tcx > ,
151151) -> impl Display + ' a + Captures < ' tcx > {
152152 fmt:: from_fn ( move |f| {
153- let mut bounds_dup = FxHashSet :: default ( ) ;
153+ ( || {
154+ let mut bounds_dup = FxHashSet :: default ( ) ;
154155
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)
161160 } )
162161}
163162
@@ -172,7 +171,7 @@ impl clean::GenericParamDef {
172171
173172 if !outlives. is_empty ( ) {
174173 f. write_str ( ": " ) ?;
175- write ! ( f, "{}" , outlives. iter( ) . map( |lt| lt. print( ) ) . format ( " + " ) ) ?;
174+ write ! ( f, "{}" , ( || outlives. iter( ) . map( |lt| lt. print( ) ) ) . join ( " + " ) ) ?;
176175 }
177176
178177 Ok ( ( ) )
@@ -222,10 +221,11 @@ impl clean::Generics {
222221 return Ok ( ( ) ) ;
223222 }
224223
224+ let real_params = ( || real_params. clone ( ) . map ( |g| g. print ( cx) ) ) . join ( ", " ) ;
225225 if f. alternate ( ) {
226- write ! ( f, "<{:#}>" , real_params. map ( |g| g . print ( cx ) ) . format ( ", " ) )
226+ write ! ( f, "<{:#}>" , real_params)
227227 } else {
228- write ! ( f, "<{}>" , real_params. map ( |g| g . print ( cx ) ) . format ( ", " ) )
228+ write ! ( f, "<{}>" , real_params)
229229 }
230230 } )
231231 }
@@ -247,10 +247,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
247247 ending : Ending ,
248248) -> impl Display + ' a + Captures < ' tcx > {
249249 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| {
254256 fmt:: from_fn ( move |f| {
255257 if f. alternate ( ) {
256258 f. write_str ( " " ) ?;
@@ -289,13 +291,9 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
289291 }
290292 } )
291293 } )
292- . peekable ( ) ;
293-
294- if where_predicates. peek ( ) . is_none ( ) {
295- return Ok ( ( ) ) ;
296- }
294+ } ;
297295
298- let where_preds = where_predicates. format ( "," ) ;
296+ let where_preds = where_predicates. join ( "," ) ;
299297 let clause = if f. alternate ( ) {
300298 if ending == Ending :: Newline {
301299 format ! ( " where{where_preds}," )
@@ -392,7 +390,7 @@ impl clean::GenericBound {
392390 } else {
393391 f. write_str ( "use<" ) ?;
394392 }
395- args. iter ( ) . format ( ", " ) . fmt ( f) ?;
393+ ( || args. iter ( ) ) . join ( ", " ) . fmt ( f) ?;
396394 if f. alternate ( ) { f. write_str ( ">" ) } else { f. write_str ( ">" ) }
397395 }
398396 } )
@@ -496,7 +494,7 @@ pub(crate) enum HrefError {
496494// Panics if `syms` is empty.
497495pub ( crate ) fn join_with_double_colon ( syms : & [ Symbol ] ) -> String {
498496 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 ( ) ;
500498 s
501499}
502500
@@ -546,14 +544,14 @@ fn generate_macro_def_id_path(
546544 let url = match cache. extern_locations [ & def_id. krate ] {
547545 ExternalLocation :: Remote ( ref s) => {
548546 // `ExternalLocation::Remote` always end with a `/`.
549- format ! ( "{s}{path}" , path = path. iter( ) . format ( "/" ) )
547+ format ! ( "{s}{path}" , path = ( || path. iter( ) ) . join ( "/" ) )
550548 }
551549 ExternalLocation :: Local => {
552550 // `root_path` always end with a `/`.
553551 format ! (
554552 "{root_path}{path}" ,
555553 root_path = root_path. unwrap_or( "" ) ,
556- path = path. iter( ) . format ( "/" )
554+ path = ( || path. iter( ) ) . join ( "/" )
557555 )
558556 }
559557 ExternalLocation :: Unknown => {
@@ -917,7 +915,7 @@ fn tybounds<'a, 'tcx: 'a>(
917915 cx : & ' a Context < ' tcx > ,
918916) -> impl Display + ' a + Captures < ' tcx > {
919917 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) ?;
921919 if let Some ( lt) = lt {
922920 // We don't need to check `alternate` since we can be certain that
923921 // the lifetime doesn't contain any characters which need escaping.
@@ -936,7 +934,7 @@ fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>(
936934 if !params. is_empty ( ) {
937935 f. write_str ( keyword) ?;
938936 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) ?;
940938 f. write_str ( if f. alternate ( ) { "> " } else { "> " } ) ?;
941939 }
942940 Ok ( ( ) )
@@ -1027,12 +1025,12 @@ fn fmt_type(
10271025 primitive_link (
10281026 f,
10291027 PrimitiveType :: Tuple ,
1030- format_args ! ( "({})" , generic_names. iter( ) . format ( ", " ) ) ,
1028+ format_args ! ( "({})" , ( || generic_names. iter( ) ) . join ( ", " ) ) ,
10311029 cx,
10321030 )
10331031 } else {
10341032 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) ?;
10361034 f. write_str ( ")" )
10371035 }
10381036 }
@@ -1362,16 +1360,16 @@ impl clean::Arguments {
13621360 cx : & ' a Context < ' tcx > ,
13631361 ) -> impl Display + ' a + Captures < ' tcx > {
13641362 fmt:: from_fn ( move |f| {
1365- self . values
1366- . iter ( )
1367- . map ( |input| {
1363+ ( || {
1364+ self . values . iter ( ) . map ( |input| {
13681365 fmt:: from_fn ( |f| {
13691366 write ! ( f, "{}: " , input. name) ?;
13701367 input. type_ . print ( cx) . fmt ( f)
13711368 } )
13721369 } )
1373- . format ( ", " )
1374- . fmt ( f)
1370+ } )
1371+ . join ( ", " )
1372+ . fmt ( f)
13751373 } )
13761374 }
13771375}
0 commit comments