aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/ssr.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-18 14:37:34 +0000
committerGitHub <[email protected]>2020-02-18 14:37:34 +0000
commitcecf25b72f2af84fc1535cf52d6f3c1b52802565 (patch)
tree37c8dde0a459caacae6629da08d86be270469ef5 /crates/ra_ide/src/ssr.rs
parenteab80cd961919b9321e1d34343ae3f3adb0502e5 (diff)
parentf6816c253b96e8436f1156d6bd6b0942ee9fb4d3 (diff)
Merge #3220
3220: Fix clippy warnings, update Cargo.toml versions r=matklad a=SomeoneToIgnore In the `cargo xtask lint` ouptut, there were two interesting Clippy warnings that might be interesting to investigate further: * warning: this argument (4 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) * warning: large size difference between variants Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/ssr.rs')
-rw-r--r--crates/ra_ide/src/ssr.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
index 14eb0b8b2..902c29fc6 100644
--- a/crates/ra_ide/src/ssr.rs
+++ b/crates/ra_ide/src/ssr.rs
@@ -85,8 +85,11 @@ impl FromStr for SsrQuery {
85 fn from_str(query: &str) -> Result<SsrQuery, SsrError> { 85 fn from_str(query: &str) -> Result<SsrQuery, SsrError> {
86 let mut it = query.split("==>>"); 86 let mut it = query.split("==>>");
87 let pattern = it.next().expect("at least empty string").trim(); 87 let pattern = it.next().expect("at least empty string").trim();
88 let mut template = 88 let mut template = it
89 it.next().ok_or(SsrError("Cannot find delemiter `==>>`".into()))?.trim().to_string(); 89 .next()
90 .ok_or_else(|| SsrError("Cannot find delemiter `==>>`".into()))?
91 .trim()
92 .to_string();
90 if it.next().is_some() { 93 if it.next().is_some() {
91 return Err(SsrError("More than one delimiter found".into())); 94 return Err(SsrError("More than one delimiter found".into()));
92 } 95 }
@@ -131,11 +134,12 @@ fn traverse(node: &SyntaxNode, go: &mut impl FnMut(&SyntaxNode) -> bool) {
131} 134}
132 135
133fn split_by_var(s: &str) -> Result<(&str, &str, &str), SsrError> { 136fn split_by_var(s: &str) -> Result<(&str, &str, &str), SsrError> {
134 let end_of_name = s.find(":").ok_or(SsrError("Use $<name>:expr".into()))?; 137 let end_of_name = s.find(':').ok_or_else(|| SsrError("Use $<name>:expr".into()))?;
135 let name = &s[0..end_of_name]; 138 let name = &s[0..end_of_name];
136 is_name(name)?; 139 is_name(name)?;
137 let type_begin = end_of_name + 1; 140 let type_begin = end_of_name + 1;
138 let type_length = s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or(s.len()); 141 let type_length =
142 s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or_else(|| s.len());
139 let type_name = &s[type_begin..type_begin + type_length]; 143 let type_name = &s[type_begin..type_begin + type_length];
140 Ok((name, type_name, &s[type_begin + type_length..])) 144 Ok((name, type_name, &s[type_begin + type_length..]))
141} 145}
@@ -182,7 +186,7 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches {
182 pattern.text() == code.text() 186 pattern.text() == code.text()
183 } 187 }
184 (SyntaxElement::Node(ref pattern), SyntaxElement::Node(ref code)) => { 188 (SyntaxElement::Node(ref pattern), SyntaxElement::Node(ref code)) => {
185 if placeholders.iter().find(|&n| n.0.as_str() == pattern.text()).is_some() { 189 if placeholders.iter().any(|n| n.0.as_str() == pattern.text()) {
186 match_.binding.insert(Var(pattern.text().to_string()), code.clone()); 190 match_.binding.insert(Var(pattern.text().to_string()), code.clone());
187 true 191 true
188 } else { 192 } else {