@@ -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 ;
@@ -2458,7 +2458,7 @@ fn document_full(w: &mut fmt::Formatter, item: &clean::Item,
2458
2458
2459
2459
fn document_stability ( w : & mut fmt:: Formatter , cx : & Context , item : & clean:: Item ,
2460
2460
is_hidden : bool ) -> fmt:: Result {
2461
- let stabilities = short_stability ( item, cx, true ) ;
2461
+ let stabilities = short_stability ( item, cx) ;
2462
2462
if !stabilities. is_empty ( ) {
2463
2463
write ! ( w, "<div class='stability{}'>" , if is_hidden { " hidden" } else { "" } ) ?;
2464
2464
for stability in stabilities {
@@ -2651,18 +2651,6 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
2651
2651
_ => {
2652
2652
if myitem. name . is_none ( ) { continue }
2653
2653
2654
- let stabilities = short_stability ( myitem, cx, false ) ;
2655
-
2656
- let stab_docs = if !stabilities. is_empty ( ) {
2657
- stabilities. iter ( )
2658
- . map ( |s| format ! ( "[{}]" , s) )
2659
- . collect :: < Vec < _ > > ( )
2660
- . as_slice ( )
2661
- . join ( " " )
2662
- } else {
2663
- String :: new ( )
2664
- } ;
2665
-
2666
2654
let unsafety_flag = match myitem. inner {
2667
2655
clean:: FunctionItem ( ref func) | clean:: ForeignFunctionItem ( ref func)
2668
2656
if func. header . unsafety == hir:: Unsafety :: Unsafe => {
@@ -2683,11 +2671,11 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
2683
2671
<tr class='{stab}{add}module-item'>\
2684
2672
<td><a class=\" {class}\" href=\" {href}\" \
2685
2673
title='{title}'>{name}</a>{unsafety_flag}</td>\
2686
- <td class='docblock-short'>{stab_docs }{docs}\
2674
+ <td class='docblock-short'>{stab_tags }{docs}\
2687
2675
</td>\
2688
2676
</tr>",
2689
2677
name = * myitem. name. as_ref( ) . unwrap( ) ,
2690
- stab_docs = stab_docs ,
2678
+ stab_tags = stability_tags ( myitem ) ,
2691
2679
docs = MarkdownSummaryLine ( doc_value, & myitem. links( ) ) ,
2692
2680
class = myitem. type_( ) ,
2693
2681
add = add,
@@ -2714,101 +2702,123 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
2714
2702
Ok ( ( ) )
2715
2703
}
2716
2704
2717
- fn short_stability ( item : & clean:: Item , cx : & Context , show_reason : bool ) -> Vec < String > {
2705
+ /// Render the stability and deprecation tags that are displayed in the item's summary at the
2706
+ /// module level.
2707
+ fn stability_tags ( item : & clean:: Item ) -> String {
2708
+ let mut tags = String :: new ( ) ;
2709
+
2710
+ // The trailing space after each tag is to space it properly against the rest of the docs.
2711
+ if item. deprecation ( ) . is_some ( ) {
2712
+ tags. push_str ( "[<div class='stab deprecated'>Deprecated</div>] " ) ;
2713
+ }
2714
+
2715
+ if let Some ( stab) = item
2716
+ . stability
2717
+ . as_ref ( )
2718
+ . filter ( |s| s. level == stability:: Unstable )
2719
+ {
2720
+ if stab. feature . as_ref ( ) . map ( |s| & * * s) == Some ( "rustc_private" ) {
2721
+ tags. push_str ( "[<div class='stab internal'>Internal</div>] " ) ;
2722
+ } else {
2723
+ tags. push_str ( "[<div class='stab unstable'>Experimental</div>] " ) ;
2724
+ }
2725
+ }
2726
+
2727
+ if let Some ( ref cfg) = item. attrs . cfg {
2728
+ tags. push_str ( & format ! (
2729
+ "[<div class='stab portability'>{}</div>] " ,
2730
+ cfg. render_short_html( )
2731
+ ) ) ;
2732
+ }
2733
+
2734
+ tags
2735
+ }
2736
+
2737
+ /// Render the stability and/or deprecation warning that is displayed at the top of the item's
2738
+ /// documentation.
2739
+ fn short_stability ( item : & clean:: Item , cx : & Context ) -> Vec < String > {
2718
2740
let mut stability = vec ! [ ] ;
2719
2741
let error_codes = ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ;
2720
2742
2721
- if let Some ( stab) = item. stability . as_ref ( ) {
2722
- let deprecated_reason = if show_reason && !stab. deprecated_reason . is_empty ( ) {
2723
- format ! ( ": {}" , stab. deprecated_reason)
2743
+ if let Some ( Deprecation { since, note } ) = & item. deprecation ( ) {
2744
+ let mut message = if let Some ( since) = since {
2745
+ if stability:: deprecation_in_effect ( since) {
2746
+ format ! ( "Deprecated since {}" , Escape ( since) )
2747
+ } else {
2748
+ format ! ( "Deprecating in {}" , Escape ( since) )
2749
+ }
2724
2750
} else {
2725
- String :: new ( )
2751
+ String :: from ( "Deprecated" )
2726
2752
} ;
2727
- if !stab. deprecated_since . is_empty ( ) {
2728
- let since = if show_reason {
2729
- format ! ( " since {}" , Escape ( & stab. deprecated_since) )
2730
- } else {
2731
- String :: new ( )
2732
- } ;
2753
+
2754
+ if let Some ( note) = note {
2733
2755
let mut ids = cx. id_map . borrow_mut ( ) ;
2734
- let html = MarkdownHtml ( & deprecated_reason, RefCell :: new ( & mut ids) , error_codes) ;
2735
- let text = if stability:: deprecation_in_effect ( & stab. deprecated_since ) {
2736
- format ! ( "Deprecated{}{}" , since, html)
2756
+ let html = MarkdownHtml ( & note, RefCell :: new ( & mut ids) , error_codes) ;
2757
+ message. push_str ( & format ! ( ": {}" , html) ) ;
2758
+ }
2759
+ stability. push ( format ! ( "<div class='stab deprecated'>{}</div>" , message) ) ;
2760
+ }
2761
+
2762
+ if let Some ( stab) = item
2763
+ . stability
2764
+ . as_ref ( )
2765
+ . filter ( |stab| stab. level == stability:: Unstable )
2766
+ {
2767
+ let is_rustc_private = stab. feature . as_ref ( ) . map ( |s| & * * s) == Some ( "rustc_private" ) ;
2768
+
2769
+ let mut message = if is_rustc_private {
2770
+ "<span class='emoji'>⚙️</span> This is an internal compiler API."
2771
+ } else {
2772
+ "<span class='emoji'>🔬</span> This is a nightly-only experimental API."
2773
+ }
2774
+ . to_owned ( ) ;
2775
+
2776
+ if let Some ( feature) = stab. feature . as_ref ( ) {
2777
+ let mut feature = format ! ( "<code>{}</code>" , Escape ( & feature) ) ;
2778
+ if let ( Some ( url) , Some ( issue) ) = ( & cx. shared . issue_tracker_base_url , stab. issue ) {
2779
+ feature. push_str ( & format ! (
2780
+ " <a href=\" {url}{issue}\" >#{issue}</a>" ,
2781
+ url = url,
2782
+ issue = issue
2783
+ ) ) ;
2784
+ }
2785
+
2786
+ message. push_str ( & format ! ( " ({})" , feature) ) ;
2787
+ }
2788
+
2789
+ if let Some ( unstable_reason) = & stab. unstable_reason {
2790
+ // Provide a more informative message than the compiler help.
2791
+ let unstable_reason = if is_rustc_private {
2792
+ "This crate is being loaded from the sysroot, a permanently unstable location \
2793
+ for private compiler dependencies. It is not intended for general use. Prefer \
2794
+ using a public version of this crate from \
2795
+ [crates.io](https://crates.io) via [`Cargo.toml`]\
2796
+ (https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html)."
2737
2797
} else {
2738
- format ! ( "Deprecating in {}{}" , Escape ( & stab . deprecated_since ) , html )
2798
+ unstable_reason
2739
2799
} ;
2740
- stability. push ( format ! ( "<div class='stab deprecated'>{}</div>" , text) )
2741
- } ;
2742
2800
2743
- if stab. level == stability:: Unstable {
2744
- if show_reason {
2745
- let unstable_extra = match ( !stab. feature . is_empty ( ) ,
2746
- & cx. shared . issue_tracker_base_url ,
2747
- stab. issue ) {
2748
- ( true , & Some ( ref tracker_url) , Some ( issue_no) ) if issue_no > 0 =>
2749
- format ! ( " (<code>{} </code><a href=\" {}{}\" >#{}</a>)" ,
2750
- Escape ( & stab. feature) , tracker_url, issue_no, issue_no) ,
2751
- ( false , & Some ( ref tracker_url) , Some ( issue_no) ) if issue_no > 0 =>
2752
- format ! ( " (<a href=\" {}{}\" >#{}</a>)" , Escape ( & tracker_url) , issue_no,
2753
- issue_no) ,
2754
- ( true , ..) =>
2755
- format ! ( " (<code>{}</code>)" , Escape ( & stab. feature) ) ,
2756
- _ => String :: new ( ) ,
2757
- } ;
2758
- if stab. unstable_reason . is_empty ( ) {
2759
- stability. push ( format ! ( "<div class='stab unstable'>\
2760
- <span class=microscope>🔬</span> \
2761
- This is a nightly-only experimental API. {}\
2762
- </div>",
2763
- unstable_extra) ) ;
2764
- } else {
2765
- let mut ids = cx. id_map . borrow_mut ( ) ;
2766
- let text = format ! ( "<summary><span class=microscope>🔬</span> \
2767
- This is a nightly-only experimental API. {}\
2768
- </summary>{}",
2769
- unstable_extra,
2770
- MarkdownHtml (
2771
- & stab. unstable_reason,
2772
- RefCell :: new( & mut ids) ,
2773
- error_codes) ) ;
2774
- stability. push ( format ! ( "<div class='stab unstable'><details>{}</details></div>" ,
2775
- text) ) ;
2776
- }
2777
- } else {
2778
- stability. push ( "<div class='stab unstable'>Experimental</div>" . to_string ( ) )
2779
- }
2780
- } ;
2781
- } else if let Some ( depr) = item. deprecation . as_ref ( ) {
2782
- let note = if show_reason && !depr. note . is_empty ( ) {
2783
- format ! ( ": {}" , depr. note)
2784
- } else {
2785
- String :: new ( )
2786
- } ;
2787
- let since = if show_reason && !depr. since . is_empty ( ) {
2788
- format ! ( " since {}" , Escape ( & depr. since) )
2789
- } else {
2790
- String :: new ( )
2791
- } ;
2801
+ let mut ids = cx. id_map . borrow_mut ( ) ;
2802
+ message = format ! (
2803
+ "<details><summary>{}</summary>{}</details>" ,
2804
+ message,
2805
+ MarkdownHtml ( & unstable_reason, RefCell :: new( & mut ids) , error_codes)
2806
+ ) ;
2807
+ }
2792
2808
2793
- let mut ids = cx. id_map . borrow_mut ( ) ;
2794
- let text = if stability:: deprecation_in_effect ( & depr. since ) {
2795
- format ! ( "Deprecated{}{}" ,
2796
- since,
2797
- MarkdownHtml ( & note, RefCell :: new( & mut ids) , error_codes) )
2809
+ let class = if is_rustc_private {
2810
+ "internal"
2798
2811
} else {
2799
- format ! ( "Deprecating in {}{}" ,
2800
- Escape ( & depr. since) ,
2801
- MarkdownHtml ( & note, RefCell :: new( & mut ids) , error_codes) )
2812
+ "unstable"
2802
2813
} ;
2803
- stability. push ( format ! ( "<div class='stab deprecated '>{}</div>" , text ) )
2814
+ stability. push ( format ! ( "<div class='stab {} '>{}</div>" , class , message ) ) ;
2804
2815
}
2805
2816
2806
2817
if let Some ( ref cfg) = item. attrs . cfg {
2807
- stability. push ( format ! ( "<div class='stab portability'>{}</div>" , if show_reason {
2818
+ stability. push ( format ! (
2819
+ "<div class='stab portability'>{}</div>" ,
2808
2820
cfg. render_long_html( )
2809
- } else {
2810
- cfg. render_short_html( )
2811
- } ) ) ;
2821
+ ) ) ;
2812
2822
}
2813
2823
2814
2824
stability
0 commit comments