From 26a1675764c9f96cc96d75d2129dd6c828b8df51 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sat, 12 Dec 2020 12:27:09 -0500 Subject: Remove some redundant allocations --- crates/assists/src/handlers/extract_struct_from_enum_variant.rs | 2 +- crates/assists/src/handlers/qualify_path.rs | 2 +- crates/cfg/src/dnf.rs | 2 +- crates/completion/src/completions/unqualified_path.rs | 2 +- crates/completion/src/render/function.rs | 2 +- crates/project_model/src/workspace.rs | 2 +- crates/rust-analyzer/src/main_loop.rs | 1 - crates/syntax/src/ast/node_ext.rs | 2 +- crates/syntax/src/ast/token_ext.rs | 2 +- xtask/src/codegen/gen_assists_docs.rs | 2 +- 10 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index d85767b4e..2e56bd7ff 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs @@ -212,7 +212,7 @@ fn update_reference( find_node_at_offset::(source_file.syntax(), offset) { // tuple variant - (path_expr.path()?.segment()?, path_expr.syntax().parent()?.clone()) + (path_expr.path()?.segment()?, path_expr.syntax().parent()?) } else if let Some(record_expr) = find_node_at_offset::(source_file.syntax(), offset) { diff --git a/crates/assists/src/handlers/qualify_path.rs b/crates/assists/src/handlers/qualify_path.rs index 6f9810fe8..98cb09214 100644 --- a/crates/assists/src/handlers/qualify_path.rs +++ b/crates/assists/src/handlers/qualify_path.rs @@ -150,7 +150,7 @@ impl QualifyCandidate<'_> { import, trait_method_name, generics, - match arg_list.clone() { + match arg_list { Some(args) => make::arg_list(iter::once(receiver).chain(args)), None => make::arg_list(iter::once(receiver)), } diff --git a/crates/cfg/src/dnf.rs b/crates/cfg/src/dnf.rs index 580c9a9a2..30f4bcdf7 100644 --- a/crates/cfg/src/dnf.rs +++ b/crates/cfg/src/dnf.rs @@ -30,7 +30,7 @@ impl DnfExpr { pub fn new(expr: CfgExpr) -> Self { let builder = Builder { expr: DnfExpr { conjunctions: Vec::new() } }; - builder.lower(expr.clone()) + builder.lower(expr) } /// Computes a list of present or absent atoms in `opts` that cause this expression to evaluate diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 2b0924ae5..b9315f6c0 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -147,7 +147,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() .filter_map(|(import_path, definition)| { render_resolution_with_import( RenderContext::new(ctx), - ImportEdit { import_path: import_path.clone(), import_scope: import_scope.clone() }, + ImportEdit { import_path, import_scope: import_scope.clone() }, &definition, ) }); diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs index d16005249..316e05b52 100644 --- a/crates/completion/src/render/function.rs +++ b/crates/completion/src/render/function.rs @@ -91,7 +91,7 @@ impl<'a> FunctionRender<'a> { .zip(params_ty) .flat_map(|(pat, param_ty)| { let pat = pat?; - let name = pat.to_string(); + let name = pat; let arg = name.trim_start_matches("mut ").trim_start_matches('_'); Some(self.add_arg(arg, param_ty.ty())) }) diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 7f4a7e56b..68a235ce3 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -475,7 +475,7 @@ fn add_target_crate_root( Some(display_name), cfg_options, env, - proc_macro.clone(), + proc_macro, ); crate_id diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index a5f7647b8..ec3d5e060 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -658,7 +658,6 @@ impl GlobalState { log::trace!("updating notifications for {:?}", subscriptions); if self.config.publish_diagnostics { let snapshot = self.snapshot(); - let subscriptions = subscriptions.clone(); self.task_pool.handle.spawn(move || { let diagnostics = subscriptions .into_iter() diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index aa3a4b606..820af2d20 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -55,7 +55,7 @@ impl ast::Attr { let key = self.simple_name()?; let value_token = lit.syntax().first_token()?; - let value: SmolStr = ast::String::cast(value_token.clone())?.value()?.into(); + let value: SmolStr = ast::String::cast(value_token)?.value()?.into(); Some((key, value)) } diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 52b7285dd..5e9620a40 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs @@ -599,7 +599,7 @@ impl ast::IntNumber { text = &text[radix.prefix_len()..]; let buf; - if text.contains("_") { + if text.contains('_') { buf = text.replace('_', ""); text = buf.as_str(); }; diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index d7c85ebe9..be218dea1 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -134,7 +134,7 @@ r#####" buf.push_str(&test) } - let buf = reformat(&buf.to_string())?; + let buf = reformat(&buf)?; codegen::update(&project_root().join("crates/assists/src/tests/generated.rs"), &buf, mode) } -- cgit v1.2.3