aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Krüger <[email protected]>2021-03-21 11:38:21 +0000
committerMatthias Krüger <[email protected]>2021-03-21 11:38:21 +0000
commit8a671168576b9b552a22be285646fc293a80d8c2 (patch)
tree4c2a4f07acfc73de24e9ab1ce16ce7b556c6b6d4
parent3d9b3a8575ef3cb557fd847b941000df3b2db670 (diff)
use strip_prefix() instead of starts_with and slicing (clippy::manual_strip)
-rw-r--r--crates/hir_expand/src/name.rs5
-rw-r--r--crates/syntax/src/ast/edit.rs3
-rw-r--r--xtask/src/codegen/gen_assists_docs.rs4
-rw-r--r--xtask/src/codegen/gen_parser_tests.rs10
4 files changed, 9 insertions, 13 deletions
diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs
index 43de9edd6..0aeea48d5 100644
--- a/crates/hir_expand/src/name.rs
+++ b/crates/hir_expand/src/name.rs
@@ -48,9 +48,8 @@ impl Name {
48 48
49 /// Resolve a name from the text of token. 49 /// Resolve a name from the text of token.
50 fn resolve(raw_text: &str) -> Name { 50 fn resolve(raw_text: &str) -> Name {
51 let raw_start = "r#"; 51 if let Some(text) = raw_text.strip_prefix("r#") {
52 if raw_text.starts_with(raw_start) { 52 Name::new_text(SmolStr::new(text))
53 Name::new_text(SmolStr::new(&raw_text[raw_start.len()..]))
54 } else { 53 } else {
55 Name::new_text(raw_text.into()) 54 Name::new_text(raw_text.into())
56 } 55 }
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs
index 64fac13a7..80be8b79c 100644
--- a/crates/syntax/src/ast/edit.rs
+++ b/crates/syntax/src/ast/edit.rs
@@ -333,8 +333,7 @@ impl ast::Use {
333 .and_then(ast::Whitespace::cast); 333 .and_then(ast::Whitespace::cast);
334 if let Some(next_ws) = next_ws { 334 if let Some(next_ws) = next_ws {
335 let ws_text = next_ws.syntax().text(); 335 let ws_text = next_ws.syntax().text();
336 if ws_text.starts_with('\n') { 336 if let Some(rest) = ws_text.strip_prefix('\n') {
337 let rest = &ws_text[1..];
338 if rest.is_empty() { 337 if rest.is_empty() {
339 res.delete(next_ws.syntax()) 338 res.delete(next_ws.syntax())
340 } else { 339 } else {
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 {
154fn reveal_hash_comments(text: &str) -> String { 154fn reveal_hash_comments(text: &str) -> String {
155 text.split('\n') // want final newline 155 text.split('\n') // want final newline
156 .map(|it| { 156 .map(|it| {
157 if it.starts_with("# ") { 157 if let Some(stripped) = it.strip_prefix("# ") {
158 &it[2..] 158 stripped
159 } else if it == "#" { 159 } else if it == "#" {
160 "" 160 ""
161 } else { 161 } 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<Test> {
60 let mut res = Vec::new(); 60 let mut res = Vec::new();
61 for comment_block in extract_comment_blocks(s) { 61 for comment_block in extract_comment_blocks(s) {
62 let first_line = &comment_block[0]; 62 let first_line = &comment_block[0];
63 let (name, ok) = if first_line.starts_with("test ") { 63 let (name, ok) = if let Some(name) = first_line.strip_prefix("test ") {
64 let name = first_line["test ".len()..].to_string(); 64 (name.to_string(), true)
65 (name, true) 65 } else if let Some(name) = first_line.strip_prefix("test_err ") {
66 } else if first_line.starts_with("test_err ") { 66 (name.to_string(), false)
67 let name = first_line["test_err ".len()..].to_string();
68 (name, false)
69 } else { 67 } else {
70 continue; 68 continue;
71 }; 69 };