@@ -42,7 +42,7 @@ use std::str;
42
42
use std:: string:: ToString ;
43
43
44
44
use rustc_ast_pretty:: pprust;
45
- use rustc_attr:: { Deprecation , StabilityLevel } ;
45
+ use rustc_attr:: { ConstStability , Deprecation , StabilityLevel } ;
46
46
use rustc_data_structures:: fx:: FxHashSet ;
47
47
use rustc_hir as hir;
48
48
use rustc_hir:: def:: CtorKind ;
@@ -61,8 +61,8 @@ use crate::formats::item_type::ItemType;
61
61
use crate :: formats:: { AssocItemRender , Impl , RenderMode } ;
62
62
use crate :: html:: escape:: Escape ;
63
63
use crate :: html:: format:: {
64
- href, print_abi_with_space, print_default_space , print_generic_bounds , print_where_clause ,
65
- Buffer , PrintWithSpace ,
64
+ href, print_abi_with_space, print_constness_with_space , print_default_space ,
65
+ print_generic_bounds , print_where_clause , Buffer , PrintWithSpace ,
66
66
} ;
67
67
use crate :: html:: markdown:: { Markdown , MarkdownHtml , MarkdownSummaryLine } ;
68
68
@@ -826,21 +826,45 @@ fn assoc_type(
826
826
fn render_stability_since_raw (
827
827
w : & mut Buffer ,
828
828
ver : Option < & str > ,
829
- const_ver : Option < & str > ,
829
+ const_stability : Option < & ConstStability > ,
830
830
containing_ver : Option < & str > ,
831
831
containing_const_ver : Option < & str > ,
832
832
) {
833
833
let ver = ver. filter ( |inner| !inner. is_empty ( ) ) ;
834
- let const_ver = const_ver. filter ( |inner| !inner. is_empty ( ) ) ;
835
834
836
- match ( ver, const_ver) {
837
- ( Some ( v) , Some ( cv) ) if const_ver != containing_const_ver => {
835
+ match ( ver, const_stability) {
836
+ // stable and const stable
837
+ ( Some ( v) , Some ( ConstStability { level : StabilityLevel :: Stable { since } , .. } ) )
838
+ if Some ( since. as_str ( ) ) . as_deref ( ) != containing_const_ver =>
839
+ {
838
840
write ! (
839
841
w,
840
842
"<span class=\" since\" title=\" Stable since Rust version {0}, const since {1}\" >{0} (const: {1})</span>" ,
841
- v, cv
843
+ v, since
842
844
) ;
843
845
}
846
+ // stable and const unstable
847
+ (
848
+ Some ( v) ,
849
+ Some ( ConstStability { level : StabilityLevel :: Unstable { issue, .. } , feature, .. } ) ,
850
+ ) => {
851
+ write ! (
852
+ w,
853
+ "<span class=\" since\" title=\" Stable since Rust version {0}, const unstable\" >{0} (const: " ,
854
+ v
855
+ ) ;
856
+ if let Some ( n) = issue {
857
+ write ! (
858
+ w,
859
+ "<a href=\" https://github.com/rust-lang/rust/issues/{}\" title=\" Tracking issue for {}\" >unstable</a>" ,
860
+ n, feature
861
+ ) ;
862
+ } else {
863
+ write ! ( w, "unstable" ) ;
864
+ }
865
+ write ! ( w, ")</span>" ) ;
866
+ }
867
+ // stable
844
868
( Some ( v) , _) if ver != containing_ver => {
845
869
write ! (
846
870
w,
@@ -888,11 +912,13 @@ fn render_assoc_item(
888
912
}
889
913
} ;
890
914
let vis = meth. visibility . print_with_space ( meth. def_id , cx) . to_string ( ) ;
891
- let constness = header. constness . print_with_space ( ) ;
915
+ let constness =
916
+ print_constness_with_space ( & header. constness , meth. const_stability ( cx. tcx ( ) ) ) ;
892
917
let asyncness = header. asyncness . print_with_space ( ) ;
893
918
let unsafety = header. unsafety . print_with_space ( ) ;
894
919
let defaultness = print_default_space ( meth. is_default ( ) ) ;
895
920
let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
921
+
896
922
// NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
897
923
let generics_len = format ! ( "{:#}" , g. print( cx) ) . len ( ) ;
898
924
let mut header_len = "fn " . len ( )
@@ -917,15 +943,15 @@ fn render_assoc_item(
917
943
w. reserve ( header_len + "<a href=\" \" class=\" fnname\" >{" . len ( ) + "</a>" . len ( ) ) ;
918
944
write ! (
919
945
w,
920
- "{}{}{}{}{}{}{ }fn <a href=\" {href}\" class=\" fnname\" >{name}</a>\
946
+ "{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi }fn <a href=\" {href}\" class=\" fnname\" >{name}</a>\
921
947
{generics}{decl}{notable_traits}{where_clause}",
922
- indent_str,
923
- vis,
924
- constness,
925
- asyncness,
926
- unsafety,
927
- defaultness,
928
- abi,
948
+ indent = indent_str,
949
+ vis = vis ,
950
+ constness = constness ,
951
+ asyncness = asyncness ,
952
+ unsafety = unsafety ,
953
+ defaultness = defaultness ,
954
+ abi = abi ,
929
955
href = href,
930
956
name = name,
931
957
generics = g. print( cx) ,
@@ -1583,7 +1609,7 @@ fn render_rightside(
1583
1609
render_stability_since_raw (
1584
1610
w,
1585
1611
item. stable_since ( tcx) . as_deref ( ) ,
1586
- item. const_stable_since ( tcx) . as_deref ( ) ,
1612
+ item. const_stability ( tcx) ,
1587
1613
containing_item. stable_since ( tcx) . as_deref ( ) ,
1588
1614
containing_item. const_stable_since ( tcx) . as_deref ( ) ,
1589
1615
) ;
0 commit comments