Skip to content

Commit 8ad7c04

Browse files
committed
Remove needless clones
1 parent fb95296 commit 8ad7c04

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

crates/hir_def/src/item_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl ItemTree {
148148
let loc = db.lookup_intern_block(block);
149149
let block = loc.ast_id.to_node(db.upcast());
150150
let hygiene = Hygiene::new(db.upcast(), loc.ast_id.file_id);
151-
let ctx = lower::Ctx::new(db, hygiene.clone(), loc.ast_id.file_id);
151+
let ctx = lower::Ctx::new(db, hygiene, loc.ast_id.file_id);
152152
Arc::new(ctx.lower_block(&block))
153153
}
154154

crates/ide/src/highlight_related.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn highlight_references(
7878
token: SyntaxToken,
7979
file_id: FileId,
8080
) -> Option<Vec<HighlightedRange>> {
81-
let defs = find_defs(sema, token.clone());
81+
let defs = find_defs(sema, token);
8282
let usages = defs
8383
.iter()
8484
.filter_map(|&d| {

crates/ide_assists/src/handlers/extract_module.rs

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option<Modul
151151
let mut body_items: Vec<ast::Item> = node
152152
.children()
153153
.filter_map(|child| {
154-
if let Some(item) = ast::Item::cast(child.clone()) {
154+
if let Some(item) = ast::Item::cast(child) {
155155
if selection_range.contains_range(item.syntax().text_range()) {
156156
return Some(item);
157157
}
@@ -312,20 +312,20 @@ impl Module {
312312
get_replacements_for_visibilty_change(self.body_items.clone(), false);
313313

314314
let impl_items = impls.into_iter().fold(Vec::new(), |mut impl_items, x| {
315-
let this_impl_items =
315+
let mut this_impl_items =
316316
x.syntax().descendants().fold(Vec::new(), |mut this_impl_items, x| {
317-
if let Some(item) = ast::Item::cast(x.clone()) {
317+
if let Some(item) = ast::Item::cast(x) {
318318
this_impl_items.push(item);
319319
}
320320
return this_impl_items;
321321
});
322322

323-
impl_items.append(&mut this_impl_items.clone());
323+
impl_items.append(&mut this_impl_items);
324324
return impl_items;
325325
});
326326

327327
let (_, mut impl_item_replacements, _, _) =
328-
get_replacements_for_visibilty_change(impl_items.clone(), true);
328+
get_replacements_for_visibilty_change(impl_items, true);
329329

330330
replacements.append(&mut impl_item_replacements);
331331

@@ -337,7 +337,7 @@ impl Module {
337337
.find(|x| x.to_string() == desc.to_string())
338338
.is_some();
339339
if is_record_field_present {
340-
replacements.push((desc.visibility().clone(), desc.syntax().clone()));
340+
replacements.push((desc.visibility(), desc.syntax().clone()));
341341
}
342342
});
343343
});
@@ -472,7 +472,7 @@ impl Module {
472472
(&x.1).into_iter().for_each(|x| {
473473
let node_opt: Option<ast::Use> = find_node_at_range(file.syntax(), x.range);
474474
if let Some(node) = node_opt {
475-
use_opt = Some(node.clone());
475+
use_opt = Some(node);
476476
}
477477
});
478478
}
@@ -529,7 +529,7 @@ impl Module {
529529
}
530530

531531
if let Some(use_tree_str) = use_tree_str_opt {
532-
let mut use_tree_str = use_tree_str.clone();
532+
let mut use_tree_str = use_tree_str;
533533
use_tree_str.reverse();
534534
if use_tree_str[0].to_string().contains("super") {
535535
let super_path = make::ext::ident_path("super");
@@ -776,42 +776,24 @@ fn get_replacements_for_visibilty_change(
776776
body_items.push(item.clone());
777777
//Use stmts are ignored
778778
match item {
779-
ast::Item::Const(it) => {
780-
replacements.push((it.visibility().clone(), it.syntax().clone()))
781-
}
782-
ast::Item::Enum(it) => {
783-
replacements.push((it.visibility().clone(), it.syntax().clone()))
784-
}
785-
ast::Item::ExternCrate(it) => {
786-
replacements.push((it.visibility().clone(), it.syntax().clone()))
787-
}
788-
ast::Item::Fn(it) => replacements.push((it.visibility().clone(), it.syntax().clone())),
779+
ast::Item::Const(it) => replacements.push((it.visibility(), it.syntax().clone())),
780+
ast::Item::Enum(it) => replacements.push((it.visibility(), it.syntax().clone())),
781+
ast::Item::ExternCrate(it) => replacements.push((it.visibility(), it.syntax().clone())),
782+
ast::Item::Fn(it) => replacements.push((it.visibility(), it.syntax().clone())),
789783
ast::Item::Impl(it) => impls.push(it),
790-
ast::Item::MacroRules(it) => {
791-
replacements.push((it.visibility().clone(), it.syntax().clone()))
792-
}
793-
ast::Item::MacroDef(it) => {
794-
replacements.push((it.visibility().clone(), it.syntax().clone()))
795-
}
796-
ast::Item::Module(it) => {
797-
replacements.push((it.visibility().clone(), it.syntax().clone()))
798-
}
799-
ast::Item::Static(it) => {
800-
replacements.push((it.visibility().clone(), it.syntax().clone()))
801-
}
784+
ast::Item::MacroRules(it) => replacements.push((it.visibility(), it.syntax().clone())),
785+
ast::Item::MacroDef(it) => replacements.push((it.visibility(), it.syntax().clone())),
786+
ast::Item::Module(it) => replacements.push((it.visibility(), it.syntax().clone())),
787+
ast::Item::Static(it) => replacements.push((it.visibility(), it.syntax().clone())),
802788
ast::Item::Struct(it) => {
803-
replacements.push((it.visibility().clone(), it.syntax().clone()));
804-
record_field_parents.push((it.visibility().clone(), it.syntax().clone()));
805-
}
806-
ast::Item::Trait(it) => {
807-
replacements.push((it.visibility().clone(), it.syntax().clone()))
808-
}
809-
ast::Item::TypeAlias(it) => {
810-
replacements.push((it.visibility().clone(), it.syntax().clone()))
789+
replacements.push((it.visibility(), it.syntax().clone()));
790+
record_field_parents.push((it.visibility(), it.syntax().clone()));
811791
}
792+
ast::Item::Trait(it) => replacements.push((it.visibility(), it.syntax().clone())),
793+
ast::Item::TypeAlias(it) => replacements.push((it.visibility(), it.syntax().clone())),
812794
ast::Item::Union(it) => {
813-
replacements.push((it.visibility().clone(), it.syntax().clone()));
814-
record_field_parents.push((it.visibility().clone(), it.syntax().clone()));
795+
replacements.push((it.visibility(), it.syntax().clone()));
796+
record_field_parents.push((it.visibility(), it.syntax().clone()));
815797
}
816798
_ => (),
817799
}
@@ -825,7 +807,7 @@ fn get_use_tree_paths_from_path(
825807
use_tree_str: &mut Vec<ast::Path>,
826808
) -> Option<&mut Vec<ast::Path>> {
827809
path.syntax().ancestors().filter(|x| x.to_string() != path.to_string()).find_map(|x| {
828-
if let Some(use_tree) = ast::UseTree::cast(x.clone()) {
810+
if let Some(use_tree) = ast::UseTree::cast(x) {
829811
if let Some(upper_tree_path) = use_tree.path() {
830812
if upper_tree_path.to_string() != path.to_string() {
831813
use_tree_str.push(upper_tree_path.clone());

0 commit comments

Comments
 (0)