don't clone types that are Copy (clippy::clone_on_copy)

This commit is contained in:
Matthias Krüger 2021-09-11 10:18:56 +02:00
parent 22719efcc5
commit c1e96085d3
15 changed files with 30 additions and 34 deletions

View File

@ -1739,7 +1739,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category: constraint.category, category: constraint.category,
from_closure: false, from_closure: false,
span, span,
variance_info: constraint.variance_info.clone(), variance_info: constraint.variance_info,
}; };
} }
Locations::Single(loc) => loc, Locations::Single(loc) => loc,
@ -1752,13 +1752,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category, category,
from_closure: true, from_closure: true,
span: span, span: span,
variance_info: constraint.variance_info.clone(), variance_info: constraint.variance_info,
}) })
.unwrap_or(BlameConstraint { .unwrap_or(BlameConstraint {
category: constraint.category, category: constraint.category,
from_closure: false, from_closure: false,
span: body.source_info(loc).span, span: body.source_info(loc).span,
variance_info: constraint.variance_info.clone(), variance_info: constraint.variance_info,
}) })
} }
@ -2001,7 +2001,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category: constraint.category, category: constraint.category,
from_closure: false, from_closure: false,
span: constraint.locations.span(body), span: constraint.locations.span(body),
variance_info: constraint.variance_info.clone(), variance_info: constraint.variance_info,
} }
} }
}) })

View File

@ -519,7 +519,7 @@ where
let old_ambient_variance = self.ambient_variance; let old_ambient_variance = self.ambient_variance;
self.ambient_variance = self.ambient_variance.xform(variance); self.ambient_variance = self.ambient_variance.xform(variance);
self.ambient_variance_info = self.ambient_variance_info.clone().xform(info); self.ambient_variance_info = self.ambient_variance_info.xform(info);
debug!("relate_with_variance: ambient_variance = {:?}", self.ambient_variance); debug!("relate_with_variance: ambient_variance = {:?}", self.ambient_variance);
@ -597,12 +597,12 @@ where
if self.ambient_covariance() { if self.ambient_covariance() {
// Covariance: a <= b. Hence, `b: a`. // Covariance: a <= b. Hence, `b: a`.
self.push_outlives(v_b, v_a, self.ambient_variance_info.clone()); self.push_outlives(v_b, v_a, self.ambient_variance_info);
} }
if self.ambient_contravariance() { if self.ambient_contravariance() {
// Contravariant: b <= a. Hence, `a: b`. // Contravariant: b <= a. Hence, `a: b`.
self.push_outlives(v_a, v_b, self.ambient_variance_info.clone()); self.push_outlives(v_a, v_b, self.ambient_variance_info);
} }
Ok(a) Ok(a)

View File

