Skip to content

Commit 493700f

Browse files
committed
Point at the type that doesn't impl Clone in more cases beyond closures
1 parent dafc9f9 commit 493700f

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
597597
}
598598
// No binding. Nothing to suggest.
599599
GroupedMoveError::OtherIllegalMove {
600-
ref original_path, use_spans, ref kind, ..
601-
} => {
600+
ref original_path, use_spans, .. } => {
602601
let mut use_span = use_spans.var_or_use();
603602
let place_ty = original_path.ty(self.body, self.infcx.tcx).ty;
604603
let place_desc = match self.describe_place(original_path.as_ref()) {
@@ -616,14 +615,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
616615
);
617616
}
618617

619-
if let IllegalMoveOriginKind::BorrowedContent { target_place } = &kind
620-
&& let ty = target_place.ty(self.body, self.infcx.tcx).ty
621-
&& let ty::Closure(def_id, _) = ty.kind()
622-
&& def_id.as_local() == Some(self.mir_def_id())
623-
&& let Some(upvar_field) = self
618+
if let Some(upvar_field) = self
624619
.prefixes(original_path.as_ref(), PrefixSet::All)
625620
.find_map(|p| self.is_upvar_field_projection(p))
626621
{
622+
// Look for the introduction of the original binding being moved.
627623
let upvar = &self.upvars[upvar_field.index()];
628624
let upvar_hir_id = upvar.get_root_variable();
629625
use_span = match self.infcx.tcx.parent_hir_node(upvar_hir_id) {

tests/ui/async-await/async-closures/closure-shim-borrowck-error.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
error[E0507]: cannot move out of `x` which is behind a mutable reference
22
--> $DIR/closure-shim-borrowck-error.rs:11:18
33
|
4+
LL | fn hello(x: Ty) {
5+
| -- move occurs because `x` has type `Ty`, which does not implement the `Copy` trait
46
LL | needs_fn_mut(async || {
57
| ^^^^^^^^ `x` is moved here
68
LL |
79
LL | x.hello();
8-
| -
9-
| |
10-
| variable moved due to use in coroutine
11-
| move occurs because `x` has type `Ty`, which does not implement the `Copy` trait
10+
| - variable moved due to use in coroutine
1211
|
1312
note: if `Ty` implemented `Clone`, you could clone the value
1413
--> $DIR/closure-shim-borrowck-error.rs:17:1

tests/ui/async-await/async-closures/move-out-of-ref.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
error[E0507]: cannot move out of `*x` which is behind a shared reference
22
--> $DIR/move-out-of-ref.rs:9:9
33
|
4+
LL | fn hello(x: &Ty) {
5+
| --- move occurs because `*x` has type `Ty`, which does not implement the `Copy` trait
6+
LL | let c = async || {
47
LL | *x;
5-
| ^^ move occurs because `*x` has type `Ty`, which does not implement the `Copy` trait
8+
| ^^ `*x` is moved here
69
|
710
note: if `Ty` implemented `Clone`, you could clone the value
811
--> $DIR/move-out-of-ref.rs:5:1

0 commit comments

Comments
 (0)