@@ -799,58 +799,77 @@ fn assoc_type(
799799 }
800800}
801801
802+ /// Writes a span containing the versions at which an item became stable and/or const-stable. For
803+ /// example, if the item became stable at 1.0.0, and const-stable at 1.45.0, this function would
804+ /// write a span containing "1.0.0 (const: 1.45.0)".
805+ ///
806+ /// Returns `true` if a stability annotation was rendered.
807+ ///
808+ /// Stability and const-stability are considered separately. If the item is unstable, no version
809+ /// will be written. If the item is const-unstable, "const: unstable" will be appended to the
810+ /// span, with a link to the tracking issue if present. If an item's stability or const-stability
811+ /// version matches the version of its enclosing item, that version will be omitted.
812+ ///
813+ /// Note that it is possible for an unstable function to be const-stable. In that case, the span
814+ /// will include the const-stable version, but no stable version will be emitted, as a natural
815+ /// consequence of the above rules.
802816fn render_stability_since_raw (
803817 w : & mut Buffer ,
804818 ver : Option < Symbol > ,
805819 const_stability : Option < ConstStability > ,
806820 containing_ver : Option < Symbol > ,
807821 containing_const_ver : Option < Symbol > ,
808822) -> bool {
809- let ver = ver. filter ( |inner| !inner. is_empty ( ) ) ;
823+ let stable_version = ver. filter ( |inner| !inner. is_empty ( ) && Some ( * inner ) != containing_ver ) ;
810824
811- match ( ver, const_stability) {
812- // stable and const stable
813- ( Some ( v) , Some ( ConstStability { level : StabilityLevel :: Stable { since } , .. } ) )
825+ let mut title = String :: new ( ) ;
826+ let mut stability = String :: new ( ) ;
827+
828+ if let Some ( ver) = stable_version {
829+ stability. push_str ( & ver. as_str ( ) ) ;
830+ title. push_str ( & format ! ( "Stable since Rust version {}" , ver) ) ;
831+ }
832+
833+ let const_title_and_stability = match const_stability {
834+ Some ( ConstStability { level : StabilityLevel :: Stable { since } , .. } )
814835 if Some ( since) != containing_const_ver =>
815836 {
816- write ! (
817- w,
818- "<span class=\" since\" title=\" Stable since Rust version {0}, const since {1}\" >{0} (const: {1})</span>" ,
819- v, since
820- ) ;
837+ Some ( ( format ! ( "const since {}" , since) , format ! ( "const: {}" , since) ) )
821838 }
822- // stable and const unstable
823- (
824- Some ( v) ,
825- Some ( ConstStability { level : StabilityLevel :: Unstable { issue, .. } , feature, .. } ) ,
826- ) => {
827- write ! (
828- w,
829- "<span class=\" since\" title=\" Stable since Rust version {0}, const unstable\" >{0} (const: " ,
830- v
831- ) ;
832- if let Some ( n) = issue {
833- write ! (
834- w,
835- "<a href=\" https://github.com/rust-lang/rust/issues/{}\" title=\" Tracking issue for {}\" >unstable</a>" ,
839+ Some ( ConstStability { level : StabilityLevel :: Unstable { issue, .. } , feature, .. } ) => {
840+ let unstable = if let Some ( n) = issue {
841+ format ! (
842+ r#"<a href="https://github.com/rust-lang/rust/issues/{}" title="Tracking issue for {}">unstable</a>"# ,
836843 n, feature
837- ) ;
844+ )
838845 } else {
839- write ! ( w, "unstable" ) ;
840- }
841- write ! ( w, ")</span>" ) ;
846+ String :: from ( "unstable" )
847+ } ;
848+
849+ Some ( ( String :: from ( "const unstable" ) , format ! ( "const: {}" , unstable) ) )
842850 }
843- // stable
844- ( Some ( v) , _) if ver != containing_ver => {
845- write ! (
846- w,
847- "<span class=\" since\" title=\" Stable since Rust version {0}\" >{0}</span>" ,
848- v
849- ) ;
851+ _ => None ,
852+ } ;
853+
854+ if let Some ( ( const_title, const_stability) ) = const_title_and_stability {
855+ if !title. is_empty ( ) {
856+ title. push_str ( & format ! ( ", {}" , const_title) ) ;
857+ } else {
858+ title. push_str ( & const_title) ;
859+ }
860+
861+ if !stability. is_empty ( ) {
862+ stability. push_str ( & format ! ( " ({})" , const_stability) ) ;
863+ } else {
864+ stability. push_str ( & const_stability) ;
850865 }
851- _ => return false ,
852866 }
853- true
867+
868+ if !stability. is_empty ( ) {
869+ write ! ( w, r#"<span class="since" title="{}">{}</span>"# , title, stability) ;
870+ }
871+
872+ !stability. is_empty ( )
854873}
855874
856875fn render_assoc_item (
0 commit comments