1
1
use std:: cmp:: Ordering ;
2
2
use std:: fmt;
3
- use std:: fmt:: { Display , Write } ;
3
+ use std:: fmt:: Display ;
4
4
5
5
use itertools:: Itertools ;
6
6
use rinja:: Template ;
@@ -27,7 +27,7 @@ use super::{
27
27
} ;
28
28
use crate :: clean;
29
29
use crate :: config:: ModuleSorting ;
30
- use crate :: display:: Joined as _;
30
+ use crate :: display:: { Joined as _, MaybeDisplay as _ } ;
31
31
use crate :: formats:: Impl ;
32
32
use crate :: formats:: item_type:: ItemType ;
33
33
use crate :: html:: escape:: { Escape , EscapeBodyTextWithWbr } ;
@@ -2050,27 +2050,26 @@ pub(super) fn item_path(ty: ItemType, name: &str) -> String {
2050
2050
}
2051
2051
}
2052
2052
2053
- fn bounds ( t_bounds : & [ clean:: GenericBound ] , trait_alias : bool , cx : & Context < ' _ > ) -> String {
2054
- let mut bounds = String :: new ( ) ;
2055
- if t_bounds. is_empty ( ) {
2056
- return bounds;
2057
- }
2058
- let has_lots_of_bounds = t_bounds. len ( ) > 2 ;
2059
- let inter_str = if has_lots_of_bounds { "\n + " } else { " + " } ;
2060
- if !trait_alias {
2061
- if has_lots_of_bounds {
2062
- bounds. push_str ( ":\n " ) ;
2063
- } else {
2064
- bounds. push_str ( ": " ) ;
2065
- }
2066
- }
2067
- write ! (
2068
- bounds,
2069
- "{}" ,
2070
- fmt:: from_fn( |f| t_bounds. iter( ) . map( |p| p. print( cx) ) . joined( inter_str, f) )
2071
- )
2072
- . unwrap ( ) ;
2073
- bounds
2053
+ fn bounds < ' a , ' tcx > (
2054
+ bounds : & ' a [ clean:: GenericBound ] ,
2055
+ trait_alias : bool ,
2056
+ cx : & ' a Context < ' tcx > ,
2057
+ ) -> impl Display + ' a + Captures < ' tcx > {
2058
+ ( !bounds. is_empty ( ) )
2059
+ . then_some ( fmt:: from_fn ( move |f| {
2060
+ let has_lots_of_bounds = bounds. len ( ) > 2 ;
2061
+ let inter_str = if has_lots_of_bounds { "\n + " } else { " + " } ;
2062
+ if !trait_alias {
2063
+ if has_lots_of_bounds {
2064
+ f. write_str ( ":\n " ) ?;
2065
+ } else {
2066
+ f. write_str ( ": " ) ?;
2067
+ }
2068
+ }
2069
+
2070
+ bounds. iter ( ) . map ( |p| p. print ( cx) ) . joined ( inter_str, f)
2071
+ } ) )
2072
+ . maybe_display ( )
2074
2073
}
2075
2074
2076
2075
fn wrap_item < W , F > ( w : & mut W , f : F )
0 commit comments