Remove needless clones

This commit is contained in:
Laurențiu Nicola 2021-12-17 17:35:10 +02:00
parent fb9529626d
commit 8ad7c0439c
3 changed files with 25 additions and 43 deletions

View File

@ -148,7 +148,7 @@ impl ItemTree {
let loc = db.lookup_intern_block(block); let loc = db.lookup_intern_block(block);
let block = loc.ast_id.to_node(db.upcast()); let block = loc.ast_id.to_node(db.upcast());
let hygiene = Hygiene::new(db.upcast(), loc.ast_id.file_id); 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)) Arc::new(ctx.lower_block(&block))
} }

View File

@ -78,7 +78,7 @@ fn highlight_references(
token: SyntaxToken, token: SyntaxToken,
file_id: FileId, file_id: FileId,
) -> Option<Vec<HighlightedRange>> { ) -> Option<Vec<HighlightedRange>> {
let defs = find_defs(sema, token.clone()); let defs = find_defs(sema, token);
let usages = defs let usages = defs
.iter() .iter()
.filter_map(|&d| { .filter_map(|&d| {

View File

@ -151,7 +151,7 @@ fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option<Modul
let mut body_items: Vec<ast::Item> = node let mut body_items: Vec<ast::Item> = node
.children() .children()
.filter_map(|child| { .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()) { if selection_range.contains_range(item.syntax().text_range()) {
return Some(item); return Some(item);
} }
@ -312,20 +312,20 @@ impl Module {
get_replacements_for_visibilty_change(self.body_items.clone(), false); get_replacements_for_visibilty_change(self.body_items.clone(), false);
let impl_items = impls.into_iter().fold(Vec::new(), |mut impl_items, x| { 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| { 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); this_impl_items.push(item);
} }
return this_impl_items; return this_impl_items;
}); });
impl_items.append(&mut this_impl_items.clone()); impl_items.append(&mut this_impl_items);
return impl_items; return impl_items;
}); });
let (_, mut impl_item_replacements, _, _) = 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); replacements.append(&mut impl_item_replacements);
@ -337,7 +337,7 @@ impl Module {
.find(|x| x.to_string() == desc.to_string()) .find(|x| x.to_string() == desc.to_string())
.is_some(); .is_some();
if is_record_field_present { 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| { (&x.1).into_iter().for_each(|x| {
let node_opt: Option<ast::Use> = find_node_at_range(file.syntax(), x.range); let node_opt: Option<ast::Use> = find_node_at_range(file.syntax(), x.range);
if let Some(node) = node_opt { 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 { 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(); use_tree_str.reverse();
if use_tree_str[0].to_string().contains("super") { if use_tree_str[0].to_string().contains("super") {
let super_path = make::ext::ident_path("super"); let super_path = make::ext::ident_path("super");
@ -776,42 +776,24 @@ fn get_replacements_for_visibilty_change(
body_items.push(item.clone()); body_items.push(item.clone());
//Use stmts are ignored //Use stmts are ignored
match item { match item {
ast::Item::Const(it) => { ast::Item::Const(it) => replacements.push((it.visibility(), it.syntax().clone())),
replacements.push((it.visibility().clone(), 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::Enum(it) => { ast::Item::Fn(it) => replacements.push((it.visibility(), it.syntax().clone())),
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::Impl(it) => impls.push(it), ast::Item::Impl(it) => impls.push(it),
ast::Item::MacroRules(it) => { ast::Item::MacroRules(it) => replacements.push((it.visibility(), it.syntax().clone())),
replacements.push((it.visibility().clone(), 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::MacroDef(it) => { ast::Item::Static(it) => replacements.push((it.visibility(), it.syntax().clone())),
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::Struct(it) => { ast::Item::Struct(it) => {
replacements.push((it.visibility().clone(), it.syntax().clone())); replacements.push((it.visibility(), it.syntax().clone()));
record_field_parents.push((it.visibility().clone(), it.syntax().clone())); record_field_parents.push((it.visibility(), 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()))
} }
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) => { ast::Item::Union(it) => {
replacements.push((it.visibility().clone(), it.syntax().clone())); replacements.push((it.visibility(), it.syntax().clone()));
record_field_parents.push((it.visibility().clone(), 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>, use_tree_str: &mut Vec<ast::Path>,
) -> Option<&mut Vec<ast::Path>> { ) -> Option<&mut Vec<ast::Path>> {
path.syntax().ancestors().filter(|x| x.to_string() != path.to_string()).find_map(|x| { 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 let Some(upper_tree_path) = use_tree.path() {
if upper_tree_path.to_string() != path.to_string() { if upper_tree_path.to_string() != path.to_string() {
use_tree_str.push(upper_tree_path.clone()); use_tree_str.push(upper_tree_path.clone());