Skip to content

Commit 3837df2

Browse files
committed
don't clone types that are copy (clippy::clone_on_copy)
1 parent 139c646 commit 3837df2

File tree

25 files changed

+99
-111
lines changed

25 files changed

+99
-111
lines changed

src/librustc_builtin_macros/deriving/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
6363
let span = cx.with_def_site_ctxt(span);
6464
let name = cx.expr_lit(span, ast::LitKind::Str(ident.name, ast::StrStyle::Cooked));
6565
let builder = cx.ident_of("debug_trait_builder", span);
66-
let builder_expr = cx.expr_ident(span, builder.clone());
66+
let builder_expr = cx.expr_ident(span, builder);
6767

6868
let fmt = substr.nonself_args[0].clone();
6969

src/librustc_errors/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ fn emit_to_destination(
20052005
let _buffer_lock = lock::acquire_global_lock("rustc_errors");
20062006
for (pos, line) in rendered_buffer.iter().enumerate() {
20072007
for part in line {
2008-
dst.apply_style(lvl.clone(), part.style)?;
2008+
dst.apply_style(*lvl, part.style)?;
20092009
write!(dst, "{}", part.text)?;
20102010
dst.reset()?;
20112011
}

src/librustc_infer/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
871871
return Some(());
872872
}
873873
if let &ty::Adt(def, _) = &ta.kind {
874-
let path_ = self.tcx.def_path_str(def.did.clone());
874+
let path_ = self.tcx.def_path_str(def.did);
875875
if path_ == other_path {
876876
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
877877
return Some(());
@@ -1091,8 +1091,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10911091
let sub_no_defaults_1 = self.strip_generic_default_params(def1.did, sub1);
10921092
let sub_no_defaults_2 = self.strip_generic_default_params(def2.did, sub2);
10931093
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1094-
let path1 = self.tcx.def_path_str(def1.did.clone());
1095-
let path2 = self.tcx.def_path_str(def2.did.clone());
1094+
let path1 = self.tcx.def_path_str(def1.did);
1095+
let path2 = self.tcx.def_path_str(def2.did);
10961096
if def1.did == def2.did {
10971097
// Easy case. Replace same types with `_` to shorten the output and highlight
10981098
// the differing ones.

src/librustc_infer/infer/outlives/obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ where
452452
// even though a satisfactory solution exists.
453453
let generic = GenericKind::Projection(projection_ty);
454454
let verify_bound = self.verify_bound.generic_bound(generic);
455-
self.delegate.push_verify(origin, generic.clone(), region, verify_bound);
455+
self.delegate.push_verify(origin, generic, region, verify_bound);
456456
}
457457
}
458458

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10561056
place: {:?}",
10571057
place_span.0
10581058
);
1059-
this.reservation_error_reported.insert(place_span.0.clone());
1059+
this.reservation_error_reported.insert(place_span.0);
10601060
}
10611061
Activation(_, activating) => {
10621062
debug!(

src/librustc_mir/dataflow/move_paths/builder.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
286286
// Box starts out uninitialized - need to create a separate
287287
// move-path for the interior so it will be separate from
288288
// the exterior.
289-
self.create_move_path(self.builder.tcx.mk_place_deref(place.clone()));
289+
self.create_move_path(self.builder.tcx.mk_place_deref(*place));
290290
self.gather_init(place.as_ref(), InitKind::Shallow);
291291
} else {
292292
self.gather_init(place.as_ref(), InitKind::Deep);
@@ -458,9 +458,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
458458
for offset in from..to {
459459
let elem =
460460
ProjectionElem::ConstantIndex { offset, min_length: len, from_end: false };
461-
let path = self.add_move_path(base_path, &elem, |tcx| {
462-
tcx.mk_place_elem(base_place.clone(), elem)
463-
});
461+
let path =
462+
self.add_move_path(base_path, &elem, |tcx| tcx.mk_place_elem(base_place, elem));
464463
self.record_move(place, path);
465464
}
466465
} else {

src/librustc_mir/monomorphize/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn collect_items_rec<'tcx>(
335335
recursion_depths: &mut DefIdMap<usize>,
336336
inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>,
337337
) {
338-
if !visited.lock_mut().insert(starting_point.clone()) {
338+
if !visited.lock_mut().insert(starting_point) {
339339
// We've been here already, no need to search again.
340340
return;
341341
}

src/librustc_mir/shim.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl CloneShimBuilder<'tcx> {
538538
// BB #2
539539
// `dest[i] = Clone::clone(src[beg])`;
540540
// Goto #3 if ok, #5 if unwinding happens.
541-
let dest_field = self.tcx.mk_place_index(dest.clone(), beg);
541+
let dest_field = self.tcx.mk_place_index(dest, beg);
542542
let src_field = self.tcx.mk_place_index(src, beg);
543543
self.make_clone_call(dest_field, src_field, ty, BasicBlock::new(3), BasicBlock::new(5));
544544

@@ -620,9 +620,9 @@ impl CloneShimBuilder<'tcx> {
620620
let mut previous_field = None;
621621
for (i, ity) in tys.enumerate() {
622622
let field = Field::new(i);
623-
let src_field = self.tcx.mk_place_field(src.clone(), field, ity);
623+
let src_field = self.tcx.mk_place_field(src, field, ity);
624624

625-
let dest_field = self.tcx.mk_place_field(dest.clone(), field, ity);
625+
let dest_field = self.tcx.mk_place_field(dest, field, ity);
626626

627627
// #(2i + 1) is the cleanup block for the previous clone operation
628628
let cleanup_block = self.block_index_offset(1);
@@ -633,7 +633,7 @@ impl CloneShimBuilder<'tcx> {
633633
// BB #(2i)
634634
// `dest.i = Clone::clone(&src.i);`
635635
// Goto #(2i + 2) if ok, #(2i + 1) if unwinding happens.
636-
self.make_clone_call(dest_field.clone(), src_field, ity, next_block, cleanup_block);
636+
self.make_clone_call(dest_field, src_field, ity, next_block, cleanup_block);
637637

638638
// BB #(2i + 1) (cleanup)
639639
if let Some((previous_field, previous_cleanup)) = previous_field.take() {

src/librustc_mir/transform/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl Inliner<'tcx> {
582582
let tuple_tmp_args = tuple_tys.iter().enumerate().map(|(i, ty)| {
583583
// This is e.g., `tuple_tmp.0` in our example above.
584584
let tuple_field =
585-
Operand::Move(tcx.mk_place_field(tuple.clone(), Field::new(i), ty.expect_ty()));
585+
Operand::Move(tcx.mk_place_field(tuple, Field::new(i), ty.expect_ty()));
586586

587587
// Spill to a local to make e.g., `tmp0`.
588588
self.create_temp_if_necessary(tuple_field, callsite, caller_body)

src/librustc_mir/util/aggregate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn expand_aggregate<'tcx>(
5656
let offset = i as u32;
5757
assert_eq!(offset as usize, i);
5858
tcx.mk_place_elem(
59-
lhs.clone(),
59+
lhs,
6060
ProjectionElem::ConstantIndex {
6161
offset,
6262
// FIXME(eddyb) `min_length` doesn't appear to be used.
@@ -66,7 +66,7 @@ pub fn expand_aggregate<'tcx>(
6666
)
6767
} else {
6868
let field = Field::new(active_field_index.unwrap_or(i));
69-
tcx.mk_place_field(lhs.clone(), field, ty)
69+
tcx.mk_place_field(lhs, field, ty)
7070
};
7171
Statement { source_info, kind: StatementKind::Assign(box (lhs_field, Rvalue::Use(op))) }
7272
})

src/librustc_mir/util/elaborate_drops.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ where
212212
assert_eq!(self.elaborator.param_env().reveal, Reveal::All);
213213
let field_ty =
214214
tcx.normalize_erasing_regions(self.elaborator.param_env(), f.ty(tcx, substs));
215-
(tcx.mk_place_field(base_place.clone(), field, field_ty), subpath)
215+
(tcx.mk_place_field(base_place, field, field_ty), subpath)
216216
})
217217
.collect()
218218
}
@@ -340,7 +340,7 @@ where
340340
.enumerate()
341341
.map(|(i, &ty)| {
342342
(
343-
self.tcx().mk_place_field(self.place.clone(), Field::new(i), ty),
343+
self.tcx().mk_place_field(self.place, Field::new(i), ty),
344344
self.elaborator.field_subpath(self.path, Field::new(i)),
345345
)
346346
})
@@ -353,7 +353,7 @@ where
353353
fn open_drop_for_box(&mut self, adt: &'tcx ty::AdtDef, substs: SubstsRef<'tcx>) -> BasicBlock {
354354
debug!("open_drop_for_box({:?}, {:?}, {:?})", self, adt, substs);
355355

356-
let interior = self.tcx().mk_place_deref(self.place.clone());
356+
let interior = self.tcx().mk_place_deref(self.place);
357357
let interior_path = self.elaborator.deref_subpath(self.path);
358358

359359
let succ = self.succ; // FIXME(#43234)
@@ -434,7 +434,7 @@ where
434434

435435
if let Some(variant_path) = subpath {
436436
let base_place = tcx.mk_place_elem(
437-
self.place.clone(),
437+
self.place,
438438
ProjectionElem::Downcast(Some(variant.ident.name), variant_index),
439439
);
440440
let fields = self.move_paths_for_fields(base_place, variant_path, &variant, substs);
@@ -622,7 +622,7 @@ where
622622
(Rvalue::Use(copy(cur.into())), Rvalue::BinaryOp(BinOp::Offset, move_(cur.into()), one))
623623
} else {
624624
(
625-
Rvalue::AddressOf(Mutability::Mut, tcx.mk_place_index(self.place.clone(), cur)),
625+
Rvalue::AddressOf(Mutability::Mut, tcx.mk_place_index(self.place, cur)),
626626
Rvalue::BinaryOp(BinOp::Add, move_(cur.into()), one),
627627
)
628628
};
@@ -654,7 +654,7 @@ where
654654
self.elaborator.patch().patch_terminator(
655655
drop_block,
656656
TerminatorKind::Drop {
657-
location: tcx.mk_place_deref(ptr.clone()),
657+
location: tcx.mk_place_deref(ptr),
658658
target: loop_block,
659659
unwind: unwind.into_option(),
660660
},
@@ -682,7 +682,7 @@ where
682682
.map(|i| {
683683
(
684684
tcx.mk_place_elem(
685-
self.place.clone(),
685+
self.place,
686686
ProjectionElem::ConstantIndex {
687687
offset: i,
688688
min_length: size,
@@ -719,8 +719,8 @@ where
719719
switch_ty: tcx.types.usize,
720720
values: From::from(USIZE_SWITCH_ZERO),
721721
targets: vec![
722-
self.drop_loop_pair(ety, false, len.clone()),
723-
self.drop_loop_pair(ety, true, len.clone()),
722+
self.drop_loop_pair(ety, false, len),
723+
self.drop_loop_pair(ety, true, len),
724724
],
725725
},
726726
}),
@@ -912,7 +912,7 @@ where
912912
.map(|(i, f)| {
913913
let field = Field::new(i);
914914
let field_ty = f.ty(tcx, substs);
915-
Operand::Move(tcx.mk_place_field(self.place.clone(), field, field_ty))
915+
Operand::Move(tcx.mk_place_field(self.place, field, field_ty))
916916
})
917917
.collect();
918918

src/librustc_mir_build/build/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::build::matches::ArmHasGuard;
22
use crate::build::ForGuard::OutsideGuard;
33
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
44
use crate::hair::*;
5-
use rustc_middle::mir::*;
65
use rustc_hir as hir;
6+
use rustc_middle::mir::*;
77
use rustc_span::Span;
88

99
impl<'a, 'tcx> Builder<'a, 'tcx> {
@@ -29,7 +29,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2929
// This is a `break`-able block
3030
let exit_block = this.cfg.start_new_block();
3131
let block_exit =
32-
this.in_breakable_scope(None, exit_block, destination.clone(), |this| {
32+
this.in_breakable_scope(None, exit_block, destination, |this| {
3333
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
3434
});
3535
this.cfg.goto(unpack!(block_exit), source_info, exit_block);

src/librustc_mir_build/build/expr/into.rs

+41-47
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
use crate::build::expr::category::{Category, RvalueFunc};
44
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
55
use crate::hair::*;
6-
use rustc_middle::mir::*;
7-
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation};
86
use rustc_data_structures::fx::FxHashMap;
97
use rustc_hir as hir;
8+
use rustc_middle::mir::*;
9+
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation};
1010
use rustc_span::symbol::sym;
1111

1212
use rustc_target::spec::abi::Abi;
@@ -139,31 +139,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
139139
// Start the loop.
140140
this.cfg.goto(block, source_info, loop_block);
141141

142-
this.in_breakable_scope(
143-
Some(loop_block),
144-
exit_block,
145-
destination.clone(),
146-
move |this| {
147-
// conduct the test, if necessary
148-
let body_block = this.cfg.start_new_block();
149-
let diverge_cleanup = this.diverge_cleanup();
150-
this.cfg.terminate(
151-
loop_block,
152-
source_info,
153-
TerminatorKind::FalseUnwind {
154-
real_target: body_block,
155-
unwind: Some(diverge_cleanup),
156-
},
157-
);
158-
159-
// The “return” value of the loop body must always be an unit. We therefore
160-
// introduce a unit temporary as the destination for the loop body.
161-
let tmp = this.get_unit_temp();
162-
// Execute the body, branching back to the test.
163-
let body_block_end = unpack!(this.into(tmp, body_block, body));
164-
this.cfg.goto(body_block_end, source_info, loop_block);
165-
},
166-
);
142+
this.in_breakable_scope(Some(loop_block), exit_block, destination, move |this| {
143+
// conduct the test, if necessary
144+
let body_block = this.cfg.start_new_block();
145+
let diverge_cleanup = this.diverge_cleanup();
146+
this.cfg.terminate(
147+
loop_block,
148+
source_info,
149+
TerminatorKind::FalseUnwind {
150+
real_target: body_block,
151+
unwind: Some(diverge_cleanup),
152+
},
153+
);
154+
155+
// The “return” value of the loop body must always be an unit. We therefore
156+
// introduce a unit temporary as the destination for the loop body.
157+
let tmp = this.get_unit_temp();
158+
// Execute the body, branching back to the test.
159+
let body_block_end = unpack!(this.into(tmp, body_block, body));
160+
this.cfg.goto(body_block_end, source_info, loop_block);
161+
});
167162
exit_block.unit()
168163
}
169164
ExprKind::Call { ty, fun, args, from_hir_call } => {
@@ -278,26 +273,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
278273

279274
let field_names = this.hir.all_fields(adt_def, variant_index);
280275

281-
let fields =
282-
if let Some(FruInfo { base, field_types }) = base {
283-
let base = unpack!(block = this.as_place(block, base));
284-
285-
// MIR does not natively support FRU, so for each
286-
// base-supplied field, generate an operand that
287-
// reads it from the base.
288-
field_names
289-
.into_iter()
290-
.zip(field_types.into_iter())
291-
.map(|(n, ty)| match fields_map.get(&n) {
292-
Some(v) => v.clone(),
293-
None => this.consume_by_copy_or_move(
294-
this.hir.tcx().mk_place_field(base.clone(), n, ty),
295-
),
296-
})
297-
.collect()
298-
} else {
299-
field_names.iter().filter_map(|n| fields_map.get(n).cloned()).collect()
300-
};
276+
let fields = if let Some(FruInfo { base, field_types }) = base {
277+
let base = unpack!(block = this.as_place(block, base));
278+
279+
// MIR does not natively support FRU, so for each
280+
// base-supplied field, generate an operand that
281+
// reads it from the base.
282+
field_names
283+
.into_iter()
284+
.zip(field_types.into_iter())
285+
.map(|(n, ty)| match fields_map.get(&n) {
286+
Some(v) => v.clone(),
287+
None => this.consume_by_copy_or_move(
288+
this.hir.tcx().mk_place_field(base, n, ty),
289+
),
290+
})
291+
.collect()
292+
} else {
293+
field_names.iter().filter_map(|n| fields_map.get(n).cloned()).collect()
294+
};
301295

302296
let inferred_ty = expr.ty;
303297
let user_ty = user_ty.map(|ty| {

src/librustc_mir_build/build/matches/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1903,9 +1903,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19031903
self.schedule_drop_for_binding(binding.var_id, binding.span, OutsideGuard);
19041904
}
19051905
let rvalue = match binding.binding_mode {
1906-
BindingMode::ByValue => {
1907-
Rvalue::Use(self.consume_by_copy_or_move(binding.source.clone()))
1908-
}
1906+
BindingMode::ByValue => Rvalue::Use(self.consume_by_copy_or_move(binding.source)),
19091907
BindingMode::ByRef(borrow_kind) => {
19101908
Rvalue::Ref(re_erased, borrow_kind, binding.source)
19111909
}

0 commit comments

Comments
 (0)