Skip to content

Commit 1d59c7b

Browse files
committed
Remove non-needed clones
I am not certain if this will improve performance, but it seems having a .clone() without any need should be removed. This was done with clippy, and manually reviewed: ``` cargo clippy --fix -- -A clippy::all -D clippy::redundant_clone ```
1 parent a065255 commit 1d59c7b

File tree

21 files changed

+25
-33
lines changed

21 files changed

+25
-33
lines changed

crates/hir-def/src/nameres/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ impl DefCollector<'_> {
13451345
// Missing proc macros are non-fatal, so they are handled specially.
13461346
DefDiagnostic::unresolved_proc_macro(module_id, loc.kind.clone(), loc.def.krate)
13471347
}
1348-
_ => DefDiagnostic::macro_error(module_id, loc.kind.clone(), err.to_string()),
1348+
_ => DefDiagnostic::macro_error(module_id, loc.kind, err.to_string()),
13491349
};
13501350

13511351
self.def_map.diagnostics.push(diag);

crates/hir-ty/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,9 @@ pub fn callable_sig_from_fnonce(
577577
let fn_once =
578578
TyBuilder::trait_ref(db, fn_once_trait).push(self_ty.clone()).push(args.clone()).build();
579579
let projection =
580-
TyBuilder::assoc_type_projection(db, output_assoc_type, Some(fn_once.substitution.clone()))
581-
.build();
580+
TyBuilder::assoc_type_projection(db, output_assoc_type, Some(fn_once.substitution)).build();
582581

583582
let ret_ty = db.normalize_projection(projection, env);
584583

585-
Some(CallableSig::from_params_and_return(params, ret_ty.clone(), false, Safety::Safe))
584+
Some(CallableSig::from_params_and_return(params, ret_ty, false, Safety::Safe))
586585
}

crates/hir-ty/src/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ fn fallback_bound_vars<T: TypeFoldable<Interner> + HasInterner<Interner = Intern
19831983
if bound.index_if_innermost().map_or(true, is_allowed) {
19841984
bound.shifted_in_from(binders).to_const(Interner, ty)
19851985
} else {
1986-
unknown_const(ty.clone())
1986+
unknown_const(ty)
19871987
}
19881988
},
19891989
)

crates/hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ impl<'db> SemanticsImpl<'db> {
847847
}
848848
};
849849
process_expansion_for_token(&mut stack, file_id, None, token.as_ref())
850-
} else if let Some(meta) = ast::Meta::cast(parent.clone()) {
850+
} else if let Some(meta) = ast::Meta::cast(parent) {
851851
// attribute we failed expansion for earlier, this might be a derive invocation
852852
// or derive helper attribute
853853
let attr = meta.parent_attr()?;

crates/hir/src/source_analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl SourceAnalyzer {
118118
fn expr_id(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<ExprId> {
119119
let src = match expr {
120120
ast::Expr::MacroExpr(expr) => {
121-
self.expand_expr(db, InFile::new(self.file_id, expr.macro_call()?.clone()))?
121+
self.expand_expr(db, InFile::new(self.file_id, expr.macro_call()?))?
122122
}
123123
_ => InFile::new(self.file_id, expr.clone()),
124124
};

crates/ide-assists/src/handlers/replace_or_with_or_else.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn into_closure(param: &Expr) -> Expr {
7575
(|| {
7676
if let ast::Expr::CallExpr(call) = param {
7777
if call.arg_list()?.args().count() == 0 {
78-
Some(call.expr()?.clone())
78+
Some(call.expr()?)
7979
} else {
8080
None
8181
}
@@ -151,7 +151,7 @@ fn into_call(param: &Expr) -> Expr {
151151
(|| {
152152
if let ast::Expr::ClosureExpr(closure) = param {
153153
if closure.param_list()?.params().count() == 0 {
154-
Some(closure.body()?.clone())
154+
Some(closure.body()?)
155155
} else {
156156
None
157157
}

crates/ide-completion/src/completions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl Completions {
494494
pattern_ctx,
495495
path_ctx,
496496
variant,
497-
local_name.clone(),
497+
local_name,
498498
None,
499499
));
500500
}

crates/ide-completion/src/completions/postfix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn include_references(initial_element: &ast::Expr) -> (ast::Expr, ast::Expr) {
224224

225225
if let Some(first_ref_expr) = resulting_element.syntax().parent().and_then(ast::RefExpr::cast) {
226226
if let Some(expr) = first_ref_expr.expr() {
227-
resulting_element = expr.clone();
227+
resulting_element = expr;
228228
}
229229

230230
while let Some(parent_ref_element) =
@@ -571,7 +571,7 @@ fn main() { ControlFlow::Break('\\\\') }
571571
);
572572

573573
check_edit_with_config(
574-
config.clone(),
574+
config,
575575
"break",
576576
r#"
577577
//- minicore: try

crates/ide-completion/src/context/analysis.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn analyze(
286286
ast::NameLike::NameRef(name_ref) => {
287287
let parent = name_ref.syntax().parent()?;
288288
let (nameref_ctx, qualifier_ctx) =
289-
classify_name_ref(sema, &original_file, name_ref, parent.clone())?;
289+
classify_name_ref(sema, &original_file, name_ref, parent)?;
290290
qual_ctx = qualifier_ctx;
291291
CompletionAnalysis::NameRef(nameref_ctx)
292292
}
@@ -585,11 +585,7 @@ fn classify_name_ref(
585585
original_file,
586586
&record_field.parent_record_pat(),
587587
),
588-
..pattern_context_for(
589-
sema,
590-
original_file,
591-
record_field.parent_record_pat().clone().into(),
592-
)
588+
..pattern_context_for(sema, original_file, record_field.parent_record_pat().into())
593589
});
594590
return Some(make_res(kind));
595591
}

crates/ide-completion/src/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub(crate) fn render_field(
131131
item.detail(ty.display(ctx.db()).to_string())
132132
.set_documentation(field.docs(ctx.db()))
133133
.set_deprecated(is_deprecated)
134-
.lookup_by(name.clone());
134+
.lookup_by(name);
135135
item.insert_text(field_with_receiver(receiver.as_ref(), &escaped_name));
136136
if let Some(receiver) = &dot_access.receiver {
137137
if let Some(original) = ctx.completion.sema.original_ast_node(receiver.clone()) {

0 commit comments

Comments
 (0)