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 } ;
@@ -2123,27 +2123,26 @@ pub(super) fn item_path(ty: ItemType, name: &str) -> String {
2123
2123
}
2124
2124
}
2125
2125
2126
- fn bounds ( t_bounds : & [ clean:: GenericBound ] , trait_alias : bool , cx : & Context < ' _ > ) -> String {
2127
- let mut bounds = String :: new ( ) ;
2128
- if t_bounds. is_empty ( ) {
2129
- return bounds;
2130
- }
2131
- let has_lots_of_bounds = t_bounds. len ( ) > 2 ;
2132
- let inter_str = if has_lots_of_bounds { "\n + " } else { " + " } ;
2133
- if !trait_alias {
2134
- if has_lots_of_bounds {
2135
- bounds. push_str ( ":\n " ) ;
2136
- } else {
2137
- bounds. push_str ( ": " ) ;
2138
- }
2139
- }
2140
- write ! (
2141
- bounds,
2142
- "{}" ,
2143
- fmt:: from_fn( |f| t_bounds. iter( ) . map( |p| p. print( cx) ) . joined( inter_str, f) )
2144
- )
2145
- . unwrap ( ) ;
2146
- bounds
2126
+ fn bounds < ' a , ' tcx > (
2127
+ bounds : & ' a [ clean:: GenericBound ] ,
2128
+ trait_alias : bool ,
2129
+ cx : & ' a Context < ' tcx > ,
2130
+ ) -> impl Display + ' a + Captures < ' tcx > {
2131
+ ( !bounds. is_empty ( ) )
2132
+ . then_some ( fmt:: from_fn ( move |f| {
2133
+ let has_lots_of_bounds = bounds. len ( ) > 2 ;
2134
+ let inter_str = if has_lots_of_bounds { "\n + " } else { " + " } ;
2135
+ if !trait_alias {
2136
+ if has_lots_of_bounds {
2137
+ f. write_str ( ":\n " ) ?;
2138
+ } else {
2139
+ f. write_str ( ": " ) ?;
2140
+ }
2141
+ }
2142
+
2143
+ bounds. iter ( ) . map ( |p| p. print ( cx) ) . joined ( inter_str, f)
2144
+ } ) )
2145
+ . maybe_display ( )
2147
2146
}
2148
2147
2149
2148
fn wrap_item < W , F > ( w : & mut W , f : F )
0 commit comments