about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-07-21 16:53:31 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-07-23 16:04:45 +0000
commit6237e735c4dc165b3efec236e11a44bdccf1dfd7 (patch)
tree1478963bdcdf1d3655524a5387aeffce5c1b1549
parentdafc9f9b534c8d1a50ba87f776eb1d6dfb1a7c94 (diff)
downloadrust-6237e735c4dc165b3efec236e11a44bdccf1dfd7.tar.gz
rust-6237e735c4dc165b3efec236e11a44bdccf1dfd7.zip
Point at the type that doesn't impl `Clone` in more cases beyond closures
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/move_errors.rs15
-rw-r--r--tests/ui/async-await/async-closures/closure-shim-borrowck-error.stderr7
-rw-r--r--tests/ui/async-await/async-closures/move-out-of-ref.stderr5
3 files changed, 12 insertions, 15 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
index 67dce7615c0..a0c1f66d35c 100644
--- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
@@ -596,9 +596,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
                 self.add_move_error_details(err, &binds_to);
             }
             // No binding. Nothing to suggest.
-            GroupedMoveError::OtherIllegalMove {
-                ref original_path, use_spans, ref kind, ..
-            } => {
+            GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => {
                 let mut use_span = use_spans.var_or_use();
                 let place_ty = original_path.ty(self.body, self.infcx.tcx).ty;
                 let place_desc = match self.describe_place(original_path.as_ref()) {
@@ -616,14 +614,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
                     );
                 }
 
-                if let IllegalMoveOriginKind::BorrowedContent { target_place } = &kind
-                    && let ty = target_place.ty(self.body, self.infcx.tcx).ty
-                    && let ty::Closure(def_id, _) = ty.kind()
-                    && def_id.as_local() == Some(self.mir_def_id())
-                    && let Some(upvar_field) = self
-                        .prefixes(original_path.as_ref(), PrefixSet::All)
-                        .find_map(|p| self.is_upvar_field_projection(p))
+                if let Some(upvar_field) = self
+                    .prefixes(original_path.as_ref(), PrefixSet::All)
+                    .find_map(|p| self.is_upvar_field_projection(p))
                 {
+                    // Look for the introduction of the original binding being moved.
                     let upvar = &self.upvars[upvar_field.index()];
                     let upvar_hir_id = upvar.get_root_variable();
                     use_span = match self.infcx.tcx.parent_hir_node(upvar_hir_id) {
diff --git a/tests/ui/async-await/async-closures/closure-shim-borrowck-error.stderr b/tests/ui/async-await/async-closures/closure-shim-borrowck-error.stderr
index 03fa220b0bf..3fe1431fda7 100644
--- a/tests/ui/async-await/async-closures/closure-shim-borrowck-error.stderr
+++ b/tests/ui/async-await/async-closures/closure-shim-borrowck-error.stderr
@@ -1,14 +1,13 @@
 error[E0507]: cannot move out of `x` which is behind a mutable reference
   --> $DIR/closure-shim-borrowck-error.rs:11:18
    |
+LL | fn hello(x: Ty) {
+   |             -- move occurs because `x` has type `Ty`, which does not implement the `Copy` trait
 LL |     needs_fn_mut(async || {
    |                  ^^^^^^^^ `x` is moved here
 LL |
 LL |         x.hello();
-   |         -
-   |         |
-   |         variable moved due to use in coroutine
-   |         move occurs because `x` has type `Ty`, which does not implement the `Copy` trait
+   |         - variable moved due to use in coroutine
    |
 note: if `Ty` implemented `Clone`, you could clone the value
   --> $DIR/closure-shim-borrowck-error.rs:17:1
diff --git a/tests/ui/async-await/async-closures/move-out-of-ref.stderr b/tests/ui/async-await/async-closures/move-out-of-ref.stderr
index 8a63515a8a9..d443dc9d483 100644
--- a/tests/ui/async-await/async-closures/move-out-of-ref.stderr
+++ b/tests/ui/async-await/async-closures/move-out-of-ref.stderr
@@ -1,8 +1,11 @@
 error[E0507]: cannot move out of `*x` which is behind a shared reference
   --> $DIR/move-out-of-ref.rs:9:9
    |
+LL | fn hello(x: &Ty) {
+   |             --- move occurs because `*x` has type `Ty`, which does not implement the `Copy` trait
+LL |     let c = async || {
 LL |         *x;
-   |         ^^ move occurs because `*x` has type `Ty`, which does not implement the `Copy` trait
+   |         ^^ `*x` is moved here
    |
 note: if `Ty` implemented `Clone`, you could clone the value
   --> $DIR/move-out-of-ref.rs:5:1