about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-06-23 20:30:56 +0000
committerbors <bors@rust-lang.org>2015-06-23 20:30:56 +0000
commit6fed735b22ef66918cf78c3df9a7922df9ed7954 (patch)
treea915622146c74c65f4e1e5d640f654967dfb68ba
parent2ad26e850ed5dfedda8c96d7315aee50145ceedd (diff)
parent2962b2681fd9dd4c91f27c4b061d9a2dc15ced02 (diff)
downloadrust-6fed735b22ef66918cf78c3df9a7922df9ed7954.tar.gz
rust-6fed735b22ef66918cf78c3df9a7922df9ed7954.zip
Auto merge of #26061 - Gankro:inherit-dep, r=brson
Uncertain if this is the desired effect/strategy/testing.

r? @aturon 
-rw-r--r--src/librustc/middle/stability.rs51
-rw-r--r--src/libsyntax/attr.rs6
-rw-r--r--src/test/compile-fail/lint-stability-fields.rs35
-rw-r--r--src/test/compile-fail/lint-stability.rs12
-rw-r--r--src/test/compile-fail/stability-attribute-sanity.rs1
5 files changed, 93 insertions, 12 deletions
diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs
index 3f00d9ba5e9..dad41bdd3a3 100644
--- a/src/librustc/middle/stability.rs
+++ b/src/librustc/middle/stability.rs
@@ -30,6 +30,7 @@ use syntax::feature_gate::emit_feature_err;
 use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
 
 use std::mem::replace;
+use std::cmp::Ordering;
 
 /// A stability index, giving the stability level for items and methods.
 pub struct Index<'tcx> {
