about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-22 02:40:04 +0100
committerGitHub <noreply@github.com>2019-12-22 02:40:04 +0100
commiteaeb1138c6e4956a416e161ffc03eaf7db832101 (patch)
tree38ba6a99e4e17147adca35c2543c1adf065a0ead /src/tools
parent877dc9daa8eebee7a6e4dc5fc7df6770a086df59 (diff)
parent62714f8b170dadc381fd9883031d42ba2ee8ece9 (diff)
downloadrust-eaeb1138c6e4956a416e161ffc03eaf7db832101.tar.gz
rust-eaeb1138c6e4956a416e161ffc03eaf7db832101.zip
Rollup merge of #67480 - rossmacarthur:fix-41260-avoid-issue-0-part-2, r=Centril
Require issue = "none" over issue = "0" in unstable attributes

These changes make the use of `issue = "none"` required in unstable attributes throughout the compiler.

Notes:
- #66299 is now in beta so `issue = "none"` is accepted.
- The `tidy` tool now fails on `issue = "0"`.
- Tests that used `issue = "0"` were changed to use `issue = "none"`, except for _one_ that asserts `issue = "0"` can still be used.
- The compiler still allows `issue = "0"` because some submodules require it, this could be disallowed once these are updated.

Resolves #41260

r? @varkor
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/tidy/src/features.rs18
-rw-r--r--src/tools/unstable-book-gen/src/main.rs15
2 files changed, 16 insertions, 17 deletions
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs
index 4ea101296b7..82292a6912c 100644
--- a/src/tools/tidy/src/features.rs
+++ b/src/tools/tidy/src/features.rs
@@ -12,6 +12,7 @@
 use std::collections::HashMap;
 use std::fmt;
 use std::fs;
+use std::num::NonZeroU32;
 use std::path::Path;
 
 use regex::Regex;
@@ -48,7 +49,7 @@ pub struct Feature {
     pub level: Status,
     pub since: Option<Version>,
     pub has_gate_test: bool,
-    pub tracking_issue: Option<u32>,
+    pub tracking_issue: Option<NonZeroU32>,
 }
 
 pub type Features = HashMap<String, Feature>;
@@ -396,6 +397,14 @@ fn map_lib_features(base_src_path: &Path,
             return;
         }
 
+        let handle_issue_none = |s| match s {
+            "none" => None,
+            issue => {
+                let n = issue.parse().expect("issue number is not a valid integer");
+                assert_ne!(n, 0, "\"none\" should be used when there is no issue, not \"0\"");
+                NonZeroU32::new(n)
+            }
+        };
         let mut becoming_feature: Option<(&str, Feature)> = None;
         let mut iter_lines = contents.lines().enumerate().peekable();
         while let Some((i, line)) = iter_lines.next() {
@@ -407,8 +416,7 @@ fn map_lib_features(base_src_path: &Path,
             };
             if let Some((ref name, ref mut f)) = becoming_feature {
                 if f.tracking_issue.is_none() {
-                    f.tracking_issue = find_attr_val(line, "issue")
-                    .map(|s| s.parse().unwrap());
+                    f.tracking_issue = find_attr_val(line, "issue").and_then(handle_issue_none);
                 }
                 if line.ends_with(']') {
                     mf(Ok((name, f.clone())), file, i + 1);
@@ -439,7 +447,7 @@ fn map_lib_features(base_src_path: &Path,
                     // FIXME(#57563): #57563 is now used as a common tracking issue,
                     // although we would like to have specific tracking issues for each
                     // `rustc_const_unstable` in the future.
-                    tracking_issue: Some(57563),
+                    tracking_issue: NonZeroU32::new(57563),
                 };
                 mf(Ok((feature_name, feature)), file, i + 1);
                 continue;
@@ -467,7 +475,7 @@ fn map_lib_features(base_src_path: &Path,
                 }
                 None => None,
             };
-            let tracking_issue = find_attr_val(line, "issue").map(|s| s.parse().unwrap());
+            let tracking_issue = find_attr_val(line, "issue").and_then(handle_issue_none);
 
             let feature = Feature {
                 level,
diff --git a/src/tools/unstable-book-gen/src/main.rs b/src/tools/unstable-book-gen/src/main.rs
index fdb0b6d3e56..39e8d61edeb 100644
--- a/src/tools/unstable-book-gen/src/main.rs
+++ b/src/tools/unstable-book-gen/src/main.rs
@@ -2,7 +2,7 @@
 
 #![deny(warnings)]
 
-use tidy::features::{Feature, Features, collect_lib_features, collect_lang_features};
+use tidy::features::{Features, collect_lib_features, collect_lang_features};
 use tidy::unstable_book::{collect_unstable_feature_names, collect_unstable_book_section_file_names,
                           PATH_STR, LANG_FEATURES_DIR, LIB_FEATURES_DIR};
 use std::collections::BTreeSet;
@@ -70,15 +70,6 @@ fn generate_summary(path: &Path, lang_features: &Features, lib_features: &Featur
 
 }
 
-fn has_valid_tracking_issue(f: &Feature) -> bool {
-    if let Some(n) = f.tracking_issue {
-        if n > 0 {
-            return true;
-        }
-    }
-    false
-}
-
 fn generate_unstable_book_files(src :&Path, out: &Path, features :&Features) {
     let unstable_features = collect_unstable_feature_names(features);
     let unstable_section_file_names = collect_unstable_book_section_file_names(src);
@@ -89,10 +80,10 @@ fn generate_unstable_book_files(src :&Path, out: &Path, features :&Features) {
         let out_file_path = out.join(&file_name);
         let feature = &features[&feature_name_underscore];
 
-        if has_valid_tracking_issue(&feature) {
+        if let Some(issue) = feature.tracking_issue {
             generate_stub_issue(&out_file_path,
                                 &feature_name_underscore,
-                                feature.tracking_issue.unwrap());
+                                issue.get());
         } else {
             generate_stub_no_issue(&out_file_path, &feature_name_underscore);
         }