Skip to content

Commit 626b496

Browse files
committed
Rollup merge of rust-lang#55358 - sinkuu:redundant_clone2, r=estebank
Remove redundant clone (2)
2 parents 9c55a4a + 3878d24 commit 626b496

File tree

35 files changed

+56
-65
lines changed

35 files changed

+56
-65
lines changed

src/bootstrap/dist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1447,8 +1447,8 @@ impl Step for Extended {
14471447
tarballs.extend(rls_installer.clone());
14481448
tarballs.extend(clippy_installer.clone());
14491449
tarballs.extend(rustfmt_installer.clone());
1450-
tarballs.extend(llvm_tools_installer.clone());
1451-
tarballs.extend(lldb_installer.clone());
1450+
tarballs.extend(llvm_tools_installer);
1451+
tarballs.extend(lldb_installer);
14521452
tarballs.push(analysis_installer);
14531453
tarballs.push(std_installer);
14541454
if builder.config.docs {

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ impl Step for Compiletest {
10521052
let hostflags = flags.clone();
10531053
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
10541054

1055-
let mut targetflags = flags.clone();
1055+
let mut targetflags = flags;
10561056
targetflags.push(format!(
10571057
"-Lnative={}",
10581058
builder.test_helpers_out(target).display()

src/librustc/infer/outlives/obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ where
458458
);
459459
debug!("projection_must_outlive: unique declared bound appears in trait ref");
460460
self.delegate
461-
.push_sub_region_constraint(origin.clone(), region, unique_bound);
461+
.push_sub_region_constraint(origin, region, unique_bound);
462462
return;
463463
}
464464

src/librustc/infer/region_constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
749749
a // LUB(a,a) = a
750750
}
751751

752-
_ => self.combine_vars(tcx, Lub, a, b, origin.clone()),
752+
_ => self.combine_vars(tcx, Lub, a, b, origin),
753753
}
754754
}
755755

@@ -771,7 +771,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
771771
a // GLB(a,a) = a
772772
}
773773

774-
_ => self.combine_vars(tcx, Glb, a, b, origin.clone()),
774+
_ => self.combine_vars(tcx, Glb, a, b, origin),
775775
}
776776
}
777777

src/librustc/traits/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
239239

240240
let msg = format!("type mismatch resolving `{}`", predicate);
241241
let error_id = (DiagnosticMessageId::ErrorId(271),
242-
Some(obligation.cause.span), msg.clone());
242+
Some(obligation.cause.span), msg);
243243
let fresh = self.tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
244244
if fresh {
245245
let mut diag = struct_span_err!(
@@ -379,7 +379,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
379379
}
380380
}
381381
if let Some(t) = self.get_parent_trait_ref(&obligation.cause.code) {
382-
flags.push(("parent_trait".to_owned(), Some(t.to_string())));
382+
flags.push(("parent_trait".to_owned(), Some(t)));
383383
}
384384

385385
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {

src/librustc/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
594594

595595
// But for now, let's classify this as an overflow:
596596
let recursion_limit = *selcx.tcx().sess.recursion_limit.get();
597-
let obligation = Obligation::with_depth(cause.clone(),
597+
let obligation = Obligation::with_depth(cause,
598598
recursion_limit,
599599
param_env,
600600
projection_ty);

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12001200
cstore,
12011201
global_arenas: &arenas.global,
12021202
global_interners: interners,
1203-
dep_graph: dep_graph.clone(),
1203+
dep_graph,
12041204
types: common_types,
12051205
trait_map,
12061206
export_map: resolutions.export_map.into_iter().map(|(k, v)| {

src/librustc_borrowck/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
695695
let mut err = self.cannot_act_on_moved_value(use_span,
696696
verb,
697697
msg,
698-
Some(nl.to_string()),
698+
Some(nl),
699699
Origin::Ast);
700700
let need_note = match lp.ty.sty {
701701
ty::Closure(id, _) => {

src/librustc_borrowck/borrowck/move_data.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
347347
lp = base_lp.clone();
348348
}
349349

350-
self.add_move_helper(tcx, orig_lp.clone(), id, kind);
350+
self.add_move_helper(tcx, orig_lp, id, kind);
351351
}
352352

353353
fn add_move_helper(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -359,7 +359,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
359359
id,
360360
kind);
361361

362-
let path_index = self.move_path(tcx, lp.clone());
362+
let path_index = self.move_path(tcx, lp);
363363
let move_index = MoveIndex(self.moves.borrow().len());
364364

365365
let next_move = self.path_first_move(path_index);
@@ -402,7 +402,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
402402
}
403403
}
404404

405-
self.add_assignment_helper(tcx, lp.clone(), assign_id, span);
405+
self.add_assignment_helper(tcx, lp, assign_id, span);
406406
}
407407

408408
fn add_assignment_helper(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,

src/librustc_codegen_llvm/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
784784
!tcx.sess.opts.output_types.should_codegen() {
785785
let ongoing_codegen = write::start_async_codegen(
786786
tcx,
787-
time_graph.clone(),
787+
time_graph,
788788
metadata,
789789
rx,
790790
1);

src/librustc_codegen_utils/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn filename_for_input(sess: &Session,
138138
let suffix = &sess.target.target.options.exe_suffix;
139139
let out_filename = outputs.path(OutputType::Exe);
140140
if suffix.is_empty() {
141-
out_filename.to_path_buf()
141+
out_filename
142142
} else {
143143
out_filename.with_extension(&suffix[1..])
144144
}

src/librustc_mir/borrow_check/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16151615
ProjectionElem::Index(..)
16161616
| ProjectionElem::ConstantIndex { .. }
16171617
| ProjectionElem::Subslice { .. } => {
1618-
self.describe_field(&proj.base, field).to_string()
1618+
self.describe_field(&proj.base, field)
16191619
}
16201620
},
16211621
}

src/librustc_mir/build/matches/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
265265
block,
266266
Statement {
267267
source_info,
268-
kind: StatementKind::FakeRead(FakeReadCause::ForLet, place.clone()),
268+
kind: StatementKind::FakeRead(FakeReadCause::ForLet, place),
269269
},
270270
);
271271

@@ -314,7 +314,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
314314
Statement {
315315
source_info: ty_source_info,
316316
kind: StatementKind::AscribeUserType(
317-
place.clone(),
317+
place,
318318
ty::Variance::Invariant,
319319
box ascription_user_ty,
320320
),

src/librustc_mir/build/matches/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
324324
let ref_ty = self.hir.tcx().mk_ref(region, tam);
325325

326326
// let lhs_ref_place = &lhs;
327-
let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place.clone());
327+
let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place);
328328
let lhs_ref_place = self.temp(ref_ty, test.span);
329329
self.cfg.push_assign(block, source_info, &lhs_ref_place, ref_rvalue);
330330
let val = Operand::Move(lhs_ref_place);

src/librustc_mir/build/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
644644
}).collect()
645645
});
646646

