@@ -1019,7 +1019,7 @@ fn assoc_method<'a, 'tcx>(
1019
1019
/// example, if the item became stable at 1.0.0, and const-stable at 1.45.0, this function would
1020
1020
/// write a span containing "1.0.0 (const: 1.45.0)".
1021
1021
///
1022
- /// Returns `true ` if a stability annotation was rendered.
1022
+ /// Returns `None ` if there is no stability annotation to be rendered.
1023
1023
///
1024
1024
/// Stability and const-stability are considered separately. If the item is unstable, no version
1025
1025
/// 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>(
1030
1030
/// will include the const-stable version, but no stable version will be emitted, as a natural
1031
1031
/// consequence of the above rules.
1032
1032
fn render_stability_since_raw_with_extra (
1033
- w : & mut String ,
1034
1033
stable_version : Option < StableSince > ,
1035
1034
const_stability : Option < ConstStability > ,
1036
1035
extra_class : & str ,
1037
- ) -> bool {
1036
+ ) -> Option < impl fmt :: Display + ' _ > {
1038
1037
let mut title = String :: new ( ) ;
1039
1038
let mut stability = String :: new ( ) ;
1040
1039
@@ -1084,14 +1083,9 @@ fn render_stability_since_raw_with_extra(
1084
1083
}
1085
1084
}
1086
1085
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
+ } ) )
1095
1089
}
1096
1090
1097
1091
fn since_to_string ( since : & StableSince ) -> Option < String > {
@@ -1104,11 +1098,10 @@ fn since_to_string(since: &StableSince) -> Option<String> {
1104
1098
1105
1099
#[ inline]
1106
1100
fn render_stability_since_raw (
1107
- w : & mut String ,
1108
1101
ver : Option < StableSince > ,
1109
1102
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, "" )
1112
1105
}
1113
1106
1114
1107
fn render_assoc_item < ' a , ' tcx > (
@@ -2114,30 +2107,27 @@ fn render_rightside(w: &mut String, cx: &Context<'_>, item: &clean::Item, render
2114
2107
let src_href = cx. src_href ( item) ;
2115
2108
let has_src_ref = src_href. is_some ( ) ;
2116
2109
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 (
2120
2111
item. stable_since ( tcx) ,
2121
2112
const_stability,
2122
2113
if has_src_ref { "" } else { " rightside" } ,
2123
2114
) ;
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) ) => {
2131
2117
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
+ ) ,
2134
2122
) ;
2135
2123
}
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 ) => { }
2141
2131
}
2142
2132
}
2143
2133
0 commit comments