Skip to content

Commit aa6e58b

Browse files
Rollup merge of rust-lang#68459 - matthiaskrgr:clone_on_copy2, r=eddyb
don't clone types that are copy, round two. Apparently fixing some of these issues makes clippy find even more so I did a couple of rounds now. r? @eddyb
2 parents 8a79d08 + f7dcdcc commit aa6e58b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+155
-192
lines changed

src/librustc/infer/fudge.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn const_vars_since_snapshot<'tcx>(
1919
(
2020
range.start..range.end,
2121
(range.start.index..range.end.index)
22-
.map(|index| table.probe_value(ConstVid::from_index(index)).origin.clone())
22+
.map(|index| table.probe_value(ConstVid::from_index(index)).origin)
2323
.collect(),
2424
)
2525
}

src/librustc/infer/lexical_region_resolve/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
611611

612612
errors.push(RegionResolutionError::GenericBoundFailure(
613613
verify.origin.clone(),
614-
verify.kind.clone(),
614+
verify.kind,
615615
sub,
616616
));
617617
}
@@ -761,7 +761,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
761761

762762
for upper_bound in &upper_bounds {
763763
if !self.region_rels.is_subregion_of(effective_lower_bound, upper_bound.region) {
764-
let origin = self.var_infos[node_idx].origin.clone();
764+
let origin = self.var_infos[node_idx].origin;
765765
debug!(
766766
"region inference error at {:?} for {:?}: SubSupConflict sub: {:?} \
767767
sup: {:?}",

src/librustc/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
832832
(
833833
range.clone(),
834834
(range.start.index()..range.end.index())
835-
.map(|index| self.var_infos[ty::RegionVid::from(index)].origin.clone())
835+
.map(|index| self.var_infos[ty::RegionVid::from(index)].origin)
836836
.collect(),
837837
)
838838
}

src/librustc/infer/type_variable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'tcx> TypeVariableTable<'tcx> {
306306
(
307307
range.start.vid..range.end.vid,
308308
(range.start.vid.index..range.end.vid.index)
309-
.map(|index| self.values.get(index as usize).origin.clone())
309+
.map(|index| self.values.get(index as usize).origin)
310310
.collect(),
311311
)
312312
}

src/librustc/mir/mod.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ impl<'tcx> Operand<'tcx> {
19881988
pub fn to_copy(&self) -> Self {
19891989
match *self {
19901990
Operand::Copy(_) | Operand::Constant(_) => self.clone(),
1991-
Operand::Move(ref place) => Operand::Copy(place.clone()),
1991+
Operand::Move(place) => Operand::Copy(place),
19921992
}
19931993
}
19941994
}
@@ -2462,11 +2462,15 @@ impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
24622462
let projs: Vec<_> = self
24632463
.projs
24642464
.iter()
2465-
.map(|elem| match elem {
2465+
.map(|&elem| match elem {
24662466
Deref => Deref,
2467-
Field(f, ()) => Field(f.clone(), ()),
2467+
Field(f, ()) => Field(f, ()),
24682468
Index(()) => Index(()),
2469-
elem => elem.clone(),
2469+
Downcast(symbol, variantidx) => Downcast(symbol, variantidx),
2470+
ConstantIndex { offset, min_length, from_end } => {
2471+
ConstantIndex { offset, min_length, from_end }
2472+
}
2473+
Subslice { from, to, from_end } => Subslice { from, to, from_end },
24702474
})
24712475
.collect();
24722476

@@ -2862,11 +2866,15 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
28622866
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
28632867
use crate::mir::ProjectionElem::*;
28642868

2865-
match self {
2869+
match *self {
28662870
Deref => Deref,
2867-
Field(f, ty) => Field(*f, ty.fold_with(folder)),
2871+
Field(f, ty) => Field(f, ty.fold_with(folder)),
28682872
Index(v) => Index(v.fold_with(folder)),
2869-
elem => elem.clone(),
2873+
Downcast(symbol, variantidx) => Downcast(symbol, variantidx),
2874+
ConstantIndex { offset, min_length, from_end } => {
2875+
ConstantIndex { offset, min_length, from_end }
2876+
}
2877+
Subslice { from, to, from_end } => Subslice { from, to, from_end },
28702878
}
28712879
}
28722880

@@ -2911,7 +2919,7 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
29112919
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
29122920
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
29132921
Constant {
2914-
span: self.span.clone(),
2922+
span: self.span,
29152923
user_ty: self.user_ty.fold_with(folder),
29162924
literal: self.literal.fold_with(folder),
29172925
}

src/librustc/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'tcx> CodegenUnit<'tcx> {
362362
}
363363

364364
pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
365-
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name().clone()))
365+
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name()))
366366
}
367367
}
368368

