Tweak output in for loops
Do not suggest `.clone()` as we already suggest borrowing the iterated value.
This commit is contained in:
parent
c0e481731b
commit
d687d46f68
5 changed files with 11 additions and 19 deletions
|
@ -397,8 +397,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
&& let Some(node) = hir.find(hir.local_def_id_to_hir_id(def_id))
|
||||
&& let Some(fn_sig) = node.fn_sig()
|
||||
&& let Some(ident) = node.ident()
|
||||
&& let Some(pos) = args.iter()
|
||||
.position(|arg| arg.hir_id == expr.hir_id)
|
||||
&& let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
|
||||
&& let Some(arg) = fn_sig.decl.inputs.get(pos + offset)
|
||||
{
|
||||
let mut span: MultiSpan = arg.span.into();
|
||||
|
@ -425,7 +424,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}
|
||||
let place = &self.move_data.move_paths[mpi].place;
|
||||
let ty = place.ty(self.body, self.infcx.tcx).ty;
|
||||
self.suggest_cloning(err, ty, move_span);
|
||||
if let hir::Node::Expr(parent_expr) = parent
|
||||
&& let hir::ExprKind::Call(call_expr, _) = parent_expr.kind
|
||||
&& let hir::ExprKind::Path(
|
||||
hir::QPath::LangItem(LangItem::IntoIterIntoIter, _, _)
|
||||
) = call_expr.kind
|
||||
{
|
||||
// Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
|
||||
} else {
|
||||
self.suggest_cloning(err, ty, move_span);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(pat) = finder.pat && !seen_spans.contains(&pat.span) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue