Point at the type that doesn't impl Clone in more cases beyond closures
This commit is contained in:
@@ -596,9 +596,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
self.add_move_error_details(err, &binds_to);
|
self.add_move_error_details(err, &binds_to);
|
||||||
}
|
}
|
||||||
// No binding. Nothing to suggest.
|
// No binding. Nothing to suggest.
|
||||||
GroupedMoveError::OtherIllegalMove {
|
GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => {
|
||||||
ref original_path, use_spans, ref kind, ..
|
|
||||||
} => {
|
|
||||||
let mut use_span = use_spans.var_or_use();
|
let mut use_span = use_spans.var_or_use();
|
||||||
let place_ty = original_path.ty(self.body, self.infcx.tcx).ty;
|
let place_ty = original_path.ty(self.body, self.infcx.tcx).ty;
|
||||||
let place_desc = match self.describe_place(original_path.as_ref()) {
|
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
|
if let Some(upvar_field) = self
|
||||||
&& 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)
|
.prefixes(original_path.as_ref(), PrefixSet::All)
|
||||||
.find_map(|p| self.is_upvar_field_projection(p))
|
.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 = &self.upvars[upvar_field.index()];
|
||||||
let upvar_hir_id = upvar.get_root_variable();
|
let upvar_hir_id = upvar.get_root_variable();
|
||||||
use_span = match self.infcx.tcx.parent_hir_node(upvar_hir_id) {
|
use_span = match self.infcx.tcx.parent_hir_node(upvar_hir_id) {
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
error[E0507]: cannot move out of `x` which is behind a mutable reference
|
error[E0507]: cannot move out of `x` which is behind a mutable reference
|
||||||
--> $DIR/closure-shim-borrowck-error.rs:11:18
|
--> $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 || {
|
LL | needs_fn_mut(async || {
|
||||||
| ^^^^^^^^ `x` is moved here
|
| ^^^^^^^^ `x` is moved here
|
||||||
LL |
|
LL |
|
||||||
LL | x.hello();
|
LL | x.hello();
|
||||||
| -
|
| - variable moved due to use in coroutine
|
||||||
| |
|
|
||||||
| variable moved due to use in coroutine
|
|
||||||
| move occurs because `x` has type `Ty`, which does not implement the `Copy` trait
|
|
||||||
|
|
|
|
||||||
note: if `Ty` implemented `Clone`, you could clone the value
|
note: if `Ty` implemented `Clone`, you could clone the value
|
||||||
--> $DIR/closure-shim-borrowck-error.rs:17:1
|
--> $DIR/closure-shim-borrowck-error.rs:17:1
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
error[E0507]: cannot move out of `*x` which is behind a shared reference
|
error[E0507]: cannot move out of `*x` which is behind a shared reference
|
||||||
--> $DIR/move-out-of-ref.rs:9:9
|
--> $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;
|
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
|
note: if `Ty` implemented `Clone`, you could clone the value
|
||||||
--> $DIR/move-out-of-ref.rs:5:1
|
--> $DIR/move-out-of-ref.rs:5:1
|
||||||
|
|||||||
Reference in New Issue
Block a user