Skip to content

Commit

Permalink
Move suggest_hoisting_call_outside_loop out of suggest_cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 17, 2024
1 parent da2364d commit 3b237d7
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} else if let UseSpans::FnSelfUse { kind: CallKind::Normal { .. }, .. } = move_spans
{
// We already suggest cloning for these cases in `explain_captures`.
} else {
} else if self.suggest_hoisting_call_outside_loop(err, expr) {
// The place where the the type moves would be misleading to suggest clone.
// #121466
self.suggest_cloning(err, ty, expr, move_span);
}
}
Expand Down Expand Up @@ -977,11 +979,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

fn suggest_cloning(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, expr: &hir::Expr<'_>, span: Span) {
let tcx = self.infcx.tcx;
if !self.suggest_hoisting_call_outside_loop(err, expr) {
// The place where the the type moves would be misleading to suggest clone. (#121466)
return;
}

// Try to find predicates on *generic params* that would allow copying `ty`
let suggestion =
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
Expand Down

0 comments on commit 3b237d7

Please sign in to comment.