Skip to content

Commit 1c5fa44

Browse files
committed
Auto merge of #16294 - matthiaskrgr:less_alloc, r=Veykril
minor: some minor clippy::perf fixes can be read commit by commit if you want 🤷
2 parents f595e60 + 3fb2cd2 commit 1c5fa44

34 files changed

+62
-73
lines changed

crates/hir-def/src/body/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ impl ExprCollector<'_> {
16101610
|name| self.alloc_expr_desugared(Expr::Path(Path::from(name))),
16111611
|name, span| {
16121612
if let Some(span) = span {
1613-
mappings.push((span, name.clone()))
1613+
mappings.push((span, name))
16141614
}
16151615
},
16161616
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ impl DefCollector<'_> {
13971397
always!(krate == loc.def.krate);
13981398
DefDiagnostic::unresolved_proc_macro(module_id, loc.kind.clone(), loc.def.krate)
13991399
}
1400-
_ => DefDiagnostic::macro_error(module_id, loc.kind.clone(), err.to_string()),
1400+
_ => DefDiagnostic::macro_error(module_id, loc.kind, err.to_string()),
14011401
};
14021402

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

crates/hir-ty/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ fn render_const_scalar(
609609
}
610610
hir_def::AdtId::EnumId(e) => {
611611
let Some((var_id, var_layout)) =
612-
detect_variant_from_bytes(&layout, f.db, trait_env.clone(), b, e)
612+
detect_variant_from_bytes(&layout, f.db, trait_env, b, e)
613613
else {
614614
return f.write_str("<failed-to-detect-variant>");
615615
};

crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl<'a> InferenceContext<'a> {
738738
result.tuple_field_access_types = tuple_field_accesses_rev
739739
.into_iter()
740740
.enumerate()
741-
.map(|(idx, subst)| (TupleId(idx as u32), table.resolve_completely(subst.clone())))
741+
.map(|(idx, subst)| (TupleId(idx as u32), table.resolve_completely(subst)))
742742
.collect();
743743
result
744744
}

crates/hir-ty/src/infer/closure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl HirPlace {
130130
ctx.owner.module(ctx.db.upcast()).krate(),
131131
);
132132
}
133-
ty.clone()
133+
ty
134134
}
135135

