From f9bb398cc50d2cad543cd5d2d135db5574ba3a6c Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 16 Feb 2021 10:55:34 -0500 Subject: Fix a few clippy::perf warnings --- crates/ide/src/doc_links.rs | 2 +- crates/ide/src/goto_definition.rs | 2 +- crates/ide/src/references/rename.rs | 6 ++++-- crates/ide/src/view_hir.rs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index f94adec9b..7bdd3cca3 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 e86ae2a18..abed1969e 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 08f16b54d..a4b320227 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 cfcfb7cfb..f8f3fae3d 100644 --- a/crates/ide/src/view_hir.rs +++ b/crates/ide/src/view_hir.rs @@ -11,7 +11,7 @@ use syntax::{algo::find_node_at_offset, ast, AstNode}; // | 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 { -- cgit v1.2.3