Skip to content

Commit c45126e

Browse files
authored
Merge pull request #19727 from matthiaskrgr/enolc
remove a couple of clones
2 parents 00d2f60 + 3e196c0 commit c45126e

File tree

32 files changed

+71
-90
lines changed

32 files changed

+71
-90
lines changed

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl GenericParamsCollector {
270270
let self_ = Name::new_symbol_root(sym::Self_);
271271
let idx = self.type_or_consts.alloc(
272272
TypeParamData {
273-
name: Some(self_.clone()),
273+
name: Some(self_),
274274
default: None,
275275
provenance: TypeParamProvenance::TraitSelf,
276276
}

src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl Attr {
320320
) -> impl IntoIterator<Item = Self> {
321321
let is_cfg_attr = self.path.as_ident().is_some_and(|name| *name == sym::cfg_attr);
322322
if !is_cfg_attr {
323-
return smallvec![self.clone()];
323+
return smallvec![self];
324324
}
325325

326326
let subtree = match self.token_tree_value() {

src/tools/rust-analyzer/crates/hir-ty/src/dyn_compatibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ fn receiver_is_dispatchable(
515515
trait_id: to_chalk_trait_id(trait_),
516516
substitution: Substitution::from_iter(
517517
Interner,
518-
std::iter::once(unsized_self_ty.clone().cast(Interner))
518+
std::iter::once(unsized_self_ty.cast(Interner))
519519
.chain(placeholder_subst.iter(Interner).skip(1).cloned()),
520520
),
521521
});

src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl InferenceContext<'_> {
127127
let prev_diverges = mem::replace(&mut self.diverges, Diverges::Maybe);
128128
let prev_closure = mem::replace(&mut self.current_closure, id);
129129
let prev_ret_ty = mem::replace(&mut self.return_ty, body_ret_ty.clone());
130-
let prev_ret_coercion = self.return_coercion.replace(CoerceMany::new(body_ret_ty.clone()));
130+
let prev_ret_coercion = self.return_coercion.replace(CoerceMany::new(body_ret_ty));
131131
let prev_resume_yield_tys = mem::replace(&mut self.resume_yield_tys, resume_yield_tys);
132132

133133
self.with_breakable_ctx(BreakableKind::Border, None, None, |this| {

src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,9 @@ impl InferenceContext<'_> {
827827
}
828828
let assoc = self.resolve_ops_index_output();
829829
self.resolve_associated_type_with_params(
830-
self_ty.clone(),
830+
self_ty,
831831
assoc,
832-
&[index_ty.clone().cast(Interner)],
832+
&[index_ty.cast(Interner)],
833833
)
834834
} else {
835835
self.err_ty()

src/tools/rust-analyzer/crates/hir-ty/src/infer/pat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl InferenceContext<'_> {
435435
decl: Option<DeclContext>,
436436
) -> Ty {
437437
let (expectation_type, expectation_lt) = match expected.as_reference() {
438-
Some((inner_ty, lifetime, _exp_mut)) => (inner_ty.clone(), lifetime.clone()),
438+
Some((inner_ty, lifetime, _exp_mut)) => (inner_ty.clone(), lifetime),
439439
None => {
440440
let inner_ty = self.table.new_type_var();
441441
let inner_lt = self.table.new_lifetime_var();
@@ -597,7 +597,7 @@ impl InferenceContext<'_> {
597597
let size = consteval::usize_const(self.db, Some(len as u128), self.owner.krate(self.db));
598598

599599
let elem_ty = self.table.new_type_var();
600-
let array_ty = TyKind::Array(elem_ty.clone(), size).intern(Interner);
600+
let array_ty = TyKind::Array(elem_ty, size).intern(Interner);
601601
Some(array_ty)
602602
}
603603

src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ impl<'a> InferenceTable<'a> {
10291029
};
10301030
let sized_pred = WhereClause::Implemented(TraitRef {
10311031
trait_id: to_chalk_trait_id(sized),
1032-
substitution: Substitution::from1(Interner, ty.clone()),
1032+
substitution: Substitution::from1(Interner, ty),
10331033
});
10341034
let goal = GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(sized_pred)).intern(Interner);
10351035
matches!(self.try_obligation(goal), Some(Solution::Unique(_)))

src/tools/rust-analyzer/crates/hir/src/lib.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,24 +3685,16 @@ impl GenericDef {
36853685
}
36863686

36873687
let source_map = match def {
3688-
GenericDefId::AdtId(AdtId::EnumId(it)) => {
3689-
db.enum_signature_with_source_map(it).1.clone()
3690-
}
3691-
GenericDefId::AdtId(AdtId::StructId(it)) => {
3692-
db.struct_signature_with_source_map(it).1.clone()
3693-
}
3694-
GenericDefId::AdtId(AdtId::UnionId(it)) => {
3695-
db.union_signature_with_source_map(it).1.clone()
3696-
}
3688+
GenericDefId::AdtId(AdtId::EnumId(it)) => db.enum_signature_with_source_map(it).1,
3689+
GenericDefId::AdtId(AdtId::StructId(it)) => db.struct_signature_with_source_map(it).1,
3690+
GenericDefId::AdtId(AdtId::UnionId(it)) => db.union_signature_with_source_map(it).1,
36973691
GenericDefId::ConstId(_) => return,
3698-
GenericDefId::FunctionId(it) => db.function_signature_with_source_map(it).1.clone(),
3699-
GenericDefId::ImplId(it) => db.impl_signature_with_source_map(it).1.clone(),
3692+
GenericDefId::FunctionId(it) => db.function_signature_with_source_map(it).1,
3693+
GenericDefId::ImplId(it) => db.impl_signature_with_source_map(it).1,
37003694
GenericDefId::StaticId(_) => return,
3701-
GenericDefId::TraitAliasId(it) => {
3702-
db.trait_alias_signature_with_source_map(it).1.clone()
3703-
}
3704-
GenericDefId::TraitId(it) => db.trait_signature_with_source_map(it).1.clone(),
3705-
GenericDefId::TypeAliasId(it) => db.type_alias_signature_with_source_map(it).1.clone(),
3695+
GenericDefId::TraitAliasId(it) => db.trait_alias_signature_with_source_map(it).1,
3696+
GenericDefId::TraitId(it) => db.trait_signature_with_source_map(it).1,
3697+
GenericDefId::TypeAliasId(it) => db.type_alias_signature_with_source_map(it).1,
37063698
};
37073699

37083700
expr_store_diagnostics(db, acc, &source_map);
@@ -3802,7 +3794,7 @@ impl GenericSubstitution {
38023794
container_params
38033795
.chain(self_params)
38043796
.filter_map(|(ty, name)| {
3805-
Some((name?.symbol().clone(), Type { ty: ty.clone(), env: self.env.clone() }))
3797+
Some((name?.symbol().clone(), Type { ty, env: self.env.clone() }))
38063798
})
38073799
.collect()
38083800
}

src/tools/rust-analyzer/crates/hir/src/semantics.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ impl<'db> SemanticsImpl<'db> {
926926
token: InRealFile<SyntaxToken>,
927927
mut cb: impl FnMut(InFile<SyntaxToken>, SyntaxContext) -> ControlFlow<T>,
928928
) -> Option<T> {
929-
self.descend_into_macros_impl(token.clone(), &mut cb)
929+
self.descend_into_macros_impl(token, &mut cb)
930930
}
931931

932932
/// Descends the token into expansions, returning the tokens that matches the input
@@ -958,17 +958,13 @@ impl<'db> SemanticsImpl<'db> {
958958
let text = token.text();
959959
let kind = token.kind();
960960
if let Ok(token) = self.wrap_token_infile(token.clone()).into_real_file() {
961-
self.descend_into_macros_breakable(
962-
token.clone(),
963-
|InFile { value, file_id: _ }, _ctx| {
964-
let mapped_kind = value.kind();
965-
let any_ident_match =
966-
|| kind.is_any_identifier() && value.kind().is_any_identifier();
967-
let matches =
968-
(kind == mapped_kind || any_ident_match()) && text == value.text();
969-
if matches { ControlFlow::Break(value) } else { ControlFlow::Continue(()) }
970-
},
971-
)
961+
self.descend_into_macros_breakable(token, |InFile { value, file_id: _ }, _ctx| {
962+
let mapped_kind = value.kind();
963+
let any_ident_match =
964+
|| kind.is_any_identifier() && value.kind().is_any_identifier();
965+
let matches = (kind == mapped_kind || any_ident_match()) && text == value.text();
966+
if matches { ControlFlow::Break(value) } else { ControlFlow::Continue(()) }
967+
})
972968
} else {
973969
None
974970
}

src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl SourceToDefCtx<'_, '_> {
559559
let item = match ast::Item::cast(value.clone()) {
560560
Some(it) => it,
561561
None => {
562-
let variant = ast::Variant::cast(value.clone())?;
562+
let variant = ast::Variant::cast(value)?;
563563
return this
564564
.enum_variant_to_def(InFile::new(file_id, &variant))
565565
.map(Into::into);

0 commit comments

Comments
 (0)