Remove redundant clone

This commit is contained in:
Shotaro Yamada 2018-10-26 03:11:11 +09:00
parent 7b0735a832
commit 3878d24ef6
35 changed files with 56 additions and 65 deletions

View File

@ -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 {

View File

@ -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()

View File

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

View File

@ -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),
}
}
@ -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),
}
}

View File

@ -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!(
@ -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() {

View File

@ -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);

View File

@ -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)| {

View File

@ -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, _) => {

View File

@ -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>,
@ -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);
@ -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>,

View File

@ -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);

View File

@ -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..])
}

View File

@ -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)
}
},
}

View File

@ -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),
},
);
@ -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,
ascription_user_ty,
),

View File

@ -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);

View File

@ -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,
@ -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);

View File

@ -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));

View File

@ -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)

View File

@ -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,

View File

@ -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(),

View File

@ -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;
@ -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) => ( {
@ -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) => ( {
@ -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());
}
} );

View File

@ -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,

View File

@ -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,
);
}

View File

@ -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()
@ -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

View File

@ -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))

View File

@ -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),

View File

@ -66,7 +66,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) ||
@ -109,7 +109,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(),
),

View File

@ -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);

View File

@ -521,7 +521,7 @@ pub fn run(mut krate: clean::Crate,
external_html: external_html.clone(),
krate: krate.name.clone(),
},
css_file_extension: css_file_extension.clone(),
css_file_extension,
created_dirs: Default::default(),
sort_modules_alphabetically,
themes,
@ -1343,7 +1343,7 @@ impl DocFolder for Cache {
self.search_index.push(IndexItem {
ty: item.type_(),
name: s.to_string(),
path: path.join("::").to_string(),
path: path.join("::"),
desc: plain_summary_line(item.doc_value()),
parent,
parent_idx: None,
@ -2283,7 +2283,7 @@ fn document_short(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, link
format!("{} [Read more]({})",
&plain_summary_line(Some(s)), naive_assoc_href(item, link))
} else {
plain_summary_line(Some(s)).to_string()
plain_summary_line(Some(s))
};
render_markdown(w, cx, &markdown, item.links(), prefix)?;
} else if !prefix.is_empty() {
@ -2435,7 +2435,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
// (which is the position in the vector).
indices.dedup_by_key(|i| (items[*i].def_id,
if items[*i].name.as_ref().is_some() {
Some(full_path(cx, &items[*i]).clone())
Some(full_path(cx, &items[*i]))
} else {
None
},

View File

@ -460,7 +460,7 @@ fn main_args(args: &[String]) -> isize {
let externs = match parse_externs(&matches) {
Ok(ex) => ex,
Err(err) => {
diag.struct_err(&err.to_string()).emit();
diag.struct_err(&err).emit();
return 1;
}
};

View File

@ -208,7 +208,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
// needs to be the result of SourceMap::span_to_unmapped_path
let input = config::Input::Str {
name: filename.to_owned(),
input: test.to_owned(),
input: test,
};
let outputs = OutputTypes::new(&[(OutputType::Exe, None)]);
@ -350,7 +350,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
let newpath = {
let path = env::var_os(var).unwrap_or(OsString::new());
let mut path = env::split_paths(&path).collect::<Vec<_>>();
path.insert(0, libdir.clone());
path.insert(0, libdir);
env::join_paths(path).unwrap()
};
cmd.env(var, &newpath);

View File

@ -133,8 +133,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
// Replace all the tokens for the corresponding positions in the macro, to maintain
// proper positions in error reporting, while maintaining the macro_backtrace.
if rhs_spans.len() == tts.len() {
tts = tts.map_enumerated(|i, tt| {
let mut tt = tt.clone();
tts = tts.map_enumerated(|i, mut tt| {
let mut sp = rhs_spans[i];
sp = sp.with_ctxt(tt.span().ctxt());
tt.set_span(sp);

View File

@ -219,9 +219,9 @@ impl Add for LockstepIterSize {
LockstepIterSize::Unconstrained => other,
LockstepIterSize::Contradiction(_) => self,
LockstepIterSize::Constraint(l_len, ref l_id) => match other {
LockstepIterSize::Unconstrained => self.clone(),
LockstepIterSize::Unconstrained => self,
LockstepIterSize::Contradiction(_) => other,
LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self.clone(),
LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self,
LockstepIterSize::Constraint(r_len, r_id) => {
let msg = format!("inconsistent lockstep iteration: \
'{}' has {} items, but '{}' has {}",

View File

@ -346,7 +346,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
test_runner.span = sp;
let test_main_path_expr = ecx.expr_path(test_runner.clone());
let test_main_path_expr = ecx.expr_path(test_runner);
let call_test_main = ecx.expr_call(sp, test_main_path_expr,
vec![mk_tests_slice(cx)]);
let call_test_main = ecx.stmt_expr(call_test_main);

View File

@ -178,7 +178,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<
cx.expr_match(span, new, vec![eq_arm, neq_arm])
},
equals_expr.clone(),
equals_expr,
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 {
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")

View File

@ -75,7 +75,7 @@ impl MultiItemModifier for ProcMacroDerive {
// Mark attributes as known, and used.
MarkAttrs(&self.attrs).visit_item(&item);
let input = __internal::new_token_stream(ecx.resolver.eliminate_crate_var(item.clone()));
let input = __internal::new_token_stream(ecx.resolver.eliminate_crate_var(item));
let res = __internal::set_sess(ecx, || {
let inner = self.inner;
panic::catch_unwind(panic::AssertUnwindSafe(|| inner(input)))