Skip to content

Commit c2e1097

Browse files
Rollup merge of #88849 - matthiaskrgr:clony_on_copy, r=petrochenkov
don't clone types that are Copy (clippy::clone_on_copy)
2 parents 2cfafa6 + c1e9608 commit c2e1097

File tree

15 files changed

+30
-34
lines changed

15 files changed

+30
-34
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17391739
category: constraint.category,
17401740
from_closure: false,
17411741
span,
1742-
variance_info: constraint.variance_info.clone(),
1742+
variance_info: constraint.variance_info,
17431743
};
17441744
}
17451745
Locations::Single(loc) => loc,
@@ -1752,13 +1752,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17521752
category,
17531753
from_closure: true,
17541754
span: span,
1755-
variance_info: constraint.variance_info.clone(),
1755+
variance_info: constraint.variance_info,
17561756
})
17571757
.unwrap_or(BlameConstraint {
17581758
category: constraint.category,
17591759
from_closure: false,
17601760
span: body.source_info(loc).span,
1761-
variance_info: constraint.variance_info.clone(),
1761+
variance_info: constraint.variance_info,
17621762
})
17631763
}
17641764

@@ -2001,7 +2001,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20012001
category: constraint.category,
20022002
from_closure: false,
20032003
span: constraint.locations.span(body),
2004-
variance_info: constraint.variance_info.clone(),
2004+
variance_info: constraint.variance_info,
20052005
}
20062006
}
20072007
})

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ where
519519

520520
let old_ambient_variance = self.ambient_variance;
521521
self.ambient_variance = self.ambient_variance.xform(variance);
522-
self.ambient_variance_info = self.ambient_variance_info.clone().xform(info);
522+
self.ambient_variance_info = self.ambient_variance_info.xform(info);
523523

524524
debug!("relate_with_variance: ambient_variance = {:?}", self.ambient_variance);
525525

@@ -597,12 +597,12 @@ where
597597

598598
if self.ambient_covariance() {
599599
// Covariance: a <= b. Hence, `b: a`.
600-
self.push_outlives(v_b, v_a, self.ambient_variance_info.clone());
600+
self.push_outlives(v_b, v_a, self.ambient_variance_info);
601601
}
602602

603603
if self.ambient_contravariance() {
604604
// Contravariant: b <= a. Hence, `a: b`.
605-
self.push_outlives(v_a, v_b, self.ambient_variance_info.clone());
605+
self.push_outlives(v_a, v_b, self.ambient_variance_info);
606606
}
607607

608608
Ok(a)

compiler/rustc_macros/src/session_diagnostic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
448448
span_idx = Some(syn::Index::from(idx));
449449
} else {
450450
throw_span_err!(
451-
info.span.clone().unwrap(),
451+
info.span.unwrap(),
452452
"type of field annotated with `#[suggestion(...)]` contains more than one Span"
453453
);
454454
}
@@ -460,7 +460,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
460460
applicability_idx = Some(syn::Index::from(idx));
461461
} else {
462462
throw_span_err!(
463-
info.span.clone().unwrap(),
463+
info.span.unwrap(),
464464
"type of field annotated with `#[suggestion(...)]` contains more than one Applicability"
465465
);
466466
}
@@ -479,15 +479,15 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
479479
return Ok((span, applicability));
480480
}
481481
throw_span_err!(
482-
info.span.clone().unwrap(),
482+
info.span.unwrap(),
483483
"wrong types for suggestion",
484484
|diag| {
485485
diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type (Span, Applicability)")
486486
}
487487
);
488488
}
489489
_ => throw_span_err!(
490-
info.span.clone().unwrap(),
490+
info.span.unwrap(),
491491
"wrong field type for suggestion",
492492
|diag| {
493493
diag.help("#[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)")

compiler/rustc_mir_build/src/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20602060
source_info.span, ascription.source, ascription.user_ty,
20612061
);
20622062

2063-
let user_ty = ascription.user_ty.clone().user_ty(
2063+
let user_ty = ascription.user_ty.user_ty(
20642064
&mut self.canonical_user_type_annotations,
20652065
ascription.source.ty(&self.local_decls, self.tcx).ty,
20662066
source_info.span,

compiler/rustc_mir_transform/src/lower_slice_len.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ fn lower_slice_len_call<'tcx>(
7575
let deref_arg = tcx.mk_place_deref(arg);
7676
let r_value = Rvalue::Len(deref_arg);
7777
let len_statement_kind = StatementKind::Assign(Box::new((*dest, r_value)));
78-
let add_statement = Statement {
79-
kind: len_statement_kind,
80-
source_info: terminator.source_info.clone(),
81-
};
78+
let add_statement =
79+
Statement { kind: len_statement_kind, source_info: terminator.source_info };
8280

8381
// modify terminator into simple Goto
84-
let new_terminator_kind = TerminatorKind::Goto { target: bb.clone() };
82+
let new_terminator_kind = TerminatorKind::Goto { target: *bb };
8583

8684
let patch = SliceLenPatchInformation { add_statement, new_terminator_kind };
8785

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ impl<'a> Resolver<'a> {
14871487
.iter()
14881488
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
14891489
.collect(),
1490-
main_def: self.main_def.clone(),
1490+
main_def: self.main_def,
14911491
trait_impls: self.trait_impls.clone(),
14921492
proc_macros,
14931493
confused_type_with_std_module: self.confused_type_with_std_module.clone(),

compiler/rustc_span/src/hygiene.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1357,9 +1357,7 @@ fn for_all_expns_in<E>(
13571357
mut f: impl FnMut(ExpnId, &ExpnData, ExpnHash) -> Result<(), E>,
13581358
) -> Result<(), E> {
13591359
let all_data: Vec<_> = HygieneData::with(|data| {
1360-
expns
1361-
.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn).clone()))
1362-
.collect()
1360+
expns.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn))).collect()
13631361
});
13641362
for (expn, data, hash) in all_data.into_iter() {
13651363
f(expn, &data, hash)?;

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
249249
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
250250
root_obligation.cause.code.peel_derives()
251251
{
252-
if let Some(cause) = self.tcx.diagnostic_hir_wf_check((
253-
tcx.erase_regions(obligation.predicate),
254-
wf_loc.clone(),
255-
)) {
252+
if let Some(cause) = self
253+
.tcx
254+
.diagnostic_hir_wf_check((tcx.erase_regions(obligation.predicate), *wf_loc))
255+
{
256256
obligation.cause = cause;
257257
span = obligation.cause.span;
258258
}

compiler/rustc_trait_selection/src/traits/project.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
595595
ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => {
596596
let universe = self.universe_for(debruijn);
597597
let p = ty::PlaceholderRegion { universe, name: br.kind };
598-
self.mapped_regions.insert(p.clone(), br);
598+
self.mapped_regions.insert(p, br);
599599
self.infcx.tcx.mk_region(ty::RePlaceholder(p))
600600
}
601601
_ => r,
@@ -613,7 +613,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
613613
ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => {
614614
let universe = self.universe_for(debruijn);
615615
let p = ty::PlaceholderType { universe, name: bound_ty.var };
616-
self.mapped_types.insert(p.clone(), bound_ty);
616+
self.mapped_types.insert(p, bound_ty);
617617
self.infcx.tcx.mk_ty(ty::Placeholder(p))
618618
}
619619
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
@@ -637,7 +637,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
637637
universe,
638638
name: ty::BoundConst { var: bound_const, ty },
639639
};
640-
self.mapped_consts.insert(p.clone(), bound_const);
640+
self.mapped_consts.insert(p, bound_const);
641641
self.infcx.tcx.mk_const(ty::Const { val: ty::ConstKind::Placeholder(p), ty })
642642
}
643643
_ if ct.has_vars_bound_at_or_above(self.current_index) => ct.super_fold_with(self),

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
24452445
"get_provisional = {:#?}",
24462446
self.map.borrow().get(&fresh_trait_ref),
24472447
);
2448-
Some(self.map.borrow().get(&fresh_trait_ref)?.clone())
2448+
Some(*self.map.borrow().get(&fresh_trait_ref)?)
24492449
}
24502450

24512451
/// Insert a provisional result into the cache. The result came

compiler/rustc_typeck/src/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub enum AutorefOrPtrAdjustment<'tcx> {
186186
impl<'tcx> AutorefOrPtrAdjustment<'tcx> {
187187
fn get_unsize(&self) -> Option<Ty<'tcx>> {
188188
match self {
189-
AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => unsize.clone(),
189+
AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
190190
AutorefOrPtrAdjustment::ToConstPtr => None,
191191
}
192192
}

library/test/src/formatters/junit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
5353
// Because the testsuit node holds some of the information as attributes, we can't write it
5454
// until all of the tests has ran. Instead of writting every result as they come in, we add
5555
// them to a Vec and write them all at once when run is complete.
56-
let duration = exec_time.map(|t| t.0.clone()).unwrap_or_default();
56+
let duration = exec_time.map(|t| t.0).unwrap_or_default();
5757
self.results.push((desc.clone(), result.clone(), duration));
5858
Ok(())
5959
}

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl Item {
463463
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
464464
match did {
465465
Some(did) => {
466-
if let Ok((mut href, ..)) = href(did.clone(), cx) {
466+
if let Ok((mut href, ..)) = href(*did, cx) {
467467
if let Some(ref fragment) = *fragment {
468468
href.push('#');
469469
href.push_str(fragment);

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
7373
search_paths: options.libs.clone(),
7474
crate_types,
7575
lint_opts: if !options.display_warnings { lint_opts } else { vec![] },
76-
lint_cap: Some(options.lint_cap.clone().unwrap_or_else(|| lint::Forbid)),
76+
lint_cap: Some(options.lint_cap.unwrap_or_else(|| lint::Forbid)),
7777
cg: options.codegen_options.clone(),
7878
externs: options.externs.clone(),
7979
unstable_features: options.render_options.unstable_features,

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ impl LinkCollector<'_, '_> {
13231323
if let Some(ref cached) = self.visited_links.get(&key) {
13241324
match cached {
13251325
Some(cached) => {
1326-
self.kind_side_channel.set(cached.side_channel.clone());
1326+
self.kind_side_channel.set(cached.side_channel);
13271327
return Some(cached.res.clone());
13281328
}
13291329
None if cache_resolution_failure => return None,

0 commit comments

Comments
 (0)