src/librustc/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl AutoTraitFinder<'tcx> {
535535
}
536536

537537
while !vid_map.is_empty() {
538-
let target = vid_map.keys().next().expect("Keys somehow empty").clone();
538+
let target = *vid_map.keys().next().expect("Keys somehow empty");
539539
let deps = vid_map.remove(&target).expect("Entry somehow missing");
540540

541541
for smaller in deps.smaller.iter() {

src/librustc/traits/error_reporting/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
5454
span,
5555
predicates
5656
.iter()
57-
.map(|predicate| ErrorDescriptor {
58-
predicate: predicate.clone(),
59-
index: None,
60-
})
57+
.map(|&predicate| ErrorDescriptor { predicate, index: None })
6158
.collect(),
6259
)
6360
})
@@ -73,7 +70,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
7370
}
7471

7572
error_map.entry(span).or_default().push(ErrorDescriptor {
76-
predicate: error.obligation.predicate.clone(),
73+
predicate: error.obligation.predicate,
7774
index: Some(index),
7875
});
7976

@@ -137,7 +134,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
137134
}
138135
};
139136

140-
for implication in super::elaborate_predicates(self.tcx, vec![cond.clone()]) {
137+
for implication in super::elaborate_predicates(self.tcx, vec![*cond]) {
141138
if let ty::Predicate::Trait(implication, _) = implication {
142139
let error = error.to_poly_trait_ref();
143140
let implication = implication.to_poly_trait_ref();

src/librustc/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
377377
let normalized_ty = normalize_projection_type(
378378
self.selcx,
379379
self.param_env,
380-
data.clone(),
380+
*data,
381381
self.cause.clone(),
382382
self.depth,
383383
&mut self.obligations,
@@ -433,7 +433,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
433433
opt_normalize_projection_type(
434434
selcx,
435435
param_env,
436-
projection_ty.clone(),
436+
projection_ty,
437437
cause.clone(),
438438
depth,
439439
obligations,

src/librustc/traits/select.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
20682068
}
20692069
}
20702070

2071-
_ => candidates.vec.push(AutoImplCandidate(def_id.clone())),
2071+
_ => candidates.vec.push(AutoImplCandidate(def_id)),
20722072
}
20732073
}
20742074

@@ -2132,10 +2132,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21322132
// but `Foo` is declared as `trait Foo: Bar<u32>`.
21332133
let upcast_trait_refs = util::supertraits(self.tcx(), poly_trait_ref)
21342134
.filter(|upcast_trait_ref| {
2135-
self.infcx.probe(|_| {
2136-
let upcast_trait_ref = upcast_trait_ref.clone();
2137-
self.match_poly_trait_ref(obligation, upcast_trait_ref).is_ok()
2138-
})
2135+
self.infcx
2136+
.probe(|_| self.match_poly_trait_ref(obligation, *upcast_trait_ref).is_ok())
21392137
})
21402138
.count();
21412139

@@ -2243,7 +2241,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22432241
let def_id = obligation.predicate.def_id();
22442242

22452243
if self.tcx().is_trait_alias(def_id) {
2246-
candidates.vec.push(TraitAliasCandidate(def_id.clone()));
2244+
candidates.vec.push(TraitAliasCandidate(def_id));
22472245
}
22482246

22492247
Ok(())
@@ -3249,7 +3247,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
32493247
obligation_trait_ref: ty::PolyTraitRef<'tcx>,
32503248
expected_trait_ref: ty::PolyTraitRef<'tcx>,
32513249
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
3252-
let obligation_trait_ref = obligation_trait_ref.clone();
32533250
self.infcx
32543251
.at(&obligation_cause, obligation_param_env)
32553252
.sup(obligation_trait_ref, expected_trait_ref)

src/librustc/traits/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,11 @@ pub fn predicates_for_generics<'tcx>(
526526
generic_bounds
527527
.predicates
528528
.iter()
529-
.map(|predicate| Obligation {
529+
.map(|&predicate| Obligation {
530530
cause: cause.clone(),
531531
recursion_depth,
532532
param_env,
533-
predicate: predicate.clone(),
533+
predicate,
534534
})
535535
.collect()
536536
}

src/librustc/traits/wf.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
318318
if let Elaborate::All = elaborate {
319319
let trait_assoc_items = tcx.associated_items(trait_ref.def_id);
320320

321-
let predicates =
322-
obligations.iter().map(|obligation| obligation.predicate.clone()).collect();
321+
let predicates = obligations.iter().map(|obligation| obligation.predicate).collect();
323322
let implied_obligations = traits::elaborate_predicates(tcx, predicates);
324323
let implied_obligations = implied_obligations.map(|pred| {
325324
let mut cause = cause.clone();

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ impl<'tcx> TyCtxt<'tcx> {
12941294
// statements within the query system and we'd run into endless
12951295
// recursion otherwise.
12961296
let (crate_name, crate_disambiguator) = if def_id.is_local() {
1297-
(self.crate_name.clone(), self.sess.local_crate_disambiguator())
1297+
(self.crate_name, self.sess.local_crate_disambiguator())
12981298
} else {
12991299
(
13001300
self.cstore.crate_name_untracked(def_id.krate),

src/librustc/ty/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ pub trait ToPolyTraitRef<'tcx> {
13261326

13271327
impl<'tcx> ToPolyTraitRef<'tcx> for TraitRef<'tcx> {
13281328
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx> {
1329-
ty::Binder::dummy(self.clone())
1329+
ty::Binder::dummy(*self)
13301330
}
13311331
}
13321332

@@ -1372,19 +1372,19 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&PolyTraitRef<'tcx>> {
13721372

13731373
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
13741374
fn to_predicate(&self) -> Predicate<'tcx> {
1375-
Predicate::RegionOutlives(self.clone())
1375+
Predicate::RegionOutlives(*self)
13761376
}
13771377
}
13781378

13791379
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
13801380
fn to_predicate(&self) -> Predicate<'tcx> {
1381-
Predicate::TypeOutlives(self.clone())
1381+
Predicate::TypeOutlives(*self)
13821382
}
13831383
}
13841384

13851385
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
13861386
fn to_predicate(&self) -> Predicate<'tcx> {
1387-
Predicate::Projection(self.clone())
1387+
Predicate::Projection(*self)
13881388
}
13891389
}
13901390

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
838838

839839
pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
840840
// Note that we preserve binding levels
841-
Binder(ty::TraitPredicate { trait_ref: self.skip_binder().clone() })
841+
Binder(ty::TraitPredicate { trait_ref: *self.skip_binder() })
842842
}
843843
}
844844

