Skip to content

Commit

Permalink
Rollup merge of rust-lang#55358 - sinkuu:redundant_clone2, r=estebank
Browse files Browse the repository at this point in the history
Remove redundant clone (2)
  • Loading branch information
kennytm committed Oct 26, 2018
2 parents 9c55a4a + 3878d24 commit 626b496
Show file tree
Hide file tree
Showing 35 changed files with 56 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,8 +1447,8 @@ impl Step for Extended {
tarballs.extend(rls_installer.clone());
tarballs.extend(clippy_installer.clone());
tarballs.extend(rustfmt_installer.clone());
tarballs.extend(llvm_tools_installer.clone());
tarballs.extend(lldb_installer.clone());
tarballs.extend(llvm_tools_installer);
tarballs.extend(lldb_installer);
tarballs.push(analysis_installer);
tarballs.push(std_installer);
if builder.config.docs {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ impl Step for Compiletest {
let hostflags = flags.clone();
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));

let mut targetflags = flags.clone();
let mut targetflags = flags;
targetflags.push(format!(
"-Lnative={}",
builder.test_helpers_out(target).display()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ where
);
debug!("projection_must_outlive: unique declared bound appears in trait ref");
self.delegate
.push_sub_region_constraint(origin.clone(), region, unique_bound);
.push_sub_region_constraint(origin, region, unique_bound);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
a // LUB(a,a) = a
}

_ => self.combine_vars(tcx, Lub, a, b, origin.clone()),
_ => self.combine_vars(tcx, Lub, a, b, origin),
}
}

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

_ => self.combine_vars(tcx, Glb, a, b, origin.clone()),
_ => self.combine_vars(tcx, Glb, a, b, origin),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

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

if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(

// But for now, let's classify this as an overflow:
let recursion_limit = *selcx.tcx().sess.recursion_limit.get();
let obligation = Obligation::with_depth(cause.clone(),
let obligation = Obligation::with_depth(cause,
recursion_limit,
param_env,
projection_ty);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
cstore,
global_arenas: &arenas.global,
global_interners: interners,
dep_graph: dep_graph.clone(),
dep_graph,
types: common_types,
trait_map,
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
let mut err = self.cannot_act_on_moved_value(use_span,
verb,
msg,
Some(nl.to_string()),
Some(nl),
Origin::Ast);
let need_note = match lp.ty.sty {
ty::Closure(id, _) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_borrowck/borrowck/move_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
lp = base_lp.clone();
}

self.add_move_helper(tcx, orig_lp.clone(), id, kind);
self.add_move_helper(tcx, orig_lp, id, kind);
}

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

let path_index = self.move_path(tcx, lp.clone());
let path_index = self.move_path(tcx, lp);
let move_index = MoveIndex(self.moves.borrow().len());

let next_move = self.path_first_move(path_index);
Expand Down Expand Up @@ -402,7 +402,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
}
}

self.add_assignment_helper(tcx, lp.clone(), assign_id, span);
self.add_assignment_helper(tcx, lp, assign_id, span);
}

fn add_assignment_helper(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
!tcx.sess.opts.output_types.should_codegen() {
let ongoing_codegen = write::start_async_codegen(
tcx,
time_graph.clone(),
time_graph,
metadata,
rx,
1);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_utils/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn filename_for_input(sess: &Session,
let suffix = &sess.target.target.options.exe_suffix;
let out_filename = outputs.path(OutputType::Exe);
if suffix.is_empty() {
out_filename.to_path_buf()
out_filename
} else {
out_filename.with_extension(&suffix[1..])
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
ProjectionElem::Index(..)
| ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Subslice { .. } => {
self.describe_field(&proj.base, field).to_string()
self.describe_field(&proj.base, field)
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
block,
Statement {
source_info,
kind: StatementKind::FakeRead(FakeReadCause::ForLet, place.clone()),
kind: StatementKind::FakeRead(FakeReadCause::ForLet, place),
},
);

Expand Down Expand Up @@ -314,7 +314,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
Statement {
source_info: ty_source_info,
kind: StatementKind::AscribeUserType(
place.clone(),
place,
ty::Variance::Invariant,
box ascription_user_ty,
),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let ref_ty = self.hir.tcx().mk_ref(region, tam);

// let lhs_ref_place = &lhs;
let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place.clone());
let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place);
let lhs_ref_place = self.temp(ref_ty, test.span);
self.cfg.push_assign(block, source_info, &lhs_ref_place, ref_rvalue);
let val = Operand::Move(lhs_ref_place);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
}).collect()
});

