Skip to content

Commit 6674756

Browse files
bors[bot]lnicola
andauthored
Merge #11041
11041: minor: Fix some clippy lints r=lnicola a=lnicola bors r+ Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents 04b0b19 + 6c799da commit 6674756

File tree

12 files changed

+37
-60
lines changed

12 files changed

+37
-60
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/convert_comment_block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> {
9696
let block_prefix =
9797
CommentKind { shape: CommentShape::Block, ..comment.kind() }.prefix();
9898

99-
let output =
100-
format!("{}\n{}\n{}*/", block_prefix, block_comment_body, indentation.to_string());
99+
let output = format!("{}\n{}\n{}*/", block_prefix, block_comment_body, indentation);
101100

102101
edit.replace(target, output)
103102
},

crates/ide_assists/src/handlers/convert_into_to_from.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext) -> Op
9191
builder.replace(src_type.syntax().text_range(), dest_type.to_string());
9292
builder.replace(ast_trait.syntax().text_range(), format!("From<{}>", src_type));
9393
builder.replace(into_fn_return.syntax().text_range(), "-> Self");
94-
builder.replace(
95-
into_fn_params.syntax().text_range(),
96-
format!("(val: {})", src_type.to_string()),
97-
);
94+
builder.replace(into_fn_params.syntax().text_range(), format!("(val: {})", src_type));
9895
builder.replace(into_fn_name.syntax().text_range(), "from");
9996

10097
for s in selfs {

crates/ide_assists/src/handlers/destructure_tuple_binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn edit_tuple_assignment(
174174

175175
// with sub_pattern: keep original tuple and add subpattern: `tup @ (_0, _1)`
176176
if in_sub_pattern {
177-
let text = format!(" @ {}", tuple_pat.to_string());
177+
let text = format!(" @ {}", tuple_pat);
178178
match ctx.config.snippet_cap {
179179
Some(cap) => {
180180
let snip = add_cursor(&text);

crates/ide_assists/src/handlers/extract_module.rs

Lines changed: 24 additions & 42 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
}
@@ -298,7 +298,7 @@ impl Module {
298298
if let Some(name_ref) = ast::NameRef::cast(desc) {
299299
return Some((
300300
name_ref.syntax().text_range(),
301-
format!("{}::{}", self.name, name_ref.to_string()),
301+
format!("{}::{}", self.name, name_ref),
302302
));
303303
}
304304
}
@@ -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());

crates/ide_assists/src/handlers/generate_documentation_template.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ pub(crate) fn generate_documentation_template(
5959
"Generate a documentation template",
6060
text_range,
6161
|builder| {
62-
let mut doc_lines = Vec::new();
6362
// Introduction / short function description before the sections
64-
doc_lines.push(introduction_builder(&ast_func, ctx));
63+
let mut doc_lines = vec![introduction_builder(&ast_func, ctx)];
6564
// Then come the sections
6665
if let Some(mut lines) = examples_builder(&ast_func, ctx) {
6766
doc_lines.push("".into());
@@ -303,7 +302,7 @@ fn arguments_from_params(param_list: &ast::ParamList) -> String {
303302
// instance `TuplePat`) could be managed later.
304303
Some(ast::Pat::IdentPat(ident_pat)) => match ident_pat.name() {
305304
Some(name) => match is_a_ref_mut_param(&param) {
306-
true => format!("&mut {}", name.to_string()),
305+
true => format!("&mut {}", name),
307306
false => name.to_string(),
308307
},
309308
None => "_".to_string(),

crates/ide_assists/src/handlers/qualify_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl QualifyCandidate<'_> {
121121
}
122122
QualifyCandidate::UnqualifiedName(generics) => {
123123
let generics = generics.as_ref().map_or_else(String::new, ToString::to_string);
124-
replacer(format!("{}{}", import.to_string(), generics));
124+
replacer(format!("{}{}", import, generics));
125125
}
126126
QualifyCandidate::TraitAssocItem(qualifier, segment) => {
127127
replacer(format!("<{} as {}>::{}", qualifier, import, segment));

crates/ide_assists/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
431431
buf.push_str("\n\n");
432432
adt.attrs()
433433
.filter(|attr| attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false))
434-
.for_each(|attr| buf.push_str(format!("{}\n", attr.to_string()).as_str()));
434+
.for_each(|attr| buf.push_str(format!("{}\n", attr).as_str()));
435435
buf.push_str("impl");
436436
if let Some(generic_params) = &generic_params {
437437
let lifetimes = generic_params.lifetime_params().map(|lt| format!("{}", lt.syntax()));

crates/ide_completion/src/completions/attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This module uses a bit of static metadata to provide completions
44
//! for built-in attributes.
5-
//! Non-builtin attribute(excluding derives attributes) completions are done in [`super::unqualified_path`].
5+
//! Non-built-in attribute (excluding derives attributes) completions are done in [`super::unqualified_path`].
66
77
use ide_db::{
88
helpers::{

0 commit comments

Comments
 (0)