|
4 | 4 | #![allow(rustc::untranslatable_diagnostic)]
|
5 | 5 |
|
6 | 6 | use either::Either;
|
| 7 | +use hir::ClosureKind; |
7 | 8 | use rustc_data_structures::captures::Captures;
|
8 | 9 | use rustc_data_structures::fx::FxIndexSet;
|
9 | 10 | use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan};
|
@@ -463,6 +464,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
463 | 464 | } else if let UseSpans::FnSelfUse { kind: CallKind::Normal { .. }, .. } = move_spans
|
464 | 465 | {
|
465 | 466 | // We already suggest cloning for these cases in `explain_captures`.
|
| 467 | + } else if let UseSpans::ClosureUse { |
| 468 | + closure_kind: |
| 469 | + ClosureKind::Coroutine(CoroutineKind::Desugared(_, CoroutineSource::Block)), |
| 470 | + args_span: _, |
| 471 | + capture_kind_span: _, |
| 472 | + path_span, |
| 473 | + } = move_spans |
| 474 | + { |
| 475 | + self.suggest_cloning(err, ty, expr, path_span); |
466 | 476 | } else if self.suggest_hoisting_call_outside_loop(err, expr) {
|
467 | 477 | // The place where the the type moves would be misleading to suggest clone.
|
468 | 478 | // #121466
|
@@ -621,7 +631,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
621 | 631 | }
|
622 | 632 |
|
623 | 633 | // FIXME: We make sure that this is a normal top-level binding,
|
624 |
| - // but we could suggest `todo!()` for all uninitalized bindings in the pattern pattern |
| 634 | + // but we could suggest `todo!()` for all uninitialized bindings in the pattern pattern |
625 | 635 | if let hir::StmtKind::Let(hir::LetStmt { span, ty, init: None, pat, .. }) =
|
626 | 636 | &ex.kind
|
627 | 637 | && let hir::PatKind::Binding(..) = pat.kind
|
@@ -749,7 +759,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
749 | 759 | true
|
750 | 760 | }
|
751 | 761 |
|
752 |
| - /// In a move error that occurs on a call wihtin a loop, we try to identify cases where cloning |
| 762 | + /// In a move error that occurs on a call within a loop, we try to identify cases where cloning |
753 | 763 | /// the value would lead to a logic error. We infer these cases by seeing if the moved value is
|
754 | 764 | /// part of the logic to break the loop, either through an explicit `break` or if the expression
|
755 | 765 | /// is part of a `while let`.
|
@@ -950,7 +960,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
950 | 960 | {
|
951 | 961 | // FIXME: We could check that the call's *parent* takes `&mut val` to make the
|
952 | 962 | // suggestion more targeted to the `mk_iter(val).next()` case. Maybe do that only to
|
953 |
| - // check for wheter to suggest `let value` or `let mut value`. |
| 963 | + // check for whether to suggest `let value` or `let mut value`. |
954 | 964 |
|
955 | 965 | let span = in_loop.span;
|
956 | 966 | if !finder.found_breaks.is_empty()
|
|
0 commit comments