647-
let mut builder = Builder::new(hir.clone(),
647+
let mut builder = Builder::new(hir,
648648
span,
649649
arguments.len(),
650650
safety,
@@ -714,7 +714,7 @@ fn construct_const<'a, 'gcx, 'tcx>(
714714
let ty = hir.tables().expr_ty_adjusted(ast_expr);
715715
let owner_id = tcx.hir.body_owner(body_id);
716716
let span = tcx.hir.span(owner_id);
717-
let mut builder = Builder::new(hir.clone(), span, 0, Safety::Safe, ty, ty_span,vec![]);
717+
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span,vec![]);
718718

719719
let mut block = START_BLOCK;
720720
let expr = builder.hir.mirror(ast_expr);

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
547547
// `dest[i] = Clone::clone(src[beg])`;
548548
// Goto #3 if ok, #5 if unwinding happens.
549549
let dest_field = dest.clone().index(beg);
550-
let src_field = src.clone().index(beg);
550+
let src_field = src.index(beg);
551551
self.make_clone_call(dest_field, src_field, ty, BasicBlock::new(3),
552552
BasicBlock::new(5));
553553

src/librustc_mir/util/elaborate_drops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,11 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
753753
self.place.clone()
754754
)));
755755
drop_block_stmts.push(self.assign(&cur, Rvalue::Cast(
756-
CastKind::Misc, Operand::Move(tmp.clone()), iter_ty
756+
CastKind::Misc, Operand::Move(tmp), iter_ty
757757
)));
758758
drop_block_stmts.push(self.assign(&length_or_end,
759759
Rvalue::BinaryOp(BinOp::Offset,
760-
Operand::Copy(cur.clone()), Operand::Move(length.clone())
760+
Operand::Copy(cur), Operand::Move(length)
761761
)));
762762
} else {
763763
// index = 0 (length already pushed)

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
218218
};
219219
this.add_import_directive(
220220
base.into_iter().collect(),
221-
subclass.clone(),
221+
subclass,
222222
source.ident.span,
223223
id,
224224
root_use_tree.span,

src/librustc_save_analysis/dump_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
105105
tcx: save_ctxt.tcx,
106106
save_ctxt,
107107
dumper,
108-
span: span_utils.clone(),
108+
span: span_utils,
109109
cur_scope: CRATE_NODE_ID,
110110
// mac_defs: FxHashSet::default(),
111111
macro_calls: FxHashSet::default(),

src/librustc_target/spec/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ impl ToJson for Target {
11321132
macro_rules! target_val {
11331133
($attr:ident) => ( {
11341134
let name = (stringify!($attr)).replace("_", "-");
1135-
d.insert(name.to_string(), self.$attr.to_json());
1135+
d.insert(name, self.$attr.to_json());
11361136
} );
11371137
($attr:ident, $key_name:expr) => ( {
11381138
let name = $key_name;
@@ -1144,7 +1144,7 @@ impl ToJson for Target {
11441144
($attr:ident) => ( {
11451145
let name = (stringify!($attr)).replace("_", "-");
11461146
if default.$attr != self.options.$attr {
1147-
d.insert(name.to_string(), self.options.$attr.to_json());
1147+
d.insert(name, self.options.$attr.to_json());
11481148
}
11491149
} );
11501150
($attr:ident, $key_name:expr) => ( {
@@ -1160,7 +1160,7 @@ impl ToJson for Target {
11601160
.iter()
11611161
.map(|(k, v)| (k.desc().to_owned(), v.clone()))
11621162
.collect::<BTreeMap<_, _>>();
1163-
d.insert(name.to_string(), obj.to_json());
1163+
d.insert(name, obj.to_json());
11641164
}
11651165
} );
11661166
(env - $attr:ident) => ( {
@@ -1170,7 +1170,7 @@ impl ToJson for Target {
11701170
.iter()
11711171
.map(|&(ref k, ref v)| k.clone() + "=" + &v)
11721172
.collect::<Vec<_>>();
1173-
d.insert(name.to_string(), obj.to_json());
1173+
d.insert(name, obj.to_json());
11741174
}
11751175
} );
11761176

src/librustc_typeck/check/autoderef.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
6161
let suggested_limit = *tcx.sess.recursion_limit.get() * 2;
6262
let msg = format!("reached the recursion limit while auto-dereferencing {:?}",
6363
self.cur_ty);
64-
let error_id = (DiagnosticMessageId::ErrorId(55), Some(self.span), msg.clone());
64+
let error_id = (DiagnosticMessageId::ErrorId(55), Some(self.span), msg);
6565
let fresh = tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
6666
if fresh {
6767
struct_span_err!(tcx.sess,

src/librustc_typeck/check/compare_method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
325325
diag.span_suggestion_with_applicability(
326326
impl_err_span,
327327
"consider change the type to match the mutability in trait",
328-
trait_err_str.to_string(),
328+
trait_err_str,
329329
Applicability::MachineApplicable,
330330
);
331331
}

src/librustc_typeck/check/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
11571157

11581158
// Convert the bounds into obligations.
11591159
let impl_obligations = traits::predicates_for_generics(
1160-
cause.clone(), self.param_env, &impl_bounds);
1160+
cause, self.param_env, &impl_bounds);
11611161

11621162
debug!("impl_obligations={:?}", impl_obligations);
11631163
impl_obligations.into_iter()
@@ -1175,7 +1175,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
11751175
TraitCandidate(trait_ref) => {
11761176
let predicate = trait_ref.to_predicate();
11771177
let obligation =
1178-
traits::Obligation::new(cause.clone(), self.param_env, predicate);
1178+
traits::Obligation::new(cause, self.param_env, predicate);
11791179
if !self.predicate_may_hold(&obligation) {
11801180
if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) {
11811181
// This candidate's primary obligation doesn't even

src/librustc_typeck/check/mod.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -4752,25 +4752,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47524752
} else if !self.check_for_cast(err, expr, found, expected) {
47534753
let methods = self.get_conversion_methods(expr.span, expected, found);
47544754
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
4755-
let suggestions = iter::repeat(expr_text).zip(methods.iter())
4755+
let suggestions = iter::repeat(&expr_text).zip(methods.iter())
47564756
.filter_map(|(receiver, method)| {
47574757
let method_call = format!(".{}()", method.ident);
47584758
if receiver.ends_with(&method_call) {
47594759
None // do not suggest code that is already there (#53348)
47604760
} else {
4761-
/*
4762-
methods defined in `method_call_list` will overwrite
4763-
`.clone()` in copy of `receiver`
4764-
*/
47654761
let method_call_list = [".to_vec()", ".to_string()"];
47664762
if receiver.ends_with(".clone()")
4767-
&& method_call_list.contains(&method_call.as_str()){
4768-
// created copy of `receiver` because we don't want other
4769-
// suggestion to get affected
4770-
let mut new_receiver = receiver.clone();
4771-
let max_len = new_receiver.rfind(".").unwrap();
4772-
new_receiver.truncate(max_len);
4773-
Some(format!("{}{}", new_receiver, method_call))
4763+
&& method_call_list.contains(&method_call.as_str()) {
4764+
let max_len = receiver.rfind(".").unwrap();
4765+
Some(format!("{}{}", &receiver[..max_len], method_call))
47744766
}
47754767
else {
47764768
Some(format!("{}{}", receiver, method_call))

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> {
8484
.into_iter()
8585
.chain(self.get_auto_trait_impl_for(
8686
def_id,
87-
name.clone(),
87+
name,
8888
generics.clone(),
8989
def_ctor,
9090
tcx.require_lang_item(lang_items::SyncTraitLangItem),

src/librustdoc/clean/blanket_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
6767
}
6868
let ty = self.cx.tcx.type_of(def_id);
6969
let generics = self.cx.tcx.generics_of(def_id);
70-
let real_name = name.clone().map(|name| Ident::from_str(&name));
70+
let real_name = name.map(|name| Ident::from_str(&name));
7171
let param_env = self.cx.tcx.param_env(def_id);
7272
for &trait_def_id in self.cx.all_traits.iter() {
7373
if !self.cx.renderinfo.borrow().access_levels.is_doc_reachable(trait_def_id) ||
@@ -112,7 +112,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
112112
);
113113
let may_apply = match infcx.evaluate_obligation(
114114
&traits::Obligation::new(
115-
cause.clone(),
115+
cause,
116116
param_env,
117117
trait_ref.to_predicate(),
118118
),

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3611,7 +3611,7 @@ impl ToSource for syntax_pos::Span {
36113611
fn to_src(&self, cx: &DocContext) -> String {
36123612
debug!("converting span {:?} to snippet", self.clean(cx));
36133613
let sn = match cx.sess().source_map().span_to_snippet(*self) {
3614-
Ok(x) => x.to_string(),
3614+
Ok(x) => x,
36153615
Err(_) => String::new()
36163616
};
36173617
debug!("got snippet {}", sn);

0 commit comments

Comments
 (0)