let mut builder = Builder::new(hir.clone(),
let mut builder = Builder::new(hir,
span,
arguments.len(),
safety,
Expand Down Expand Up @@ -714,7 +714,7 @@ fn construct_const<'a, 'gcx, 'tcx>(
let ty = hir.tables().expr_ty_adjusted(ast_expr);
let owner_id = tcx.hir.body_owner(body_id);
let span = tcx.hir.span(owner_id);
let mut builder = Builder::new(hir.clone(), span, 0, Safety::Safe, ty, ty_span,vec![]);
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span,vec![]);

let mut block = START_BLOCK;
let expr = builder.hir.mirror(ast_expr);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
// `dest[i] = Clone::clone(src[beg])`;
// Goto #3 if ok, #5 if unwinding happens.
let dest_field = dest.clone().index(beg);
let src_field = src.clone().index(beg);
let src_field = src.index(beg);
self.make_clone_call(dest_field, src_field, ty, BasicBlock::new(3),
BasicBlock::new(5));

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/util/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,11 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
self.place.clone()
)));
drop_block_stmts.push(self.assign(&cur, Rvalue::Cast(
CastKind::Misc, Operand::Move(tmp.clone()), iter_ty
CastKind::Misc, Operand::Move(tmp), iter_ty
)));
drop_block_stmts.push(self.assign(&length_or_end,
Rvalue::BinaryOp(BinOp::Offset,
Operand::Copy(cur.clone()), Operand::Move(length.clone())
Operand::Copy(cur), Operand::Move(length)
)));
} else {
// index = 0 (length already pushed)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
};
this.add_import_directive(
base.into_iter().collect(),
subclass.clone(),
subclass,
source.ident.span,
id,
root_use_tree.span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
tcx: save_ctxt.tcx,
save_ctxt,
dumper,
span: span_utils.clone(),
span: span_utils,
cur_scope: CRATE_NODE_ID,
// mac_defs: FxHashSet::default(),
macro_calls: FxHashSet::default(),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ impl ToJson for Target {
macro_rules! target_val {
($attr:ident) => ( {
let name = (stringify!($attr)).replace("_", "-");
d.insert(name.to_string(), self.$attr.to_json());
d.insert(name, self.$attr.to_json());
} );
($attr:ident, $key_name:expr) => ( {
let name = $key_name;
Expand All @@ -1144,7 +1144,7 @@ impl ToJson for Target {
($attr:ident) => ( {
let name = (stringify!($attr)).replace("_", "-");
if default.$attr != self.options.$attr {
d.insert(name.to_string(), self.options.$attr.to_json());
d.insert(name, self.options.$attr.to_json());
}
} );
($attr:ident, $key_name:expr) => ( {
Expand All @@ -1160,7 +1160,7 @@ impl ToJson for Target {
.iter()
.map(|(k, v)| (k.desc().to_owned(), v.clone()))
.collect::<BTreeMap<_, _>>();
d.insert(name.to_string(), obj.to_json());
d.insert(name, obj.to_json());
}
} );
(env - $attr:ident) => ( {
Expand All @@ -1170,7 +1170,7 @@ impl ToJson for Target {
.iter()
.map(|&(ref k, ref v)| k.clone() + "=" + &v)
.collect::<Vec<_>>();
d.insert(name.to_string(), obj.to_json());
d.insert(name, obj.to_json());
}
} );

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
let suggested_limit = *tcx.sess.recursion_limit.get() * 2;
let msg = format!("reached the recursion limit while auto-dereferencing {:?}",
self.cur_ty);
let error_id = (DiagnosticMessageId::ErrorId(55), Some(self.span), msg.clone());
let error_id = (DiagnosticMessageId::ErrorId(55), Some(self.span), msg);
let fresh = tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
if fresh {
struct_span_err!(tcx.sess,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
diag.span_suggestion_with_applicability(
impl_err_span,
"consider change the type to match the mutability in trait",
trait_err_str.to_string(),
trait_err_str,
Applicability::MachineApplicable,
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {

// Convert the bounds into obligations.
let impl_obligations = traits::predicates_for_generics(
cause.clone(), self.param_env, &impl_bounds);
cause, self.param_env, &impl_bounds);

debug!("impl_obligations={:?}", impl_obligations);
impl_obligations.into_iter()
Expand All @@ -1175,7 +1175,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
TraitCandidate(trait_ref) => {
let predicate = trait_ref.to_predicate();
let obligation =
traits::Obligation::new(cause.clone(), self.param_env, predicate);
traits::Obligation::new(cause, self.param_env, predicate);
if !self.predicate_may_hold(&obligation) {
if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) {
// This candidate's primary obligation doesn't even
Expand Down
16 changes: 4 additions & 12 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4752,25 +4752,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} else if !self.check_for_cast(err, expr, found, expected) {
let methods = self.get_conversion_methods(expr.span, expected, found);
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
let suggestions = iter::repeat(expr_text).zip(methods.iter())
let suggestions = iter::repeat(&expr_text).zip(methods.iter())
.filter_map(|(receiver, method)| {
let method_call = format!(".{}()", method.ident);
if receiver.ends_with(&method_call) {
None // do not suggest code that is already there (#53348)
} else {
/*
methods defined in `method_call_list` will overwrite
`.clone()` in copy of `receiver`
*/
let method_call_list = [".to_vec()", ".to_string()"];
if receiver.ends_with(".clone()")
&& method_call_list.contains(&method_call.as_str()){
// created copy of `receiver` because we don't want other
// suggestion to get affected
let mut new_receiver = receiver.clone();
let max_len = new_receiver.rfind(".").unwrap();
new_receiver.truncate(max_len);
Some(format!("{}{}", new_receiver, method_call))
&& method_call_list.contains(&method_call.as_str()) {
let max_len = receiver.rfind(".").unwrap();
Some(format!("{}{}", &receiver[..max_len], method_call))
}
else {
Some(format!("{}{}", receiver, method_call))
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> {
.into_iter()
.chain(self.get_auto_trait_impl_for(
def_id,
name.clone(),
name,
generics.clone(),
def_ctor,
tcx.require_lang_item(lang_items::SyncTraitLangItem),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
}
let ty = self.cx.tcx.type_of(def_id);
let generics = self.cx.tcx.generics_of(def_id);
let real_name = name.clone().map(|name| Ident::from_str(&name));
let real_name = name.map(|name| Ident::from_str(&name));
let param_env = self.cx.tcx.param_env(def_id);
for &trait_def_id in self.cx.all_traits.iter() {
if !self.cx.renderinfo.borrow().access_levels.is_doc_reachable(trait_def_id) ||
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
);
let may_apply = match infcx.evaluate_obligation(
&traits::Obligation::new(
cause.clone(),
cause,
param_env,
trait_ref.to_predicate(),
),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3611,7 +3611,7 @@ impl ToSource for syntax_pos::Span {
fn to_src(&self, cx: &DocContext) -> String {
debug!("converting span {:?} to snippet", self.clean(cx));
let sn = match cx.sess().source_map().span_to_snippet(*self) {
Ok(x) => x.to_string(),
Ok(x) => x,
Err(_) => String::new()
};
debug!("got snippet {}", sn);
Expand Down
Loading

0 comments on commit 626b496

Please sign in to comment.