@@ -42,7 +42,7 @@ use std::str;
4242use std:: string:: ToString ;
4343
4444use rustc_ast_pretty:: pprust;
45- use rustc_attr:: { Deprecation , StabilityLevel } ;
45+ use rustc_attr:: { ConstStability , Deprecation , StabilityLevel } ;
4646use rustc_data_structures:: fx:: FxHashSet ;
4747use rustc_hir as hir;
4848use rustc_hir:: def:: CtorKind ;
@@ -61,8 +61,8 @@ use crate::formats::item_type::ItemType;
6161use crate :: formats:: { AssocItemRender , Impl , RenderMode } ;
6262use crate :: html:: escape:: Escape ;
6363use 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 ,
6666} ;
6767use crate :: html:: markdown:: { Markdown , MarkdownHtml , MarkdownSummaryLine } ;
6868
@@ -826,21 +826,45 @@ fn assoc_type(
826826fn render_stability_since_raw (
827827 w : & mut Buffer ,
828828 ver : Option < & str > ,
829- const_ver : Option < & str > ,
829+ const_stability : Option < & ConstStability > ,
830830 containing_ver : Option < & str > ,
831831 containing_const_ver : Option < & str > ,
832832) {
833833 let ver = ver. filter ( |inner| !inner. is_empty ( ) ) ;
834- let const_ver = const_ver. filter ( |inner| !inner. is_empty ( ) ) ;
835834
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+ {
838840 write ! (
839841 w,
840842 "<span class=\" since\" title=\" Stable since Rust version {0}, const since {1}\" >{0} (const: {1})</span>" ,
841- v, cv
843+ v, since
842844 ) ;
843845 }
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
844868 ( Some ( v) , _) if ver != containing_ver => {
845869 write ! (
846870 w,
@@ -888,11 +912,13 @@ fn render_assoc_item(
888912 }
889913 } ;
890914 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 ( ) ) ) ;
892917 let asyncness = header. asyncness . print_with_space ( ) ;
893918 let unsafety = header. unsafety . print_with_space ( ) ;
894919 let defaultness = print_default_space ( meth. is_default ( ) ) ;
895920 let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
921+
896922 // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
897923 let generics_len = format ! ( "{:#}" , g. print( cx) ) . len ( ) ;
898924 let mut header_len = "fn " . len ( )
@@ -917,15 +943,15 @@ fn render_assoc_item(
917943 w. reserve ( header_len + "<a href=\" \" class=\" fnname\" >{" . len ( ) + "</a>" . len ( ) ) ;
918944 write ! (
919945 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>\
921947 {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 ,
929955 href = href,
930956 name = name,
931957 generics = g. print( cx) ,
@@ -1583,7 +1609,7 @@ fn render_rightside(
15831609 render_stability_since_raw (
15841610 w,
15851611 item. stable_since ( tcx) . as_deref ( ) ,
1586- item. const_stable_since ( tcx) . as_deref ( ) ,
1612+ item. const_stability ( tcx) ,
15871613 containing_item. stable_since ( tcx) . as_deref ( ) ,
15881614 containing_item. const_stable_since ( tcx) . as_deref ( ) ,
15891615 ) ;
0 commit comments