Point at the type that doesn't impl Clone in more cases beyond closures

This commit is contained in:
Esteban Küber 2025-07-21 16:53:31 +00:00
parent dafc9f9b53
commit 6237e735c4
3 changed files with 12 additions and 15 deletions

View File

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

View File

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

View File

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