]> git.lizzy.rs Git - rust.git/commitdiff
Fix feature name
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 5 Oct 2020 18:22:44 +0000 (20:22 +0200)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 5 Oct 2020 18:25:11 +0000 (20:25 +0200)
crates/ide/src/completion/complete_postfix/format_like.rs
xtask/src/codegen/gen_feature_docs.rs

index 0287fc803013297d01fbe2e7c7c001986ca3f30b..81c33bf3afcd130b6e234e120a59bb718e0ecb81 100644 (file)
@@ -1,4 +1,4 @@
-// Feature: Postfix completion for `format`-like strings.
+// Feature: Format String Completion.
 //
 // `"Result {result} is {2 + 2}"` is expanded to the `"Result {} is {}", result, 2 + 2`.
 //
index 3f0013e82ab1556feaaf2d2e7c01df1649f46131..341e67c733996bc3fa29843136c15d36252e355b 100644 (file)
@@ -38,7 +38,9 @@ fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> Result<()> {
 
             for block in comment_blocks {
                 let id = block.id;
-                assert!(is_valid_feature_name(&id), "invalid feature name: {:?}", id);
+                if let Err(msg) = is_valid_feature_name(&id) {
+                    panic!("invalid feature name: {:?}:\n  {}", id, msg)
+                }
                 let doc = block.contents.join("\n");
                 let location = Location::new(path.clone(), block.line);
                 acc.push(Feature { id, location, doc })
@@ -49,7 +51,7 @@ fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> Result<()> {
     }
 }
 
-fn is_valid_feature_name(feature: &str) -> bool {
+fn is_valid_feature_name(feature: &str) -> Result<(), String> {
     'word: for word in feature.split_whitespace() {
         for &short in ["to", "and"].iter() {
             if word == short {
@@ -58,14 +60,14 @@ fn is_valid_feature_name(feature: &str) -> bool {
         }
         for &short in ["To", "And"].iter() {
             if word == short {
-                return false;
+                return Err(format!("Don't capitalize {:?}", word));
             }
         }
         if !word.starts_with(char::is_uppercase) {
-            return false;
+            return Err(format!("Capitalize {:?}", word));
         }
     }
-    true
+    Ok(())
 }
 
 impl fmt::Display for Feature {