6142: Fix feature name r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-10-05 18:25:35 +00:00 committed by GitHub
commit aa76ce36e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View 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`. // `"Result {result} is {2 + 2}"` is expanded to the `"Result {} is {}", result, 2 + 2`.
// //

View File

@ -38,7 +38,9 @@ fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> Result<()> {
for block in comment_blocks { for block in comment_blocks {
let id = block.id; 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 doc = block.contents.join("\n");
let location = Location::new(path.clone(), block.line); let location = Location::new(path.clone(), block.line);
acc.push(Feature { id, location, doc }) 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() { 'word: for word in feature.split_whitespace() {
for &short in ["to", "and"].iter() { for &short in ["to", "and"].iter() {
if word == short { if word == short {
@ -58,14 +60,14 @@ fn is_valid_feature_name(feature: &str) -> bool {
} }
for &short in ["To", "And"].iter() { for &short in ["To", "And"].iter() {
if word == short { if word == short {
return false; return Err(format!("Don't capitalize {:?}", word));
} }
} }
if !word.starts_with(char::is_uppercase) { if !word.starts_with(char::is_uppercase) {
return false; return Err(format!("Capitalize {:?}", word));
} }
} }
true Ok(())
} }
impl fmt::Display for Feature { impl fmt::Display for Feature {