@@ -65,7 +65,7 @@ use rustc::hir;
65
65
use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
66
66
use rustc_data_structures:: flock;
67
67
68
- use clean:: { self , AttributesExt , GetDefId , SelfTy , Mutability } ;
68
+ use clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy , Mutability } ;
69
69
use config:: RenderOptions ;
70
70
use doctree;
71
71
use fold:: DocFolder ;
@@ -2449,7 +2449,7 @@ fn document_full(w: &mut fmt::Formatter, item: &clean::Item,
2449
2449
2450
2450
fn document_stability ( w : & mut fmt:: Formatter , cx : & Context , item : & clean:: Item ,
2451
2451
is_hidden : bool ) -> fmt:: Result {
2452
- let stabilities = short_stability ( item, cx, true ) ;
2452
+ let stabilities = short_stability ( item, cx) ;
2453
2453
if !stabilities. is_empty ( ) {
2454
2454
write ! ( w, "<div class='stability{}'>" , if is_hidden { " hidden" } else { "" } ) ?;
2455
2455
for stability in stabilities {
@@ -2642,18 +2642,6 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
2642
2642
_ => {
2643
2643
if myitem. name . is_none ( ) { continue }
2644
2644
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
-
2657
2645
let unsafety_flag = match myitem. inner {
2658
2646
clean:: FunctionItem ( ref func) | clean:: ForeignFunctionItem ( ref func)
2659
2647
if func. header . unsafety == hir:: Unsafety :: Unsafe => {
@@ -2674,11 +2662,11 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
2674
2662
<tr class='{stab}{add}module-item'>\
2675
2663
<td><a class=\" {class}\" href=\" {href}\" \
2676
2664
title='{title}'>{name}</a>{unsafety_flag}</td>\
2677
- <td class='docblock-short'>{stab_docs }{docs}\
2665
+ <td class='docblock-short'>{stab_tags }{docs}\
2678
2666
</td>\
2679
2667
</tr>",
2680
2668
name = * myitem. name. as_ref( ) . unwrap( ) ,
2681
- stab_docs = stab_docs ,
2669
+ stab_tags = stability_tags ( myitem ) ,
2682
2670
docs = MarkdownSummaryLine ( doc_value, & myitem. links( ) ) ,
2683
2671
class = myitem. type_( ) ,
2684
2672
add = add,
@@ -2705,101 +2693,99 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
2705
2693
Ok ( ( ) )
2706
2694
}
2707
2695
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 > {
2709
2728
let mut stability = vec ! [ ] ;
2710
2729
let error_codes = ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ;
2711
2730
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
+ }
2715
2738
} else {
2716
- String :: new ( )
2739
+ String :: from ( "Deprecated" )
2717
2740
} ;
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 {
2724
2743
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
+ }
2733
2749
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
+ ) ) ;
2770
2767
}
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
- } ;
2783
2768
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) )
2795
2782
}
2796
2783
2797
2784
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>" ,
2799
2787
cfg. render_long_html( )
2800
- } else {
2801
- cfg. render_short_html( )
2802
- } ) ) ;
2788
+ ) ) ;
2803
2789
}
2804
2790
2805
2791
stability
0 commit comments