Skip to content

Commit 263b584

Browse files
robertoaloifacebook-github-bot
authored andcommitted
Avoid &String type and un-necessary cloning
Summary: As per title. Suggested in D54633456. Reviewed By: michalmuskala, alanz Differential Revision: D54635043 fbshipit-source-id: 5b4cc1c1e635ec8c71e78ab32955709c2d3554ae
1 parent 44ca9b6 commit 263b584

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

crates/elp/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Config {
210210
.data
211211
.diagnostics_disabled
212212
.iter()
213-
.filter_map(DiagnosticCode::maybe_from_string)
213+
.filter_map(|code| DiagnosticCode::maybe_from_string(&code))
214214
{
215215
config = config.disable(code);
216216
}

crates/ide_db/src/diagnostic_code.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl DiagnosticCode {
176176
format!("{} ({})", self.as_code(), self.as_label())
177177
}
178178

179-
pub fn maybe_from_string(s: &String) -> Option<DiagnosticCode> {
179+
pub fn maybe_from_string(s: &str) -> Option<DiagnosticCode> {
180180
DIAGNOSTIC_CODE_LOOKUPS
181181
.get(s).cloned()
182182
// @fb-only: .or_else(|| MetaOnlyDiagnosticCode::from_str(s).ok().map(DiagnosticCode::MetaOnly))
@@ -255,7 +255,7 @@ lazy_static! {
255255
impl FromStr for DiagnosticCode {
256256
type Err = String;
257257
fn from_str(s: &str) -> Result<Self, Self::Err> {
258-
if let Some(code) = DiagnosticCode::maybe_from_string(&s.to_string()) {
258+
if let Some(code) = DiagnosticCode::maybe_from_string(s) {
259259
Ok(code)
260260
} else {
261261
Err(format!("Unknown DiagnosticCode: '{s}'"))
@@ -290,7 +290,7 @@ mod tests {
290290
let strings = vec!["W0008", "unreachable_test"];
291291
let codes = strings
292292
.iter()
293-
.map(|s| DiagnosticCode::maybe_from_string(&s.to_string()))
293+
.map(|s| DiagnosticCode::maybe_from_string(s))
294294
.collect::<Vec<_>>();
295295
expect![[r#"
296296
[
@@ -313,7 +313,7 @@ mod tests {
313313
];
314314
let codes = strings
315315
.iter()
316-
.map(|s| DiagnosticCode::maybe_from_string(&s.to_string()))
316+
.map(|s| DiagnosticCode::maybe_from_string(s))
317317
.collect::<Vec<_>>();
318318
expect![[r#"
319319
[
@@ -337,7 +337,7 @@ mod tests {
337337
let strings = vec!["C1000", "L1213"];
338338
let codes = strings
339339
.iter()
340-
.map(|s| DiagnosticCode::maybe_from_string(&s.to_string()))
340+
.map(|s| DiagnosticCode::maybe_from_string(s))
341341
.collect::<Vec<_>>();
342342
expect![[r#"
343343
[

crates/ide_db/src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn collect_fixmes(
122122
let comment_range = TextRange::new(pattern_start, pattern_end);
123123
let codes = comment
124124
.split_whitespace()
125-
.filter_map(|word| DiagnosticCode::maybe_from_string(&word.to_string()))
125+
.filter_map(|word| DiagnosticCode::maybe_from_string(word))
126126
.collect();
127127

128128
fixmes.push(Fixme {

0 commit comments

Comments
 (0)