about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-07-20 00:11:40 +0000
committerbors <bors@rust-lang.org>2017-07-20 00:11:40 +0000
commit28486e7f908da4adf81e2d0c9af3f2a5002b0a43 (patch)
tree741a3c98b878d8b8c150b7015b81167457ad44be /src/tools
parent582af6e1ad75c12320e7237ff4361a1ed3514124 (diff)
parent94fc09c68f36da4b35f870c9399743102bea393f (diff)
downloadrust-28486e7f908da4adf81e2d0c9af3f2a5002b0a43.tar.gz
rust-28486e7f908da4adf81e2d0c9af3f2a5002b0a43.zip
Auto merge of #43247 - est31:master, r=alexcrichton
Tidy: allow common lang+lib features

This allows changes to the Rust language that have both library
and language components share one feature gate.

The feature gates need to be "about the same change", so that both
library and language components must either be both unstable, or
both stable, and share the tracking issue.

Removes the ugly "proc_macro" exception added by #40939.

Closes #43089
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/tidy/src/features.rs57
1 files changed, 41 insertions, 16 deletions
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs
index 4c94ade98d9..e72f2498969 100644
--- a/src/tools/tidy/src/features.rs
+++ b/src/tools/tidy/src/features.rs
@@ -50,6 +50,34 @@ pub struct Feature {
     pub tracking_issue: Option<u32>,
 }
 
+impl Feature {
+    fn check_match(&self, other: &Feature)-> Result<(), Vec<&'static str>> {
+        let mut mismatches = Vec::new();
+        if self.level != other.level {
+            mismatches.push("stability level");
+        }
+        if self.level == Status::Stable || other.level == Status::Stable {
+            // As long as a feature is unstable, the since field tracks
+            // when the given part of the feature has been implemented.
+            // Mismatches are tolerable as features evolve and functionality
+            // gets added.
+            // Once a feature is stable, the since field tracks the first version
+            // it was part of the stable distribution, and mismatches are disallowed.
+            if self.since != other.since {
+                mismatches.push("since");
+            }
+        }
+        if self.tracking_issue != other.tracking_issue {
+            mismatches.push("tracking issue");
+        }
+        if mismatches.is_empty() {
+            Ok(())
+        } else {
+            Err(mismatches)
+        }
+    }
+}
+
 pub type Features = HashMap<String, Feature>;
 
 pub fn check(path: &Path, bad: &mut bool, quiet: bool) {
@@ -242,23 +270,20 @@ fn get_and_check_lib_features(base_src_path: &Path,
                      &mut |res, file, line| {
             match res {
                 Ok((name, f)) => {
-                    let mut err = |msg: &str| {
-                        tidy_error!(bad, "{}:{}: {}", file.display(), line, msg);
-                    };
-                    if lang_features.contains_key(name) && name != "proc_macro" {
-                        err("duplicating a lang feature");
-                    }
-                    if let Some(ref s) = lib_features.get(name) {
-                        if s.level != f.level {
-                            err("different stability level than before");
-                        }
-                        if s.since != f.since {
-                            err("different `since` than before");
+                    let mut check_features = |f: &Feature, list: &Features, display: &str| {
+                        if let Some(ref s) = list.get(name) {
+                            if let Err(m) = (&f).check_match(s) {
+                                tidy_error!(bad,
+                                            "{}:{}: mismatches to {} in: {:?}",
+                                            file.display(),
+                                            line,
+                                            display,
+                                            &m);
+                            }
                         }
-                        if s.tracking_issue != f.tracking_issue {
-                            err("different `tracking_issue` than before");
-                        }
-                    }
+                    };
+                    check_features(&f, &lang_features, "corresponding lang feature");
+                    check_features(&f, &lib_features, "previous");
                     lib_features.insert(name.to_owned(), f);
                 },
                 Err(msg) => {