136136
fn capture_kind_of_truncated_place(
@@ -245,7 +245,7 @@ pub(crate) struct CapturedItemWithoutTy {
245245

246246
impl CapturedItemWithoutTy {
247247
fn with_ty(self, ctx: &mut InferenceContext<'_>) -> CapturedItem {
248-
let ty = self.place.ty(ctx).clone();
248+
let ty = self.place.ty(ctx);
249249
let ty = match &self.kind {
250250
CaptureKind::ByValue => ty,
251251
CaptureKind::ByRef(bk) => {
@@ -396,7 +396,7 @@ impl InferenceContext<'_> {
396396

397397
fn consume_place(&mut self, place: HirPlace, span: MirSpan) {
398398
if self.is_upvar(&place) {
399-
let ty = place.ty(self).clone();
399+
let ty = place.ty(self);
400400
let kind = if self.is_ty_copy(ty) {
401401
CaptureKind::ByRef(BorrowKind::Shared)
402402
} else {

crates/hir-ty/src/infer/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl InferenceContext<'_> {
978978
.push(callee_ty.clone())
979979
.push(TyBuilder::tuple_with(params.iter().cloned()))
980980
.build();
981-
self.write_method_resolution(tgt_expr, func, subst.clone());
981+
self.write_method_resolution(tgt_expr, func, subst);
982982
}
983983
}
984984

crates/hir-ty/src/infer/pat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ impl InferenceContext<'_> {
233233
};
234234
let mut expectations_iter = expectations
235235
.iter()
236-
.cloned()
237236
.map(|a| a.assert_ty_ref(Interner).clone())
238237
.chain(repeat_with(|| self.table.new_type_var()));
239238

@@ -336,7 +335,7 @@ impl InferenceContext<'_> {
336335
&Pat::Lit(expr) => {
337336
// Don't emit type mismatches again, the expression lowering already did that.
338337
let ty = self.infer_lit_pat(expr, &expected);
339-
self.write_pat_ty(pat, ty.clone());
338+
self.write_pat_ty(pat, ty);
340339
return self.pat_ty_after_adjustment(pat);
341340
}
342341
Pat::Box { inner } => match self.resolve_boxed_box() {

crates/hir-ty/src/layout.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn layout_of_simd_ty(
164164
};
165165

166166
// Compute the ABI of the element type:
167-
let e_ly = db.layout_of_ty(e_ty, env.clone())?;
167+
let e_ly = db.layout_of_ty(e_ty, env)?;
168168
let Abi::Scalar(e_abi) = e_ly.abi else {
169169
return Err(LayoutError::Unknown);
170170
};
@@ -204,17 +204,17 @@ pub fn layout_of_ty_query(
204204
};
205205
let cx = LayoutCx { target: &target };
206206
let dl = &*cx.current_data_layout();
207-
let ty = normalize(db, trait_env.clone(), ty.clone());
207+
let ty = normalize(db, trait_env.clone(), ty);
208208
let result = match ty.kind(Interner) {
209209
TyKind::Adt(AdtId(def), subst) => {
210210
if let hir_def::AdtId::StructId(s) = def {
211211
let data = db.struct_data(*s);
212212
let repr = data.repr.unwrap_or_default();
213213
if repr.simd() {
214-
return layout_of_simd_ty(db, *s, subst, trait_env.clone(), &target);
214+
return layout_of_simd_ty(db, *s, subst, trait_env, &target);
215215
}
216216
};
217-
return db.layout_of_adt(*def, subst.clone(), trait_env.clone());
217+
return db.layout_of_adt(*def, subst.clone(), trait_env);
218218
}
219219
TyKind::Scalar(s) => match s {
220220
chalk_ir::Scalar::Bool => Layout::scalar(
@@ -280,7 +280,7 @@ pub fn layout_of_ty_query(
280280
}
281281
TyKind::Array(element, count) => {
282282
let count = try_const_usize(db, &count).ok_or(LayoutError::HasErrorConst)? as u64;
283-
let element = db.layout_of_ty(element.clone(), trait_env.clone())?;
283+
let element = db.layout_of_ty(element.clone(), trait_env)?;
284284
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
285285

286286
let abi = if count != 0 && matches!(element.abi, Abi::Uninhabited) {
@@ -303,7 +303,7 @@ pub fn layout_of_ty_query(
303303
}
304304
}
305305
TyKind::Slice(element) => {
306-
let element = db.layout_of_ty(element.clone(), trait_env.clone())?;
306+
let element = db.layout_of_ty(element.clone(), trait_env)?;
307307
Layout {
308308
variants: Variants::Single { index: struct_variant_idx() },
309309
fields: FieldsShape::Array { stride: element.size, count: 0 },
@@ -345,7 +345,7 @@ pub fn layout_of_ty_query(
345345
}))
346346
.intern(Interner);
347347
}
348-
unsized_part = normalize(db, trait_env.clone(), unsized_part);
348+
unsized_part = normalize(db, trait_env, unsized_part);
349349
let metadata = match unsized_part.kind(Interner) {
350350
TyKind::Slice(_) | TyKind::Str => {
351351
scalar_unit(dl, Primitive::Int(dl.ptr_sized_integer(), false))
@@ -384,7 +384,7 @@ pub fn layout_of_ty_query(
384384
match impl_trait_id {
385385
crate::ImplTraitId::ReturnTypeImplTrait(func, idx) => {
386386
let infer = db.infer(func.into());
387-
return db.layout_of_ty(infer.type_of_rpit[idx].clone(), trait_env.clone());
387+
return db.layout_of_ty(infer.type_of_rpit[idx].clone(), trait_env);
388388
}
389389
crate::ImplTraitId::AsyncBlockTypeImplTrait(_, _) => {
390390
return Err(LayoutError::NotImplemented)

crates/hir-ty/src/method_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ pub(crate) fn resolve_indexing_op(
13501350
ty: Canonical<Ty>,
13511351
index_trait: TraitId,
13521352
) -> Option<ReceiverAdjustments> {
1353-
let mut table = InferenceTable::new(db, env.clone());
1353+
let mut table = InferenceTable::new(db, env);
13541354
let ty = table.instantiate_canonical(ty);
13551355
let deref_chain = autoderef_method_receiver(&mut table, ty);
13561356
for (ty, adj) in deref_chain {

crates/hir-ty/src/mir/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl MirEvalError {
386386
write!(
387387
f,
388388
"Layout for type `{}` is not available due {err:?}",
389-
ty.display(db).with_closure_style(ClosureStyle::ClosureWithId).to_string()
389+
ty.display(db).with_closure_style(ClosureStyle::ClosureWithId)
390390
)?;
391391
}
392392
MirEvalError::MirLowerError(func, err) => {
@@ -1533,7 +1533,7 @@ impl Evaluator<'_> {
15331533
}
15341534
},
15351535
TyKind::Dyn(_) => {
1536-
let vtable = self.vtable_map.id(current_ty.clone());
1536+
let vtable = self.vtable_map.id(current_ty);
15371537
let mut r = Vec::with_capacity(16);
15381538
let addr = addr.get(self)?;
15391539
r.extend(addr.iter().copied());

0 commit comments

Comments
 (0)