@@ -59,9 +60,57 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
         if self.index.staged_api[&ast::LOCAL_CRATE] {
             debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
             match attr::find_stability(self.tcx.sess.diagnostic(), attrs, item_sp) {
-                Some(stab) => {
+                Some(mut stab) => {
                     debug!("annotate: found {:?}", stab);
+                    // if parent is deprecated and we're not, inherit this by merging
+                    // deprecated_since and its reason.
+                    if let Some(parent_stab) = self.parent {
+                        if parent_stab.deprecated_since.is_some()
+                        && stab.deprecated_since.is_none() {
+                            stab.deprecated_since = parent_stab.deprecated_since.clone();
+                            stab.reason = parent_stab.reason.clone();
+                        }
+                    }
+
                     let stab = self.tcx.intern_stability(stab);
+
+                    // Check if deprecated_since < stable_since. If it is,
+                    // this is *almost surely* an accident.
+                    let deprecated_predates_stable = match (stab.deprecated_since.as_ref(),
+                                                            stab.since.as_ref()) {
+                        (Some(dep_since), Some(stab_since)) => {
+                            // explicit version of iter::order::lt to handle parse errors properly
+                            let mut is_less = false;
+                            for (dep_v, stab_v) in dep_since.split(".").zip(stab_since.split(".")) {
+                                match (dep_v.parse::<u64>(), stab_v.parse::<u64>()) {
+                                    (Ok(dep_v), Ok(stab_v)) => match dep_v.cmp(&stab_v) {
+                                        Ordering::Less => {
+                                            is_less = true;
+                                            break;
+                                        }
+                                        Ordering::Equal => { continue; }
+                                        Ordering::Greater => { break; }
+                                    },
+                                    _ => {
+                                        self.tcx.sess.span_err(item_sp,
+                                            "Invalid stability or deprecation version found");
+                                        // act like it isn't less because the question is now
+                                        // nonsensical, and this makes us not do anything else
+                                        // interesting.
+                                        break;
+                                    }
+                                }
+                            }
+                            is_less
+                        },
+                        _ => false,
+                    };
+
+                    if deprecated_predates_stable {
+                        self.tcx.sess.span_err(item_sp,
+                            "An API can't be stabilized after it is deprecated");
+                    }
+
                     self.index.map.insert(local_def(id), Some(stab));
 
                     // Don't inherit #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index aa3ec03ee94..3ee8ffe3636 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -397,7 +397,7 @@ fn find_stability_generic<'a,
                              -> (Option<Stability>, Vec<&'a AM>) {
 
     let mut stab: Option<Stability> = None;
-    let mut deprecated: Option<(InternedString, Option<InternedString>)> = None;
+    let mut deprecated: Option<(Option<InternedString>, Option<InternedString>)> = None;
     let mut used_attrs: Vec<&'a AM> = vec![];
 
     'outer: for attr in attrs {
@@ -484,7 +484,7 @@ fn find_stability_generic<'a,
                 diagnostic.span_err(item_sp, "multiple deprecated attributes");
             }
 
-            deprecated = Some((since.unwrap_or(intern_and_get_ident("bogus")), reason));
+            deprecated = Some((since, reason));
         }
     }
 
@@ -493,7 +493,7 @@ fn find_stability_generic<'a,
         match stab {
             Some(ref mut s) => {
                 let (since, reason) = deprecated.unwrap();
-                s.deprecated_since = Some(since);
+                s.deprecated_since = since;
                 s.reason = reason;
             }
             None => {
diff --git a/src/test/compile-fail/lint-stability-fields.rs b/src/test/compile-fail/lint-stability-fields.rs
index 716d7674b2d..db58f930a02 100644
--- a/src/test/compile-fail/lint-stability-fields.rs
+++ b/src/test/compile-fail/lint-stability-fields.rs
@@ -116,14 +116,20 @@ mod cross_crate {
             //~^ ERROR use of deprecated item
             //~^^ ERROR use of unstable
             override1: 2,
-            override2: 3, //~ ERROR use of unstable
+            //~^ ERROR use of deprecated item
+            override2: 3,
+            //~^ ERROR use of deprecated item
+            //~^^ ERROR use of unstable
         };
 
         let _ = x.inherit;
         //~^ ERROR use of deprecated item
         //~^^ ERROR use of unstable
         let _ = x.override1;
-        let _ = x.override2; //~ ERROR use of unstable
+        //~^ ERROR use of deprecated item
+        let _ = x.override2;
+        //~^ ERROR use of deprecated item
+        //~^^ ERROR use of unstable
 
         let Deprecated {
             //~^ ERROR use of deprecated item
@@ -132,7 +138,10 @@ mod cross_crate {
             //~^ ERROR use of deprecated item
             //~^^ ERROR use of unstable
             override1: _,
-            override2: _ //~ ERROR use of unstable
+            //~^ ERROR use of deprecated item
+            override2: _
+            //~^ ERROR use of unstable
+            //~^^ ERROR use of deprecated item
         } = x;
 
         let Deprecated
@@ -149,7 +158,10 @@ mod cross_crate {
         //~^ ERROR use of deprecated item
         //~^^ ERROR use of unstable
         let _ = x.1;
-        let _ = x.2; //~ ERROR use of unstable
+        //~^ ERROR use of deprecated item
+        let _ = x.2;
+        //~^ ERROR use of deprecated item
+        //~^^ ERROR use of unstable
 
         let Deprecated2
         //~^ ERROR use of deprecated item
@@ -158,7 +170,10 @@ mod cross_crate {
              //~^ ERROR use of deprecated item
              //~^^ ERROR use of unstable
              _,
-             _) //~ ERROR use of unstable
+             //~^ ERROR use of deprecated item
+             _)
+             //~^ ERROR use of deprecated item
+             //~^^ ERROR use of unstable
             = x;
         let Deprecated2
         //~^ ERROR use of deprecated item
@@ -300,20 +315,26 @@ mod this_crate {
             inherit: 1,
             //~^ ERROR use of deprecated item
             override1: 2,
+            //~^ ERROR use of deprecated item
             override2: 3,
+            //~^ ERROR use of deprecated item
         };
 
         let _ = x.inherit;
         //~^ ERROR use of deprecated item
         let _ = x.override1;
+        //~^ ERROR use of deprecated item
         let _ = x.override2;
+        //~^ ERROR use of deprecated item
 
         let Deprecated {
             //~^ ERROR use of deprecated item
             inherit: _,
             //~^ ERROR use of deprecated item
             override1: _,
+            //~^ ERROR use of deprecated item
             override2: _
+            //~^ ERROR use of deprecated item
         } = x;
 
         let Deprecated
@@ -327,14 +348,18 @@ mod this_crate {
         let _ = x.0;
         //~^ ERROR use of deprecated item
         let _ = x.1;
+        //~^ ERROR use of deprecated item
         let _ = x.2;
+        //~^ ERROR use of deprecated item
 
         let Deprecated2
         //~^ ERROR use of deprecated item
             (_,
              //~^ ERROR use of deprecated item
              _,
+             //~^ ERROR use of deprecated item
              _)
+            //~^ ERROR use of deprecated item
             = x;
         let Deprecated2
         //~^ ERROR use of deprecated item
diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs
index 16f195b4ea2..4cba12d7b35 100644
--- a/src/test/compile-fail/lint-stability.rs
+++ b/src/test/compile-fail/lint-stability.rs
@@ -128,8 +128,11 @@ mod cross_crate {
         <Foo as Trait>::trait_stable_text(&foo);
 
         let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
-        let _ = DeprecatedUnstableStruct { i: 0 }; //~ ERROR use of deprecated item
-        //~^ ERROR use of unstable library feature
+        let _ = DeprecatedUnstableStruct {
+            //~^ ERROR use of deprecated item
+            //~^^ ERROR use of unstable library feature
+            i: 0 //~ ERROR use of deprecated item
+        };
         let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable library feature
         let _ = StableStruct { i: 0 };
 
@@ -417,7 +420,10 @@ mod this_crate {
         <Foo>::trait_stable_text(&foo);
         <Foo as Trait>::trait_stable_text(&foo);
 
-        let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
+        let _ = DeprecatedStruct {
+            //~^ ERROR use of deprecated item
+            i: 0 //~ ERROR use of deprecated item
+        };
         let _ = UnstableStruct { i: 0 };
         let _ = StableStruct { i: 0 };
 
diff --git a/src/test/compile-fail/stability-attribute-sanity.rs b/src/test/compile-fail/stability-attribute-sanity.rs
index dcbb1880b10..f0597d57b79 100644
--- a/src/test/compile-fail/stability-attribute-sanity.rs
+++ b/src/test/compile-fail/stability-attribute-sanity.rs
@@ -88,6 +88,7 @@ fn multiple3() { } //~ ERROR multiple stability levels
 #[deprecated(since = "b")]
 #[deprecated(since = "b")]
 fn multiple4() { } //~ ERROR multiple deprecated attributes
+//~^ ERROR Invalid stability or deprecation version found
 
 #[deprecated(since = "a")]
 fn deprecated_without_unstable_or_stable() { } //~ ERROR deprecated attribute must be paired