]> git.lizzy.rs Git - rust.git/commitdiff
Fix a few clippy::perf warnings
authorkjeremy <kjeremy@gmail.com>
Tue, 16 Feb 2021 15:55:34 +0000 (10:55 -0500)
committerkjeremy <kjeremy@gmail.com>
Tue, 16 Feb 2021 15:55:34 +0000 (10:55 -0500)
crates/ide/src/doc_links.rs
crates/ide/src/goto_definition.rs
crates/ide/src/references/rename.rs
crates/ide/src/view_hir.rs
crates/ide_db/src/search.rs
crates/project_model/src/build_data.rs
crates/rust-analyzer/src/config.rs
crates/rust-analyzer/src/to_proto.rs

index f94adec9bb06e9445aa675def3bb0759dc0b2985..7bdd3cca35046e3d3249cc87279042b1b154f7c7 100644 (file)
@@ -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));
                 }
             }
index e86ae2a18856e2624acd98901d2f715e0683a7ae..abed1969e37c524f13f4a4026167fe91ea80d77b 100644 (file)
@@ -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]));
     }
index 08f16b54df2cf8f93f90f39662e82187dec8c056..a4b320227930b7fde51c0cb806b8ec3452ed434a 100644 (file)
@@ -342,8 +342,10 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, 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()
index cfcfb7cfbc00504cae8f8c223df4b462c953f50e..f8f3fae3d081668ac81665b5c2a968a929c12f0c 100644 (file)
@@ -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<String> {
index 38b20f2dc543707d9e171015c524a144ce011295..22dd172f707823970e47fff806fee246e3192ce2 100644 (file)
@@ -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());
 
index a5c564e0a5f580427208deb3f2a09e3ecaef8e6a..295b5f8eff0dc855a9bc0a894bd8eaf3d89cd2d6 100644 (file)
@@ -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<BuildDataResult> {
index f9098968a8277455d973179745a53a9e745498e0..04a77d677b671c789b1bce80ef06f76c600e5743 100644 (file)
@@ -519,7 +519,7 @@ pub fn flycheck(&self) -> Option<FlycheckConfig> {
                     .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<FlycheckConfig> {
                     .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<T: DeserializeOwned>(
 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);
     }
index 8a2b4d9bd992dcc73b9dd07f6f9a6f053de836d5..b0ddb603dbe668e9e12505b638a86b17ee70ce03 100644 (file)
@@ -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(),
             };