about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurențiu Nicola <lnicola@dend.ro>2021-12-17 17:35:10 +0200
committerLaurențiu Nicola <lnicola@dend.ro>2021-12-17 17:35:10 +0200
commit8ad7c0439cb1d54af7212915c6004be4a49c2f30 (patch)
tree8f69b7aad0c2844f6346b7b9c530b45f61b3172e
parentfb9529626d040de186c5752a9cfdd49d43096bfc (diff)
downloadrust-8ad7c0439cb1d54af7212915c6004be4a49c2f30.tar.gz
rust-8ad7c0439cb1d54af7212915c6004be4a49c2f30.zip
Remove needless clones
-rw-r--r--crates/hir_def/src/item_tree.rs2
-rw-r--r--crates/ide/src/highlight_related.rs2
-rw-r--r--crates/ide_assists/src/handlers/extract_module.rs64
3 files changed, 25 insertions, 43 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index 5e260880ffd..2449e4f3e22 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -148,7 +148,7 @@ impl ItemTree {
         let loc = db.lookup_intern_block(block);
         let block = loc.ast_id.to_node(db.upcast());
         let hygiene = Hygiene::new(db.upcast(), loc.ast_id.file_id);
-        let ctx = lower::Ctx::new(db, hygiene.clone(), loc.ast_id.file_id);
+        let ctx = lower::Ctx::new(db, hygiene, loc.ast_id.file_id);
         Arc::new(ctx.lower_block(&block))
     }
 
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs
index aac23be777f..de6afaef8e5 100644
--- a/crates/ide/src/highlight_related.rs
+++ b/crates/ide/src/highlight_related.rs
@@ -78,7 +78,7 @@ fn highlight_references(
     token: SyntaxToken,
     file_id: FileId,
 ) -> Option<Vec<HighlightedRange>> {
-    let defs = find_defs(sema, token.clone());
+    let defs = find_defs(sema, token);
     let usages = defs
         .iter()
         .filter_map(|&d| {
diff --git a/crates/ide_assists/src/handlers/extract_module.rs b/crates/ide_assists/src/handlers/extract_module.rs
index 80fc7946ce3..d765dcf366d 100644
--- a/crates/ide_assists/src/handlers/extract_module.rs
+++ b/crates/ide_assists/src/handlers/extract_module.rs
@@ -151,7 +151,7 @@ fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option<Modul
     let mut body_items: Vec<ast::Item> = node
         .children()
         .filter_map(|child| {
-            if let Some(item) = ast::Item::cast(child.clone()) {
+            if let Some(item) = ast::Item::cast(child) {
                 if selection_range.contains_range(item.syntax().text_range()) {
                     return Some(item);
                 }
@@ -312,20 +312,20 @@ impl Module {
             get_replacements_for_visibilty_change(self.body_items.clone(), false);
 
         let impl_items = impls.into_iter().fold(Vec::new(), |mut impl_items, x| {
-            let this_impl_items =
+            let mut this_impl_items =
                 x.syntax().descendants().fold(Vec::new(), |mut this_impl_items, x| {
-                    if let Some(item) = ast::Item::cast(x.clone()) {
+                    if let Some(item) = ast::Item::cast(x) {
                         this_impl_items.push(item);
                     }
                     return this_impl_items;
                 });
 
-            impl_items.append(&mut this_impl_items.clone());
+            impl_items.append(&mut this_impl_items);
             return impl_items;
         });
 
         let (_, mut impl_item_replacements, _, _) =
-            get_replacements_for_visibilty_change(impl_items.clone(), true);
+            get_replacements_for_visibilty_change(impl_items, true);
 
         replacements.append(&mut impl_item_replacements);
 
@@ -337,7 +337,7 @@ impl Module {
                     .find(|x| x.to_string() == desc.to_string())
                     .is_some();
                 if is_record_field_present {
-                    replacements.push((desc.visibility().clone(), desc.syntax().clone()));
+                    replacements.push((desc.visibility(), desc.syntax().clone()));
                 }
             });
         });
@@ -472,7 +472,7 @@ impl Module {
                 (&x.1).into_iter().for_each(|x| {
                     let node_opt: Option<ast::Use> = find_node_at_range(file.syntax(), x.range);
                     if let Some(node) = node_opt {
-                        use_opt = Some(node.clone());
+                        use_opt = Some(node);
                     }
                 });
             }
@@ -529,7 +529,7 @@ impl Module {
         }
 
         if let Some(use_tree_str) = use_tree_str_opt {
-            let mut use_tree_str = use_tree_str.clone();
+            let mut use_tree_str = use_tree_str;
             use_tree_str.reverse();
             if use_tree_str[0].to_string().contains("super") {
                 let super_path = make::ext::ident_path("super");
@@ -776,42 +776,24 @@ fn get_replacements_for_visibilty_change(
         body_items.push(item.clone());
         //Use stmts are ignored
         match item {
-            ast::Item::Const(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
-            ast::Item::Enum(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
-            ast::Item::ExternCrate(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
-            ast::Item::Fn(it) => replacements.push((it.visibility().clone(), it.syntax().clone())),
+            ast::Item::Const(it) => replacements.push((it.visibility(), it.syntax().clone())),
+            ast::Item::Enum(it) => replacements.push((it.visibility(), it.syntax().clone())),
+            ast::Item::ExternCrate(it) => replacements.push((it.visibility(), it.syntax().clone())),
+            ast::Item::Fn(it) => replacements.push((it.visibility(), it.syntax().clone())),
             ast::Item::Impl(it) => impls.push(it),
-            ast::Item::MacroRules(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
-            ast::Item::MacroDef(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
-            ast::Item::Module(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
-            ast::Item::Static(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
+            ast::Item::MacroRules(it) => replacements.push((it.visibility(), it.syntax().clone())),
+            ast::Item::MacroDef(it) => replacements.push((it.visibility(), it.syntax().clone())),
+            ast::Item::Module(it) => replacements.push((it.visibility(), it.syntax().clone())),
+            ast::Item::Static(it) => replacements.push((it.visibility(), it.syntax().clone())),
             ast::Item::Struct(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()));
-                record_field_parents.push((it.visibility().clone(), it.syntax().clone()));
-            }
-            ast::Item::Trait(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
-            }
-            ast::Item::TypeAlias(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()))
+                replacements.push((it.visibility(), it.syntax().clone()));
+                record_field_parents.push((it.visibility(), it.syntax().clone()));
             }
+            ast::Item::Trait(it) => replacements.push((it.visibility(), it.syntax().clone())),
+            ast::Item::TypeAlias(it) => replacements.push((it.visibility(), it.syntax().clone())),
             ast::Item::Union(it) => {
-                replacements.push((it.visibility().clone(), it.syntax().clone()));
-                record_field_parents.push((it.visibility().clone(), it.syntax().clone()));
+                replacements.push((it.visibility(), it.syntax().clone()));
+                record_field_parents.push((it.visibility(), it.syntax().clone()));
             }
             _ => (),
         }
@@ -825,7 +807,7 @@ fn get_use_tree_paths_from_path(
     use_tree_str: &mut Vec<ast::Path>,
 ) -> Option<&mut Vec<ast::Path>> {
     path.syntax().ancestors().filter(|x| x.to_string() != path.to_string()).find_map(|x| {
-        if let Some(use_tree) = ast::UseTree::cast(x.clone()) {
+        if let Some(use_tree) = ast::UseTree::cast(x) {
             if let Some(upper_tree_path) = use_tree.path() {
                 if upper_tree_path.to_string() != path.to_string() {
                     use_tree_str.push(upper_tree_path.clone());