@@ -65,7 +65,7 @@ use rustc::hir;
6565use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
6666use rustc_data_structures:: flock;
6767
68- use clean:: { self , AttributesExt , GetDefId , SelfTy , Mutability } ;
68+ use clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy , Mutability } ;
6969use config:: RenderOptions ;
7070use doctree;
7171use fold:: DocFolder ;
@@ -2449,7 +2449,7 @@ fn document_full(w: &mut fmt::Formatter, item: &clean::Item,
24492449
24502450fn document_stability ( w : & mut fmt:: Formatter , cx : & Context , item : & clean:: Item ,
24512451 is_hidden : bool ) -> fmt:: Result {
2452- let stabilities = short_stability ( item, cx, true ) ;
2452+ let stabilities = short_stability ( item, cx) ;
24532453 if !stabilities. is_empty ( ) {
24542454 write ! ( w, "<div class='stability{}'>" , if is_hidden { " hidden" } else { "" } ) ?;
24552455 for stability in stabilities {
@@ -2642,18 +2642,6 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
26422642 _ => {
26432643 if myitem. name . is_none ( ) { continue }
26442644
2645- let stabilities = short_stability ( myitem, cx, false ) ;
2646-
2647- let stab_docs = if !stabilities. is_empty ( ) {
2648- stabilities. iter ( )
2649- . map ( |s| format ! ( "[{}]" , s) )
2650- . collect :: < Vec < _ > > ( )
2651- . as_slice ( )
2652- . join ( " " )
2653- } else {
2654- String :: new ( )
2655- } ;
2656-
26572645 let unsafety_flag = match myitem. inner {
26582646 clean:: FunctionItem ( ref func) | clean:: ForeignFunctionItem ( ref func)
26592647 if func. header . unsafety == hir:: Unsafety :: Unsafe => {
@@ -2674,11 +2662,11 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
26742662 <tr class='{stab}{add}module-item'>\
26752663 <td><a class=\" {class}\" href=\" {href}\" \
26762664 title='{title}'>{name}</a>{unsafety_flag}</td>\
2677- <td class='docblock-short'>{stab_docs }{docs}\
2665+ <td class='docblock-short'>{stab_tags }{docs}\
26782666 </td>\
26792667 </tr>",
26802668 name = * myitem. name. as_ref( ) . unwrap( ) ,
2681- stab_docs = stab_docs ,
2669+ stab_tags = stability_tags ( myitem ) ,
26822670 docs = MarkdownSummaryLine ( doc_value, & myitem. links( ) ) ,
26832671 class = myitem. type_( ) ,
26842672 add = add,
@@ -2705,101 +2693,99 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
27052693 Ok ( ( ) )
27062694}
27072695
2708- fn short_stability ( item : & clean:: Item , cx : & Context , show_reason : bool ) -> Vec < String > {
2696+ /// Render the stability and deprecation tags that are displayed in the item's summary at the
2697+ /// module level.
2698+ fn stability_tags ( item : & clean:: Item ) -> String {
2699+ let mut tags = String :: new ( ) ;
2700+
2701+ // The trailing space after each tag is to space it properly against the rest of the docs.
2702+ if item. deprecation ( ) . is_some ( ) {
2703+ tags. push_str ( "[<div class='stab deprecated'>Deprecated</div>] " ) ;
2704+ }
2705+
2706+ if item
2707+ . stability
2708+ . as_ref ( )
2709+ . filter ( |s| s. level == stability:: Unstable )
2710+ . is_some ( )
2711+ {
2712+ tags. push_str ( "[<div class='stab unstable'>Experimental</div>] " ) ;
2713+ }
2714+
2715+ if let Some ( ref cfg) = item. attrs . cfg {
2716+ tags. push_str ( & format ! (
2717+ "[<div class='stab portability'>{}</div>] " ,
2718+ cfg. render_short_html( )
2719+ ) ) ;
2720+ }
2721+
2722+ tags
2723+ }
2724+
2725+ /// Render the stability and/or deprecation warning that is displayed at the top of the item's
2726+ /// documentation.
2727+ fn short_stability ( item : & clean:: Item , cx : & Context ) -> Vec < String > {
27092728 let mut stability = vec ! [ ] ;
27102729 let error_codes = ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ;
27112730
2712- if let Some ( stab) = item. stability . as_ref ( ) {
2713- let deprecated_reason = if show_reason && !stab. deprecated_reason . is_empty ( ) {
2714- format ! ( ": {}" , stab. deprecated_reason)
2731+ if let Some ( Deprecation { since, note } ) = & item. deprecation ( ) {
2732+ let mut message = if let Some ( since) = since {
2733+ if stability:: deprecation_in_effect ( since) {
2734+ format ! ( "Deprecated since {}" , Escape ( since) )
2735+ } else {
2736+ format ! ( "Deprecating in {}" , Escape ( since) )
2737+ }
27152738 } else {
2716- String :: new ( )
2739+ String :: from ( "Deprecated" )
27172740 } ;
2718- if !stab. deprecated_since . is_empty ( ) {
2719- let since = if show_reason {
2720- format ! ( " since {}" , Escape ( & stab. deprecated_since) )
2721- } else {
2722- String :: new ( )
2723- } ;
2741+
2742+ if let Some ( note) = note {
27242743 let mut ids = cx. id_map . borrow_mut ( ) ;
2725- let html = MarkdownHtml ( & deprecated_reason, RefCell :: new ( & mut ids) , error_codes) ;
2726- let text = if stability:: deprecation_in_effect ( & stab. deprecated_since ) {
2727- format ! ( "Deprecated{}{}" , since, html)
2728- } else {
2729- format ! ( "Deprecating in {}{}" , Escape ( & stab. deprecated_since) , html)
2730- } ;
2731- stability. push ( format ! ( "<div class='stab deprecated'>{}</div>" , text) )
2732- } ;
2744+ let html = MarkdownHtml ( & note, RefCell :: new ( & mut ids) , error_codes) ;
2745+ message. push_str ( & format ! ( ": {}" , html) ) ;
2746+ }
2747+ stability. push ( format ! ( "<div class='stab deprecated'>{}</div>" , message) ) ;
2748+ }
27332749
2734- if stab. level == stability:: Unstable {
2735- if show_reason {
2736- let unstable_extra = match ( !stab. feature . is_empty ( ) ,
2737- & cx. shared . issue_tracker_base_url ,
2738- stab. issue ) {
2739- ( true , & Some ( ref tracker_url) , Some ( issue_no) ) if issue_no > 0 =>
2740- format ! ( " (<code>{} </code><a href=\" {}{}\" >#{}</a>)" ,
2741- Escape ( & stab. feature) , tracker_url, issue_no, issue_no) ,
2742- ( false , & Some ( ref tracker_url) , Some ( issue_no) ) if issue_no > 0 =>
2743- format ! ( " (<a href=\" {}{}\" >#{}</a>)" , Escape ( & tracker_url) , issue_no,
2744- issue_no) ,
2745- ( true , ..) =>
2746- format ! ( " (<code>{}</code>)" , Escape ( & stab. feature) ) ,
2747- _ => String :: new ( ) ,
2748- } ;
2749- if stab. unstable_reason . is_empty ( ) {
2750- stability. push ( format ! ( "<div class='stab unstable'>\
2751- <span class=microscope>🔬</span> \
2752- This is a nightly-only experimental API. {}\
2753- </div>",
2754- unstable_extra) ) ;
2755- } else {
2756- let mut ids = cx. id_map . borrow_mut ( ) ;
2757- let text = format ! ( "<summary><span class=microscope>🔬</span> \
2758- This is a nightly-only experimental API. {}\
2759- </summary>{}",
2760- unstable_extra,
2761- MarkdownHtml (
2762- & stab. unstable_reason,
2763- RefCell :: new( & mut ids) ,
2764- error_codes) ) ;
2765- stability. push ( format ! ( "<div class='stab unstable'><details>{}</details></div>" ,
2766- text) ) ;
2767- }
2768- } else {
2769- stability. push ( "<div class='stab unstable'>Experimental</div>" . to_string ( ) )
2750+ if let Some ( stab) = item
2751+ . stability
2752+ . as_ref ( )
2753+ . filter ( |stab| stab. level == stability:: Unstable )
2754+ {
2755+ let mut message = String :: from (
2756+ "<span class=microscope>🔬</span> This is a nightly-only experimental API." ,
2757+ ) ;
2758+
2759+ if let Some ( feature) = stab. feature . as_ref ( ) {
2760+ let mut feature = format ! ( "<code>{}</code>" , Escape ( & feature) ) ;
2761+ if let ( Some ( url) , Some ( issue) ) = ( & cx. shared . issue_tracker_base_url , stab. issue ) {
2762+ feature. push_str ( & format ! (
2763+ " <a href=\" {url}{issue}\" >#{issue}</a>" ,
2764+ url = url,
2765+ issue = issue
2766+ ) ) ;
27702767 }
2771- } ;
2772- } else if let Some ( depr) = item. deprecation . as_ref ( ) {
2773- let note = if show_reason && !depr. note . is_empty ( ) {
2774- format ! ( ": {}" , depr. note)
2775- } else {
2776- String :: new ( )
2777- } ;
2778- let since = if show_reason && !depr. since . is_empty ( ) {
2779- format ! ( " since {}" , Escape ( & depr. since) )
2780- } else {
2781- String :: new ( )
2782- } ;
27832768
2784- let mut ids = cx. id_map . borrow_mut ( ) ;
2785- let text = if stability:: deprecation_in_effect ( & depr. since ) {
2786- format ! ( "Deprecated{}{}" ,
2787- since,
2788- MarkdownHtml ( & note, RefCell :: new( & mut ids) , error_codes) )
2789- } else {
2790- format ! ( "Deprecating in {}{}" ,
2791- Escape ( & depr. since) ,
2792- MarkdownHtml ( & note, RefCell :: new( & mut ids) , error_codes) )
2793- } ;
2794- stability. push ( format ! ( "<div class='stab deprecated'>{}</div>" , text) )
2769+ message. push_str ( & format ! ( " ({})" , feature) ) ;
2770+ }
2771+
2772+ if let Some ( unstable_reason) = & stab. unstable_reason {
2773+ let mut ids = cx. id_map . borrow_mut ( ) ;
2774+ message = format ! (
2775+ "<details><summary>{}</summary>{}</details>" ,
2776+ message,
2777+ MarkdownHtml ( & unstable_reason, RefCell :: new( & mut ids) , error_codes)
2778+ ) ;
2779+ }
2780+
2781+ stability. push ( format ! ( "<div class='stab unstable'>{}</div>" , message) )
27952782 }
27962783
27972784 if let Some ( ref cfg) = item. attrs . cfg {
2798- stability. push ( format ! ( "<div class='stab portability'>{}</div>" , if show_reason {
2785+ stability. push ( format ! (
2786+ "<div class='stab portability'>{}</div>" ,
27992787 cfg. render_long_html( )
2800- } else {
2801- cfg. render_short_html( )
2802- } ) ) ;
2788+ ) ) ;
28032789 }
28042790
28052791 stability
0 commit comments