src/librustc_builtin_macros/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ impl<'a, 'b> Context<'a, 'b> {
708708
// Before consuming the expressions, we have to remember spans for
709709
// count arguments as they are now generated separate from other
710710
// arguments, hence have no access to the `P<ast::Expr>`'s.
711-
let spans_pos: Vec<_> = self.args.iter().map(|e| e.span.clone()).collect();
711+
let spans_pos: Vec<_> = self.args.iter().map(|e| e.span).collect();
712712

713713
// Right now there is a bug such that for the expression:
714714
// foo(bar(&1))

src/librustc_errors/emitter.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ pub trait Emitter {
400400
}
401401
if sm.span_to_filename(sp_label.span.clone()).is_macros() && !always_backtrace {
402402
if let Some(use_site) = sp_label.span.macro_backtrace().last() {
403-
before_after.push((sp_label.span.clone(), use_site.call_site.clone()));
403+
before_after.push((sp_label.span, use_site.call_site));
404404
}
405405
}
406406
}
@@ -1184,13 +1184,13 @@ impl EmitterWriter {
11841184
let level_str = level.to_string();
11851185
// The failure note level itself does not provide any useful diagnostic information
11861186
if *level != Level::FailureNote && !level_str.is_empty() {
1187-
buffer.append(0, &level_str, Style::Level(level.clone()));
1187+
buffer.append(0, &level_str, Style::Level(*level));
11881188
}
11891189
// only render error codes, not lint codes
11901190
if let Some(DiagnosticId::Error(ref code)) = *code {
1191-
buffer.append(0, "[", Style::Level(level.clone()));
1192-
buffer.append(0, &code, Style::Level(level.clone()));
1193-
buffer.append(0, "]", Style::Level(level.clone()));
1191+
buffer.append(0, "[", Style::Level(*level));
1192+
buffer.append(0, &code, Style::Level(*level));
1193+
buffer.append(0, "]", Style::Level(*level));
11941194
}
11951195
if *level != Level::FailureNote && !level_str.is_empty() {
11961196
buffer.append(0, ": ", header_style);
@@ -1495,7 +1495,7 @@ impl EmitterWriter {
14951495
// Render the suggestion message
14961496
let level_str = level.to_string();
14971497
if !level_str.is_empty() {
1498-
buffer.append(0, &level_str, Style::Level(level.clone()));
1498+
buffer.append(0, &level_str, Style::Level(*level));
14991499
buffer.append(0, ": ", Style::HeaderMsg);
15001500
}
15011501
self.msg_to_buffer(

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
691691
let root_place_projection = self.infcx.tcx.intern_place_elems(root_place.projection);
692692

693693
if self.access_place_error_reported.contains(&(
694-
Place { local: root_place.local.clone(), projection: root_place_projection },
694+
Place { local: *root_place.local, projection: root_place_projection },
695695
borrow_span,
696696
)) {
697697
debug!(
@@ -702,7 +702,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
702702
}
703703

704704
self.access_place_error_reported.insert((
705-
Place { local: root_place.local.clone(), projection: root_place_projection },
705+
Place { local: *root_place.local, projection: root_place_projection },
706706
borrow_span,
707707
));
708708

src/librustc_mir/borrow_check/diagnostics/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
178178
};
179179
grouped_errors.push(GroupedMoveError::MovesFromPlace {
180180
span,
181-
move_from: match_place.clone(),
181+
move_from: *match_place,
182182
original_path,
183183
kind,
184184
binds_to,

src/librustc_mir/borrow_check/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
883883
// Check is_empty() first because it's the common case, and doing that
884884
// way we avoid the clone() call.
885885
if !self.access_place_error_reported.is_empty()
886-
&& self.access_place_error_reported.contains(&(place_span.0.clone(), place_span.1))
886+
&& self.access_place_error_reported.contains(&(*place_span.0, place_span.1))
887887
{
888888
debug!(
889889
"access_place: suppressing error place_span=`{:?}` kind=`{:?}`",
@@ -911,7 +911,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
911911
if conflict_error || mutability_error {
912912
debug!("access_place: logging error place_span=`{:?}` kind=`{:?}`", place_span, kind);
913913

914-
self.access_place_error_reported.insert((place_span.0.clone(), place_span.1));
914+
self.access_place_error_reported.insert((*place_span.0, place_span.1));
915915
}
916916
}
917917

@@ -1011,10 +1011,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10111011
// the 2018 edition so we emit it as a warning. We buffer
10121012
// these sepately so that we only emit a warning if borrow
10131013
// checking was otherwise successful.
1014-
this.reservation_warnings.insert(
1015-
bi,
1016-
(place_span.0.clone(), place_span.1, location, bk, borrow.clone()),
1017-
);
1014+
this.reservation_warnings
1015+
.insert(bi, (*place_span.0, place_span.1, location, bk, borrow.clone()));
10181016

10191017
// Don't suppress actual errors.
10201018
Control::Continue

0 commit comments

Comments
 (0)