@@ -1019,7 +1019,7 @@ fn assoc_method<'a, 'tcx>(
10191019/// example, if the item became stable at 1.0.0, and const-stable at 1.45.0, this function would
10201020/// write a span containing "1.0.0 (const: 1.45.0)".
10211021///
1022- /// Returns `true ` if a stability annotation was rendered.
1022+ /// Returns `None ` if there is no stability annotation to be rendered.
10231023///
10241024/// Stability and const-stability are considered separately. If the item is unstable, no version
10251025/// will be written. If the item is const-unstable, "const: unstable" will be appended to the
@@ -1030,11 +1030,10 @@ fn assoc_method<'a, 'tcx>(
10301030/// will include the const-stable version, but no stable version will be emitted, as a natural
10311031/// consequence of the above rules.
10321032fn render_stability_since_raw_with_extra (
1033- w : & mut String ,
10341033 stable_version : Option < StableSince > ,
10351034 const_stability : Option < ConstStability > ,
10361035 extra_class : & str ,
1037- ) -> bool {
1036+ ) -> Option < impl fmt :: Display + ' _ > {
10381037 let mut title = String :: new ( ) ;
10391038 let mut stability = String :: new ( ) ;
10401039
@@ -1084,14 +1083,9 @@ fn render_stability_since_raw_with_extra(
10841083 }
10851084 }
10861085
1087- if !stability. is_empty ( ) {
1088- write_str (
1089- w,
1090- format_args ! ( r#"<span class="since{extra_class}" title="{title}">{stability}</span>"# ) ,
1091- ) ;
1092- }
1093-
1094- !stability. is_empty ( )
1086+ ( !stability. is_empty ( ) ) . then_some ( fmt:: from_fn ( move |w| {
1087+ write ! ( w, r#"<span class="since{extra_class}" title="{title}">{stability}</span>"# )
1088+ } ) )
10951089}
10961090
10971091fn since_to_string ( since : & StableSince ) -> Option < String > {
@@ -1104,11 +1098,10 @@ fn since_to_string(since: &StableSince) -> Option<String> {
11041098
11051099#[ inline]
11061100fn render_stability_since_raw (
1107- w : & mut String ,
11081101 ver : Option < StableSince > ,
11091102 const_stability : Option < ConstStability > ,
1110- ) -> bool {
1111- render_stability_since_raw_with_extra ( w , ver, const_stability, "" )
1103+ ) -> Option < impl fmt :: Display > {
1104+ render_stability_since_raw_with_extra ( ver, const_stability, "" )
11121105}
11131106
11141107fn render_assoc_item < ' a , ' tcx > (
@@ -2114,30 +2107,27 @@ fn render_rightside(w: &mut String, cx: &Context<'_>, item: &clean::Item, render
21142107 let src_href = cx. src_href ( item) ;
21152108 let has_src_ref = src_href. is_some ( ) ;
21162109
2117- let mut rightside = String :: new ( ) ;
2118- let has_stability = render_stability_since_raw_with_extra (
2119- & mut rightside,
2110+ let stability = render_stability_since_raw_with_extra (
21202111 item. stable_since ( tcx) ,
21212112 const_stability,
21222113 if has_src_ref { "" } else { " rightside" } ,
21232114 ) ;
2124- if let Some ( link) = src_href {
2125- if has_stability {
2126- write_str (
2127- & mut rightside,
2128- format_args ! ( " · <a class=\" src\" href=\" {link}\" >Source</a>" ) ,
2129- ) ;
2130- } else {
2115+ match ( stability, src_href) {
2116+ ( Some ( stability) , Some ( link) ) => {
21312117 write_str (
2132- & mut rightside,
2133- format_args ! ( "<a class=\" src rightside\" href=\" {link}\" >Source</a>" ) ,
2118+ w,
2119+ format_args ! (
2120+ "<span class=\" rightside\" >{stability} · <a class=\" src\" href=\" {link}\" >Source</a></span>"
2121+ ) ,
21342122 ) ;
21352123 }
2136- }
2137- if has_stability && has_src_ref {
2138- write_str ( w, format_args ! ( "<span class=\" rightside\" >{rightside}</span>" ) ) ;
2139- } else {
2140- w. push_str ( & rightside) ;
2124+ ( Some ( stability) , None ) => {
2125+ write_str ( w, format_args ! ( "{stability}" ) ) ;
2126+ }
2127+ ( None , Some ( link) ) => {
2128+ write_str ( w, format_args ! ( "<a class=\" src rightside\" href=\" {link}\" >Source</a>" ) ) ;
2129+ }
2130+ ( None , None ) => { }
21412131 }
21422132}
21432133
0 commit comments