mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-03 02:40:40 +00:00
Point at the type that doesn't impl Clone
in more cases beyond closures
This commit is contained in:
parent
dafc9f9b53
commit
6237e735c4
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user