From: kjeremy Date: Tue, 16 Feb 2021 15:55:34 +0000 (-0500) Subject: Fix a few clippy::perf warnings X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f9bb398cc50d2cad543cd5d2d135db5574ba3a6c;p=rust.git Fix a few clippy::perf warnings --- diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index f94adec9bb0..7bdd3cca350 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -232,7 +232,7 @@ fn rewrite_intra_doc_link( let items = t.items(db); if let Some(field_or_assoc_item) = items.iter().find_map(|assoc_item| { if let Some(name) = assoc_item.name(db) { - if link.to_string() == format!("{}::{}", canonical_path, name) { + if *link == format!("{}::{}", canonical_path, name) { return Some(FieldOrAssocItem::AssocItem(*assoc_item)); } } diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index e86ae2a1885..abed1969e37 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -31,7 +31,7 @@ pub(crate) fn goto_definition( let original_token = pick_best(file.token_at_offset(position.offset))?; let token = sema.descend_into_macros(original_token.clone()); let parent = token.parent(); - if let Some(comment) = ast::Comment::cast(token.clone()) { + if let Some(comment) = ast::Comment::cast(token) { let nav = def_for_doc_comment(&sema, position, &comment)?.try_to_nav(db)?; return Some(RangeInfo::new(original_token.text_range(), vec![nav])); } diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 08f16b54df2..a4b32022793 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs @@ -342,8 +342,10 @@ fn rename_to_self(sema: &Semantics, local: hir::Local) -> RenameRe // FIXME: reimplement this on the hir instead // as of the time of this writing params in hir don't keep their names - let fn_ast = - fn_def.source(sema.db).ok_or(format_err!("Cannot rename non-param local to self"))?.value; + let fn_ast = fn_def + .source(sema.db) + .ok_or_else(|| format_err!("Cannot rename non-param local to self"))? + .value; let first_param_range = fn_ast .param_list() diff --git a/crates/ide/src/view_hir.rs b/crates/ide/src/view_hir.rs index cfcfb7cfbc0..f8f3fae3d08 100644 --- a/crates/ide/src/view_hir.rs +++ b/crates/ide/src/view_hir.rs @@ -11,7 +11,7 @@ // | VS Code | **Rust Analyzer: View Hir** // |=== pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String { - body_hir(db, position).unwrap_or("Not inside a function body".to_string()) + body_hir(db, position).unwrap_or_else(|| "Not inside a function body".to_string()) } fn body_hir(db: &RootDatabase, position: FilePosition) -> Option { diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 38b20f2dc54..22dd172f707 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -345,7 +345,7 @@ fn search(self, sink: &mut dyn FnMut(FileId, FileReference) -> bool) { for (file_id, search_range) in search_scope { let text = sema.db.file_text(file_id); let search_range = - search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str()))); + search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(text.as_str()))); let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); diff --git a/crates/project_model/src/build_data.rs b/crates/project_model/src/build_data.rs index a5c564e0a5f..295b5f8eff0 100644 --- a/crates/project_model/src/build_data.rs +++ b/crates/project_model/src/build_data.rs @@ -61,7 +61,7 @@ pub struct BuildDataResult { impl BuildDataCollector { pub(crate) fn add_config(&mut self, workspace_root: &AbsPath, config: BuildDataConfig) { - self.configs.insert(workspace_root.to_path_buf().clone(), config); + self.configs.insert(workspace_root.to_path_buf(), config); } pub fn collect(&mut self, progress: &dyn Fn(String)) -> Result { diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index f9098968a82..04a77d677b6 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -519,7 +519,7 @@ pub fn flycheck(&self) -> Option { .data .checkOnSave_target .clone() - .or(self.data.cargo_target.clone()), + .or_else(|| self.data.cargo_target.clone()), all_targets: self.data.checkOnSave_allTargets, no_default_features: self .data @@ -533,7 +533,7 @@ pub fn flycheck(&self) -> Option { .data .checkOnSave_features .clone() - .unwrap_or(self.data.cargo_features.clone()), + .unwrap_or_else(|| self.data.cargo_features.clone()), extra_args: self.data.checkOnSave_extraArgs.clone(), }, }; @@ -731,7 +731,7 @@ fn get_field( fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value { for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) { fn key(f: &str) -> &str { - f.splitn(2, "_").next().unwrap() + f.splitn(2, '_').next().unwrap() } assert!(key(f1) <= key(f2), "wrong field order: {:?} {:?}", f1, f2); } diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 8a2b4d9bd99..b0ddb603dbe 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -891,10 +891,10 @@ pub(crate) fn code_lens( let id = lsp_types::TextDocumentIdentifier { uri: url.clone() }; - let doc_pos = lsp_types::TextDocumentPositionParams::new(id.clone(), position); + let doc_pos = lsp_types::TextDocumentPositionParams::new(id, position); let goto_params = lsp_types::request::GotoImplementationParams { - text_document_position_params: doc_pos.clone(), + text_document_position_params: doc_pos, work_done_progress_params: Default::default(), partial_result_params: Default::default(), };