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