From 8a671168576b9b552a22be285646fc293a80d8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Mar 2021 12:38:21 +0100 Subject: use strip_prefix() instead of starts_with and slicing (clippy::manual_strip) --- xtask/src/codegen/gen_assists_docs.rs | 4 ++-- xtask/src/codegen/gen_parser_tests.rs | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 158680993..c91716409 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -154,8 +154,8 @@ fn hide_hash_comments(text: &str) -> String { fn reveal_hash_comments(text: &str) -> String { text.split('\n') // want final newline .map(|it| { - if it.starts_with("# ") { - &it[2..] + if let Some(stripped) = it.strip_prefix("# ") { + stripped } else if it == "#" { "" } else { diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index 096590653..2fecb9b5b 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs @@ -60,12 +60,10 @@ fn collect_tests(s: &str) -> Vec { let mut res = Vec::new(); for comment_block in extract_comment_blocks(s) { let first_line = &comment_block[0]; - let (name, ok) = if first_line.starts_with("test ") { - let name = first_line["test ".len()..].to_string(); - (name, true) - } else if first_line.starts_with("test_err ") { - let name = first_line["test_err ".len()..].to_string(); - (name, false) + let (name, ok) = if let Some(name) = first_line.strip_prefix("test ") { + (name.to_string(), true) + } else if let Some(name) = first_line.strip_prefix("test_err ") { + (name.to_string(), false) } else { continue; }; -- cgit v1.2.3