]> git.lizzy.rs Git - rust.git/blobdiff - xtask/src/codegen/gen_feature_docs.rs
Specify actions
[rust.git] / xtask / src / codegen / gen_feature_docs.rs
index 58318564872e88cc459e8b73917186b767ec0846..170a3e88942a7304ce0ab2f07981c4663ca02c4d 100644 (file)
@@ -38,11 +38,7 @@ fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> Result<()> {
 
             for block in comment_blocks {
                 let id = block.id;
-                assert!(
-                    id.split_ascii_whitespace().all(|it| it.starts_with(char::is_uppercase)),
-                    "bad feature: {}",
-                    id
-                );
+                assert!(is_valid_feature_name(&id), "invalid feature name: {:?}", id);
                 let doc = block.contents.join("\n");
                 acc.push(Feature { id, path: path.clone(), doc })
             }
@@ -52,6 +48,25 @@ fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> Result<()> {
     }
 }
 
+fn is_valid_feature_name(feature: &str) -> bool {
+    'word: for word in feature.split_whitespace() {
+        for &short in ["to"].iter() {
+            if word == short {
+                continue 'word;
+            }
+        }
+        for &short in ["To"].iter() {
+            if word == short {
+                return false;
+            }
+        }
+        if !word.starts_with(char::is_uppercase) {
+            return false;
+        }
+    }
+    true
+}
+
 impl fmt::Display for Feature {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         writeln!(f, "=== {}", self.id)?;