@@ -260,7 +260,10 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
260
260
clean:: ForeignStaticItem ( ref i, safety) => {
261
261
write_str ( buf, format_args ! ( "{}" , item_static( cx, item, i, Some ( * safety) ) ) )
262
262
}
263
- clean:: ConstantItem ( ci) => item_constant ( buf, cx, item, & ci. generics , & ci. type_ , & ci. kind ) ,
263
+ clean:: ConstantItem ( ci) => write_str (
264
+ buf,
265
+ format_args ! ( "{}" , item_constant( cx, item, & ci. generics, & ci. type_, & ci. kind) ) ,
266
+ ) ,
264
267
clean:: ForeignTypeItem => item_foreign_type ( buf, cx, item) ,
265
268
clean:: KeywordItem => item_keyword ( buf, cx, item) ,
266
269
clean:: TraitAliasItem ( ref ta) => item_trait_alias ( buf, cx, item, ta) ,
@@ -1952,64 +1955,64 @@ fn item_primitive<'a, 'tcx>(
1952
1955
} )
1953
1956
}
1954
1957
1955
- fn item_constant (
1956
- w : & mut String ,
1957
- cx : & Context < ' _ > ,
1958
- it : & clean:: Item ,
1959
- generics : & clean:: Generics ,
1960
- ty : & clean:: Type ,
1961
- c : & clean :: ConstantKind ,
1962
- ) {
1963
- wrap_item ( w, |w| {
1964
- let tcx = cx. tcx ( ) ;
1965
- render_attributes_in_code ( w, it, cx) ;
1958
+ fn item_constant < ' a , ' tcx > (
1959
+ cx : & ' a Context < ' tcx > ,
1960
+ it : & ' a clean :: Item ,
1961
+ generics : & ' a clean:: Generics ,
1962
+ ty : & ' a clean:: Type ,
1963
+ c : & ' a clean:: ConstantKind ,
1964
+ ) -> impl fmt :: Display + ' a + Captures < ' tcx > {
1965
+ fmt :: from_fn ( |w| {
1966
+ wrap_item ( w, |w| {
1967
+ let tcx = cx. tcx ( ) ;
1968
+ render_attributes_in_code ( w, it, cx) ;
1966
1969
1967
- write_str (
1968
- w,
1969
- format_args ! (
1970
+ write ! (
1971
+ w,
1970
1972
"{vis}const {name}{generics}: {typ}{where_clause}" ,
1971
1973
vis = visibility_print_with_space( it, cx) ,
1972
1974
name = it. name. unwrap( ) ,
1973
1975
generics = generics. print( cx) ,
1974
1976
typ = ty. print( cx) ,
1975
1977
where_clause =
1976
1978
print_where_clause( generics, cx, 0 , Ending :: NoNewline ) . maybe_display( ) ,
1977
- ) ,
1978
- ) ;
1979
+ ) ?;
1979
1980
1980
- // FIXME: The code below now prints
1981
- // ` = _; // 100i32`
1982
- // if the expression is
1983
- // `50 + 50`
1984
- // which looks just wrong.
1985
- // Should we print
1986
- // ` = 100i32;`
1987
- // instead?
1988
-
1989
- let value = c. value ( tcx) ;
1990
- let is_literal = c. is_literal ( tcx) ;
1991
- let expr = c. expr ( tcx) ;
1992
- if value. is_some ( ) || is_literal {
1993
- write_str ( w, format_args ! ( " = {expr};" , expr = Escape ( & expr) ) ) ;
1994
- } else {
1995
- w . push_str ( ";" ) ;
1996
- }
1981
+ // FIXME: The code below now prints
1982
+ // ` = _; // 100i32`
1983
+ // if the expression is
1984
+ // `50 + 50`
1985
+ // which looks just wrong.
1986
+ // Should we print
1987
+ // ` = 100i32;`
1988
+ // instead?
1989
+
1990
+ let value = c. value ( tcx) ;
1991
+ let is_literal = c. is_literal ( tcx) ;
1992
+ let expr = c. expr ( tcx) ;
1993
+ if value. is_some ( ) || is_literal {
1994
+ write ! ( w, " = {expr};" , expr = Escape ( & expr) ) ? ;
1995
+ } else {
1996
+ w . write_str ( ";" ) ? ;
1997
+ }
1997
1998
1998
- if !is_literal {
1999
- if let Some ( value) = & value {
2000
- let value_lowercase = value. to_lowercase ( ) ;
2001
- let expr_lowercase = expr. to_lowercase ( ) ;
1999
+ if !is_literal {
2000
+ if let Some ( value) = & value {
2001
+ let value_lowercase = value. to_lowercase ( ) ;
2002
+ let expr_lowercase = expr. to_lowercase ( ) ;
2002
2003
2003
- if value_lowercase != expr_lowercase
2004
- && value_lowercase. trim_end_matches ( "i32" ) != expr_lowercase
2005
- {
2006
- write_str ( w, format_args ! ( " // {value}" , value = Escape ( value) ) ) ;
2004
+ if value_lowercase != expr_lowercase
2005
+ && value_lowercase. trim_end_matches ( "i32" ) != expr_lowercase
2006
+ {
2007
+ write ! ( w, " // {value}" , value = Escape ( value) ) ?;
2008
+ }
2007
2009
}
2008
2010
}
2009
- }
2010
- } ) ;
2011
+ Ok ( ( ) )
2012
+ } ) ? ;
2011
2013
2012
- write_str ( w, format_args ! ( "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ) ;
2014
+ write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) )
2015
+ } )
2013
2016
}
2014
2017
2015
2018
fn item_struct < ' a , ' tcx > (
0 commit comments