about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-03-19 15:51:11 +0000
committervarkor <github@varkor.com>2018-03-26 22:16:10 +0100
commitecaf1f57eaeca759528f1ef99017a7ee4763e307 (patch)
tree7a2b69d41a8e21f54049680090a22879cbf82f0f
parentc08902b084081867ee437d621e605d231d2ba109 (diff)
downloadrust-ecaf1f57eaeca759528f1ef99017a7ee4763e307.tar.gz
rust-ecaf1f57eaeca759528f1ef99017a7ee4763e307.zip
Add future deprecation warning to rustdoc
-rw-r--r--src/librustc/middle/stability.rs48
-rw-r--r--src/librustdoc/html/render.rs22
2 files changed, 43 insertions, 27 deletions
diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs
index 652920f95c3..d1202b59e04 100644
--- a/src/librustc/middle/stability.rs
+++ b/src/librustc/middle/stability.rs
@@ -470,6 +470,30 @@ pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
     tcx.hir.krate().visit_all_item_likes(&mut checker.as_deep_visitor());
 }
 
+/// Check whether an item marked with `deprecated(since="X")` is currently
+/// deprecated (i.e. whether X is not greater than the current rustc version).
+pub fn deprecation_in_effect(since: &str) -> bool {
+    fn parse_version(ver: &str) -> Vec<u32> {
+        // We ignore non-integer components of the version (e.g. "nightly").
+        ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
+    }
+
+    if let Some(rustc) = option_env!("CFG_RELEASE") {
+        let since: Vec<u32> = parse_version(since);
+        let rustc: Vec<u32> = parse_version(rustc);
+        // We simply treat invalid `since` attributes as relating to a previous
+        // Rust version, thus always displaying the warning.
+        if since.len() != 3 {
+            return true;
+        }
+        since <= rustc
+    } else {
+        // By default, a deprecation warning applies to
+        // the current version of the compiler.
+        true
+    }
+}
+
 struct Checker<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
 }
@@ -559,33 +583,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
         // Deprecated attributes apply in-crate and cross-crate.
         if let Some(id) = id {
             if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
-                fn deprecation_in_effect(since: Option<&str>, rustc: Option<&str>) -> bool {
-                    fn parse_version(ver: &str) -> Vec<u32> {
-                        // We ignore non-integer components of the version (e.g. "nightly").
-                        ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
-                    }
-
-                    if since.is_none() || rustc.is_none() {
-                        // By default, a deprecation warning applies to
-                        // the current version of the compiler.
-                        true
-                    } else {
-                        let since: Vec<u32> = parse_version(since.unwrap());
-                        let rustc: Vec<u32> = parse_version(rustc.unwrap());
-                        // We simply treat invalid `since` attributes as relating to a previous
-                        // Rust version, thus always displaying the warning.
-                        if since.len() != 3 {
-                            return true;
-                        }
-                        since <= rustc
-                    }
-                }
-
                 // If the deprecation is scheduled for a future Rust
                 // version, then we should display no warning message.
                 let deprecated_in_future_version = if let Some(sym) = depr_entry.attr.since {
                     let since = sym.as_str();
-                    !deprecation_in_effect(Some(since.as_ref()), option_env!("CFG_RELEASE"))
+                    !deprecation_in_effect(since.as_ref())
                 } else {
                     false
                 };
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 678e1762a55..5c7825f2dd6 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -2108,9 +2108,15 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
             } else {
                 String::new()
             };
-            let text = format!("Deprecated{}{}",
-                               since,
-                               MarkdownHtml(&deprecated_reason));
+            let text = if stability::deprecation_in_effect(&stab.deprecated_since) {
+                format!("Deprecated{}{}",
+                        since,
+                        MarkdownHtml(&deprecated_reason))
+            } else {
+                format!("This will be deprecated in {}{}",
+                        Escape(&stab.deprecated_since),
+                        MarkdownHtml(&deprecated_reason))
+            };
             stability.push(format!("<div class='stab deprecated'>{}</div>", text))
         };
 
@@ -2160,7 +2166,15 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
             String::new()
         };
 
-        let text = format!("Deprecated{}{}", since, MarkdownHtml(&note));
+        let text = if stability::deprecation_in_effect(&depr.since) {
+            format!("Deprecated{}{}",
+                    since,
+                    MarkdownHtml(&note))
+        } else {
+            format!("This will be deprecated in {}{}",
+                    Escape(&depr.since),
+                    MarkdownHtml(&note))
+        };
         stability.push(format!("<div class='stab deprecated'>{}</div>", text))
     }