Skip to content

Commit

Permalink
Rollup merge of #88849 - matthiaskrgr:clony_on_copy, r=petrochenkov
Browse files Browse the repository at this point in the history
don't clone types that are Copy (clippy::clone_on_copy)
  • Loading branch information
GuillaumeGomez authored Sep 11, 2021
2 parents 9c7edef + c1e9608 commit 35b66f8
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 34 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category: constraint.category,
from_closure: false,
span,
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
};
}
Locations::Single(loc) => loc,
Expand All @@ -1752,13 +1752,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category,
from_closure: true,
span: span,
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
})
.unwrap_or(BlameConstraint {
category: constraint.category,
from_closure: false,
span: body.source_info(loc).span,
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
})
}

Expand Down Expand Up @@ -2001,7 +2001,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category: constraint.category,
from_closure: false,
span: constraint.locations.span(body),
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
}
}
})
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ where

let old_ambient_variance = self.ambient_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);

Expand Down Expand Up @@ -597,12 +597,12 @@ where

if self.ambient_covariance() {
// 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() {
// 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)
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_macros/src/session_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
span_idx = Some(syn::Index::from(idx));
} else {
throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"type of field annotated with `#[suggestion(...)]` contains more than one Span"
);
}
Expand All @@ -460,7 +460,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
applicability_idx = Some(syn::Index::from(idx));
} else {
throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"type of field annotated with `#[suggestion(...)]` contains more than one Applicability"
);
}
Expand All @@ -479,15 +479,15 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
return Ok((span, applicability));
}
throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"wrong types for suggestion",
|diag| {
diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type (Span, Applicability)")
}
);
}
_ => throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"wrong field type for suggestion",
|diag| {
diag.help("#[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)")
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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,
ascription.source.ty(&self.local_decls, self.tcx).ty,
source_info.span,
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_mir_transform/src/lower_slice_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ fn lower_slice_len_call<'tcx>(
let deref_arg = tcx.mk_place_deref(arg);
let r_value = Rvalue::Len(deref_arg);
let len_statement_kind = StatementKind::Assign(Box::new((*dest, r_value)));
let add_statement = Statement {
kind: len_statement_kind,
source_info: terminator.source_info.clone(),
};
let add_statement =
Statement { kind: len_statement_kind, source_info: terminator.source_info };

// 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 };

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ impl<'a> Resolver<'a> {
.iter()
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
.collect(),
main_def: self.main_def.clone(),
main_def: self.main_def,
trait_impls: self.trait_impls.clone(),
proc_macros,
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,7 @@ fn for_all_expns_in<E>(
mut f: impl FnMut(ExpnId, &ExpnData, ExpnHash) -> Result<(), E>,
) -> Result<(), E> {
let all_data: Vec<_> = HygieneData::with(|data| {
expns
.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn).clone()))
.collect()
expns.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn))).collect()
});
for (expn, data, hash) in all_data.into_iter() {
f(expn, &data, hash)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
root_obligation.cause.code.peel_derives()
{
if let Some(cause) = self.tcx.diagnostic_hir_wf_check((
tcx.erase_regions(obligation.predicate),
wf_loc.clone(),
)) {
if let Some(cause) = self
.tcx
.diagnostic_hir_wf_check((tcx.erase_regions(obligation.predicate), *wf_loc))
{
obligation.cause = cause;
span = obligation.cause.span;
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => {
let universe = self.universe_for(debruijn);
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))
}
_ => r,
Expand All @@ -613,7 +613,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => {
let universe = self.universe_for(debruijn);
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))
}
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
Expand All @@ -637,7 +637,7 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
universe,
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 })
}
_ if ct.has_vars_bound_at_or_above(self.current_index) => ct.super_fold_with(self),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
"get_provisional = {:#?}",
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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub enum AutorefOrPtrAdjustment<'tcx> {
impl<'tcx> AutorefOrPtrAdjustment<'tcx> {
fn get_unsize(&self) -> Option<Ty<'tcx>> {
match self {
AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => unsize.clone(),
AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
AutorefOrPtrAdjustment::ToConstPtr => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/formatters/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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.
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));
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl Item {
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
match 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 {
href.push('#');
href.push_str(fragment);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
search_paths: options.libs.clone(),
crate_types,
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(),
externs: options.externs.clone(),
unstable_features: options.render_options.unstable_features,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ impl LinkCollector<'_, '_> {
if let Some(ref cached) = self.visited_links.get(&key) {
match 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());
}
None if cache_resolution_failure => return None,
Expand Down

0 comments on commit 35b66f8

Please sign in to comment.