@ -448,7 +448,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
span_idx = Some(syn::Index::from(idx)); span_idx = Some(syn::Index::from(idx));
} else { } else {
throw_span_err!( throw_span_err!(
info.span.clone().unwrap(), info.span.unwrap(),
"type of field annotated with `#[suggestion(...)]` contains more than one Span" "type of field annotated with `#[suggestion(...)]` contains more than one Span"
); );
} }
@ -460,7 +460,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
applicability_idx = Some(syn::Index::from(idx)); applicability_idx = Some(syn::Index::from(idx));
} else { } else {
throw_span_err!( throw_span_err!(
info.span.clone().unwrap(), info.span.unwrap(),
"type of field annotated with `#[suggestion(...)]` contains more than one Applicability" "type of field annotated with `#[suggestion(...)]` contains more than one Applicability"
); );
} }
@ -479,7 +479,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
return Ok((span, applicability)); return Ok((span, applicability));
} }
throw_span_err!( throw_span_err!(
info.span.clone().unwrap(), info.span.unwrap(),
"wrong types for suggestion", "wrong types for suggestion",
|diag| { |diag| {
diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type (Span, Applicability)") diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type (Span, Applicability)")
@ -487,7 +487,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
); );
} }
_ => throw_span_err!( _ => throw_span_err!(
info.span.clone().unwrap(), info.span.unwrap(),
"wrong field type for suggestion", "wrong field type for suggestion",
|diag| { |diag| {
diag.help("#[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)") diag.help("#[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)")

View File

@ -2060,7 +2060,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
source_info.span, ascription.source, ascription.user_ty, source_info.span, ascription.source, ascription.user_ty,
); );
let user_ty = ascription.user_ty.clone().user_ty( let user_ty = ascription.user_ty.user_ty(
&mut self.canonical_user_type_annotations, &mut self.canonical_user_type_annotations,
ascription.source.ty(&self.local_decls, self.tcx).ty, ascription.source.ty(&self.local_decls, self.tcx).ty,
source_info.span, source_info.span,

View File

@ -75,13 +75,11 @@ fn lower_slice_len_call<'tcx>(
let deref_arg = tcx.mk_place_deref(arg); let deref_arg = tcx.mk_place_deref(arg);
let r_value = Rvalue::Len(deref_arg); let r_value = Rvalue::Len(deref_arg);
let len_statement_kind = StatementKind::Assign(Box::new((*dest, r_value))); let len_statement_kind = StatementKind::Assign(Box::new((*dest, r_value)));
let add_statement = Statement { let add_statement =
kind: len_statement_kind, Statement { kind: len_statement_kind, source_info: terminator.source_info };
source_info: terminator.source_info.clone(),
};
// modify terminator into simple Goto // modify terminator into simple Goto
let new_terminator_kind = TerminatorKind::Goto { target: bb.clone() }; let new_terminator_kind = TerminatorKind::Goto { target: *bb };
let patch = SliceLenPatchInformation { add_statement, new_terminator_kind }; let patch = SliceLenPatchInformation { add_statement, new_terminator_kind };

View File

@ -1487,7 +1487,7 @@ impl<'a> Resolver<'a> {
.iter() .iter()
.map(|(ident, entry)| (ident.name, entry.introduced_by_item)) .map(|(ident, entry)| (ident.name, entry.introduced_by_item))
.collect(), .collect(),
main_def: self.main_def.clone(), main_def: self.main_def,
trait_impls: self.trait_impls.clone(), trait_impls: self.trait_impls.clone(),
proc_macros, proc_macros,
confused_type_with_std_module: self.confused_type_with_std_module.clone(), confused_type_with_std_module: self.confused_type_with_std_module.clone(),

View File

@ -1357,9 +1357,7 @@ fn for_all_expns_in<E>(
mut f: impl FnMut(ExpnId, &ExpnData, ExpnHash) -> Result<(), E>, mut f: impl FnMut(ExpnId, &ExpnData, ExpnHash) -> Result<(), E>,
) -> Result<(), E> { ) -> Result<(), E> {
let all_data: Vec<_> = HygieneData::with(|data| { let all_data: Vec<_> = HygieneData::with(|data| {
expns expns.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn))).collect()
.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn).clone()))
.collect()
}); });
for (expn, data, hash) in all_data.into_iter() { for (expn, data, hash) in all_data.into_iter() {
f(expn, &data, hash)?; f(expn, &data, hash)?;

View File

@ -249,10 +249,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let ObligationCauseCode::WellFormed(Some(wf_loc)) = if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
root_obligation.cause.code.peel_derives() root_obligation.cause.code.peel_derives()
{ {
if let Some(cause) = self.tcx.diagnostic_hir_wf_check(( if let Some(cause) = self
tcx.erase_regions(obligation.predicate), .tcx
wf_loc.clone(), .diagnostic_hir_wf_check((tcx.erase_regions(obligation.predicate), *wf_loc))
)) { {
obligation.cause = cause; obligation.cause = cause;
span = obligation.cause.span; span = obligation.cause.span;
} }

View File

@ -595,7 +595,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => { ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => {
let universe = self.universe_for(debruijn); let universe = self.universe_for(debruijn);
let p = ty::PlaceholderRegion { universe, name: br.kind }; let p = ty::PlaceholderRegion { universe, name: br.kind };
self.mapped_regions.insert(p.clone(), br); self.mapped_regions.insert(p, br);
self.infcx.tcx.mk_region(ty::RePlaceholder(p)) self.infcx.tcx.mk_region(ty::RePlaceholder(p))
} }
_ => r, _ => r,
@ -613,7 +613,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => { ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => {
let universe = self.universe_for(debruijn); let universe = self.universe_for(debruijn);
let p = ty::PlaceholderType { universe, name: bound_ty.var }; let p = ty::PlaceholderType { universe, name: bound_ty.var };
self.mapped_types.insert(p.clone(), bound_ty); self.mapped_types.insert(p, bound_ty);
self.infcx.tcx.mk_ty(ty::Placeholder(p)) self.infcx.tcx.mk_ty(ty::Placeholder(p))
} }
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self), _ 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> {
universe, universe,
name: ty::BoundConst { var: bound_const, ty }, name: ty::BoundConst { var: bound_const, ty },
}; };
self.mapped_consts.insert(p.clone(), bound_const); self.mapped_consts.insert(p, bound_const);
self.infcx.tcx.mk_const(ty::Const { val: ty::ConstKind::Placeholder(p), ty }) self.infcx.tcx.mk_const(ty::Const { val: ty::ConstKind::Placeholder(p), ty })
} }
_ if ct.has_vars_bound_at_or_above(self.current_index) => ct.super_fold_with(self), _ if ct.has_vars_bound_at_or_above(self.current_index) => ct.super_fold_with(self),

