From 9772de401efc2f7b45f5929584eb668e3c8c775f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 10 Jan 2021 12:19:00 +0200 Subject: Avoid string copy in complete_attribute --- crates/completion/src/completions/attribute.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/completion/src') diff --git a/crates/completion/src/completions/attribute.rs b/crates/completion/src/completions/attribute.rs index 3a29b5203..a52ca107e 100644 --- a/crates/completion/src/completions/attribute.rs +++ b/crates/completion/src/completions/attribute.rs @@ -21,15 +21,17 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) let attribute = ctx.attribute_under_caret.as_ref()?; match (attribute.path(), attribute.token_tree()) { - (Some(path), Some(token_tree)) => match path.to_string().as_str() { - "derive" => complete_derive(acc, ctx, token_tree), - "feature" => complete_lint(acc, ctx, token_tree, FEATURES), - "allow" | "warn" | "deny" | "forbid" => { + (Some(path), Some(token_tree)) => { + let path = path.syntax().text(); + if path == "derive" { + complete_derive(acc, ctx, token_tree) + } else if path == "feature" { + complete_lint(acc, ctx, token_tree, FEATURES) + } else if path == "allow" || path == "warn" || path == "deny" || path == "forbid" { complete_lint(acc, ctx, token_tree.clone(), DEFAULT_LINT_COMPLETIONS); complete_lint(acc, ctx, token_tree, CLIPPY_LINTS); } - _ => {} - }, + } (_, Some(_token_tree)) => {} _ => complete_attribute_start(acc, ctx, attribute), } -- cgit v1.2.3