View File

@ -2445,7 +2445,7 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
"get_provisional = {:#?}", "get_provisional = {:#?}",
self.map.borrow().get(&fresh_trait_ref), self.map.borrow().get(&fresh_trait_ref),
); );
Some(self.map.borrow().get(&fresh_trait_ref)?.clone()) Some(*self.map.borrow().get(&fresh_trait_ref)?)
} }
/// Insert a provisional result into the cache. The result came /// Insert a provisional result into the cache. The result came

View File

@ -186,7 +186,7 @@ pub enum AutorefOrPtrAdjustment<'tcx> {
impl<'tcx> AutorefOrPtrAdjustment<'tcx> { impl<'tcx> AutorefOrPtrAdjustment<'tcx> {
fn get_unsize(&self) -> Option<Ty<'tcx>> { fn get_unsize(&self) -> Option<Ty<'tcx>> {
match self { match self {
AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => unsize.clone(), AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
AutorefOrPtrAdjustment::ToConstPtr => None, AutorefOrPtrAdjustment::ToConstPtr => None,
} }
} }

View File

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

View File

@ -463,7 +463,7 @@ impl Item {
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| { .filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
match did { match did {
Some(did) => { Some(did) => {
if let Ok((mut href, ..)) = href(did.clone(), cx) { if let Ok((mut href, ..)) = href(*did, cx) {
if let Some(ref fragment) = *fragment { if let Some(ref fragment) = *fragment {
href.push('#'); href.push('#');
href.push_str(fragment); href.push_str(fragment);

View File

@ -73,7 +73,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
search_paths: options.libs.clone(), search_paths: options.libs.clone(),
crate_types, crate_types,
lint_opts: if !options.display_warnings { lint_opts } else { vec![] }, lint_opts: if !options.display_warnings { lint_opts } else { vec![] },
lint_cap: Some(options.lint_cap.clone().unwrap_or_else(|| lint::Forbid)), lint_cap: Some(options.lint_cap.unwrap_or_else(|| lint::Forbid)),
cg: options.codegen_options.clone(), cg: options.codegen_options.clone(),
externs: options.externs.clone(), externs: options.externs.clone(),
unstable_features: options.render_options.unstable_features, unstable_features: options.render_options.unstable_features,

View File

@ -1323,7 +1323,7 @@ impl LinkCollector<'_, '_> {
if let Some(ref cached) = self.visited_links.get(&key) { if let Some(ref cached) = self.visited_links.get(&key) {
match cached { match cached {
Some(cached) => { Some(cached) => {
self.kind_side_channel.set(cached.side_channel.clone()); self.kind_side_channel.set(cached.side_channel);
return Some(cached.res.clone()); return Some(cached.res.clone());
} }
None if cache_resolution_failure => return None, None if cache_resolution_failure => return None,