let place = &self.move_data.move_paths[mpi].place;
let ty = place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
- let note_msg = match self.describe_place_with_options(
- place,
- IncludingDowncast(true),
- ) {
- Some(name) => format!("`{}`", name),
+ let opt_name = self.describe_place_with_options(place, IncludingDowncast(true));
+ let note_msg = match opt_name {
+ Some(ref name) => format!("`{}`", name),
None => "value".to_owned(),
};
-
- err.note(&format!(
- "move occurs because {} has type `{}`, \
- which does not implement the `Copy` trait",
- note_msg, ty
- ));
+ let mut note = true;
+ for decl in &self.mir.local_decls {
+ if decl.ty == ty && decl.name.map(|x| x.to_string()) == opt_name {
+ err.span_label(
+ decl.source_info.span,
+ format!(
+ "move occurs because {} has type `{}`, \
+ which does not implement the `Copy` trait",
+ note_msg, ty,
+ ));
+ note = false;
+ }
+ }
+ if note {
+ err.note(&format!(
+ "move occurs because {} has type `{}`, \
+ which does not implement the `Copy` trait",
+ note_msg, ty
+ ));
+ }
}
if let Some((_, mut old_err)) = self.move_error_reported
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:27:17
|
+LL | let x = &mut 0isize;
+ | - move occurs because `x` has type `&mut isize`, which does not implement the `Copy` trait
+LL | unsafe {
LL | asm!("nop" : : "r"(x));
| - value moved here
LL | }
LL | let z = x; //[ast]~ ERROR use of moved value: `x`
| ^ value used here after move
- |
- = note: move occurs because `x` has type `&mut isize`, which does not implement the `Copy` trait
error[E0503]: cannot use `x` because it was mutably borrowed
--> $DIR/borrowck-asm.rs:35:32
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:86:40
|
+LL | let x = &mut 2;
+ | - move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait
+LL | unsafe {
LL | asm!("nop" : : "r"(x), "r"(x) ); //[ast]~ ERROR use of moved value
| - ^ value used here after move
| |
| value moved here
- |
- = note: move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait
error: aborting due to 7 previous errors
error[E0382]: use of moved value: `my_str`
--> $DIR/borrowck-drop-from-guard.rs:11:23
|
+LL | let my_str = "hello".to_owned();
+ | ------ move occurs because `my_str` has type `std::string::String`, which does not implement the `Copy` trait
+LL | match Some(42) {
LL | Some(_) if { drop(my_str); false } => {}
| ------ value moved here
LL | Some(_) => {}
LL | None => { foo(my_str); } //~ ERROR [E0382]
| ^^^^^^ value used here after move
- |
- = note: move occurs because `my_str` has type `std::string::String`, which does not implement the `Copy` trait
error: aborting due to previous error
error[E0382]: use of moved value: `src`
--> $DIR/borrowck-issue-48962.rs:16:5
|
+LL | let mut src = &mut node;
+ | ------- move occurs because `src` has type `&mut Node`, which does not implement the `Copy` trait
LL | {src};
| --- value moved here
LL | src.next = None; //~ ERROR use of moved value: `src` [E0382]
| ^^^^^^^^ value used here after move
- |
- = note: move occurs because `src` has type `&mut Node`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `src`
--> $DIR/borrowck-issue-48962.rs:22:5
|
+LL | let mut src = &mut (22, 44);
+ | ------- move occurs because `src` has type `&mut (i32, i32)`, which does not implement the `Copy` trait
LL | {src};
| --- value moved here
LL | src.0 = 66; //~ ERROR use of moved value: `src` [E0382]
| ^^^^^^^^^^ value used here after move
- |
- = note: move occurs because `src` has type `&mut (i32, i32)`, which does not implement the `Copy` trait
error: aborting due to 2 previous errors
error[E0382]: use of moved value: `t`
--> $DIR/borrowck-move-moved-value-into-closure.rs:14:12
|
+LL | let t: Box<_> = box 3;
+ | - move occurs because `t` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
+LL |
LL | call_f(move|| { *t + 1 });
| ------ - variable moved due to use in closure
| |
| ^^^^^^ - use occurs due to use in closure
| |
| value used here after move
- |
- = note: move occurs because `t` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
error: aborting due to previous error
error[E0382]: use of moved value: `x` (Mir)
--> $DIR/borrowck-reinit.rs:8:16
|
+LL | let mut x = Box::new(0);
+ | ----- move occurs because `x` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
+...
LL | drop(x);
| - value moved here
LL | let _ = (1,x); //~ ERROR use of moved value: `x` (Ast)
| ^ value used here after move
- |
- = note: move occurs because `x` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
error: aborting due to 2 previous errors
error[E0382]: use of moved value (Mir)
--> $DIR/issue-41962.rs:7:21
|
+LL | let maybe = Some(vec![true, true]);
+ | ---------------- move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
+...
LL | if let Some(thing) = maybe {
| ^^^^^ value moved here, in previous iteration of loop
|
- = note: move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 3 previous errors
error[E0382]: assign to part of moved value: `t`
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:23:9
|
+LL | let mut t: Tuple = (S(0), 0);
+ | ----- move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
LL | drop(t);
| - value moved here
LL | t.0 = S(1);
| ^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `u`
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:34:9
|
+LL | let mut u: Tpair = Tpair(S(0), 0);
+ | ----- move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
LL | drop(u);
| - value moved here
LL | u.0 = S(1);
| ^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `v`
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:45:9
|
+LL | let mut v: Spair = Spair { x: S(0), y: 0 };
+ | ----- move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
LL | drop(v);
| - value moved here
LL | v.x = S(1);
| ^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
error: aborting due to 3 previous errors
error[E0382]: assign to part of moved value: `t`
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:23:9
|
+LL | let t: Tuple = (S(0), 0);
+ | - move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
LL | drop(t);
| - value moved here
LL | t.0 = S(1);
| ^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
error[E0594]: cannot assign to `t.1`, as `t` is not declared as mutable
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:27:9
error[E0382]: assign to part of moved value: `u`
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:38:9
|
+LL | let u: Tpair = Tpair(S(0), 0);
+ | - move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
LL | drop(u);
| - value moved here
LL | u.0 = S(1);
| ^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
error[E0594]: cannot assign to `u.1`, as `u` is not declared as mutable
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:42:9
error[E0382]: assign to part of moved value: `v`
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:53:9
|
+LL | let v: Spair = Spair { x: S(0), y: 0 };
+ | - move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
LL | drop(v);
| - value moved here
LL | v.x = S(1);
| ^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
error[E0594]: cannot assign to `v.y`, as `v` is not declared as mutable
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:57:9
error[E0382]: use of moved value: `b`
--> $DIR/issue-27282-move-match-input-into-guard.rs:18:14
|
+LL | let b = &mut true;
+ | - move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait
+...
LL | _ if { (|| { let bar = b; *bar = false; })();
| -- - variable moved due to use in closure
| |
LL | false } => { },
LL | &mut true => { println!("You might think we should get here"); },
| ^^^^ value used here after move
- |
- = note: move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait
error: aborting due to previous error
error[E0382]: use of moved value: `s`
--> $DIR/issue-29723.rs:12:13
|
+LL | let s = String::new();
+ | - move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait
+LL | let _s = match 0 {
LL | 0 if { drop(s); false } => String::from("oops"),
| - value moved here
...
LL | s
| ^ value used here after move
- |
- = note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait
error: aborting due to previous error
error[E0382]: use of moved value: `x` (Mir)
--> $DIR/moves-based-on-type-tuple.rs:6:13
|
+LL | fn dup(x: Box<isize>) -> Box<(Box<isize>,Box<isize>)> {
+ | - move occurs because `x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
LL | box (x, x)
| - ^ value used here after move
| |
| value moved here
- |
- = note: move occurs because `x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
error: aborting due to 2 previous errors
error[E0382]: borrow of moved value: `x`
--> $DIR/closure-access-spans.rs:37:5
|
+LL | fn closure_imm_capture_moved(mut x: String) {
+ | ----- move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
LL | let r = x;
| - value moved here
LL | || x.len(); //~ ERROR
| ^^ - borrow occurs due to use in closure
| |
| value borrowed here after move
- |
- = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `x`
--> $DIR/closure-access-spans.rs:42:5
|
+LL | fn closure_mut_capture_moved(mut x: String) {
+ | ----- move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
LL | let r = x;
| - value moved here
LL | || x = String::new(); //~ ERROR
| ^^ - borrow occurs due to use in closure
| |
| value borrowed here after move
- |
- = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `x`
--> $DIR/closure-access-spans.rs:47:5
|
+LL | fn closure_unique_capture_moved(x: &mut String) {
+ | - move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait
LL | let r = x;
| - value moved here
LL | || *x = String::new(); //~ ERROR
| ^^ - borrow occurs due to use in closure
| |
| value borrowed here after move
- |
- = note: move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `x`
--> $DIR/closure-access-spans.rs:52:5
|
+LL | fn closure_move_capture_moved(x: &mut String) {
+ | - move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait
LL | let r = x;
| - value moved here
LL | || x; //~ ERROR
| ^^ - use occurs due to use in closure
| |
| value used here after move
- |
- = note: move occurs because `x` has type `&mut std::string::String`, which does not implement the `Copy` trait
error: aborting due to 9 previous errors
error[E0382]: use of moved value: `x`
--> $DIR/closure-move-spans.rs:7:13
|
+LL | fn move_after_move(x: String) {
+ | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
LL | || x;
| -- - variable moved due to use in closure
| |
| value moved into closure here
LL | let y = x; //~ ERROR
| ^ value used here after move
- |
- = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `x`
--> $DIR/closure-move-spans.rs:12:13
|
+LL | fn borrow_after_move(x: String) {
+ | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
LL | || x;
| -- - variable moved due to use in closure
| |
| value moved into closure here
LL | let y = &x; //~ ERROR
| ^^ value borrowed here after move
- |
- = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `x`
--> $DIR/closure-move-spans.rs:17:13
|
+LL | fn borrow_mut_after_move(mut x: String) {
+ | ----- move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
LL | || x;
| -- - variable moved due to use in closure
| |
| value moved into closure here
LL | let y = &mut x; //~ ERROR
| ^^^^^^ value borrowed here after move
- |
- = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
error: aborting due to 3 previous errors
error[E0382]: use of moved value: `x`
--> $DIR/closures-in-loops.rs:8:9
|
+LL | fn repreated_move(x: String) {
+ | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
+LL | for i in 0..10 {
LL | || x; //~ ERROR
| ^^ - use occurs due to use in closure
| |
| value moved into closure here, in previous iteration of loop
- |
- = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/closures-in-loops.rs:15:16
error[E0382]: assign of moved value: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:43:5
|
+LL | let mut d = D { x: 0, s: S{ y: 0, z: 0 } };
+ | ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait
LL | drop(d);
| - value moved here
LL | d.x = 10;
| ^^^^^^^^ value assigned here after move
- |
- = note: move occurs because `d` has type `D`, which does not implement the `Copy` trait
error[E0381]: assign to part of possibly uninitialized variable: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:49:5
error[E0382]: assign to part of moved value: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:62:5
|
+LL | let mut d = D { x: 0, s: S{ y: 0, z: 0} };
+ | ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait
LL | drop(d);
| - value moved here
LL | d.s.y = 20;
| ^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `d` has type `D`, which does not implement the `Copy` trait
error: aborting due to 6 previous errors
--> $DIR/issue-21232-partial-init-and-use.rs:113:5
|
LL | let mut s: S<B> = S::new(); drop(s);
- | - value moved here
+ | ----- - value moved here
+ | |
+ | move occurs because `s` has type `S<std::boxed::Box<u32>>`, which does not implement the `Copy` trait
LL | s.x = 10; s.y = Box::new(20);
| ^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `s` has type `S<std::boxed::Box<u32>>`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `t`
--> $DIR/issue-21232-partial-init-and-use.rs:120:5
|
LL | let mut t: T = (0, Box::new(0)); drop(t);
- | - value moved here
+ | ----- - value moved here
+ | |
+ | move occurs because `t` has type `(u32, std::boxed::Box<u32>)`, which does not implement the `Copy` trait
LL | t.0 = 10; t.1 = Box::new(20);
| ^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `t` has type `(u32, std::boxed::Box<u32>)`, which does not implement the `Copy` trait
error[E0381]: assign to part of possibly uninitialized variable: `s`
--> $DIR/issue-21232-partial-init-and-use.rs:127:5
--> $DIR/issue-21232-partial-init-and-use.rs:141:5
|
LL | let mut s: S<B> = S::new(); drop(s);
- | - value moved here
+ | ----- - value moved here
+ | |
+ | move occurs because `s` has type `S<std::boxed::Box<u32>>`, which does not implement the `Copy` trait
LL | s.x = 10;
| ^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `s` has type `S<std::boxed::Box<u32>>`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `t`
--> $DIR/issue-21232-partial-init-and-use.rs:148:5
|
LL | let mut t: T = (0, Box::new(0)); drop(t);
- | - value moved here
+ | ----- - value moved here
+ | |
+ | move occurs because `t` has type `(u32, std::boxed::Box<u32>)`, which does not implement the `Copy` trait
LL | t.0 = 10;
| ^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `t` has type `(u32, std::boxed::Box<u32>)`, which does not implement the `Copy` trait
error[E0381]: assign to part of possibly uninitialized variable: `s`
--> $DIR/issue-21232-partial-init-and-use.rs:155:5
error[E0382]: assign to part of moved value: `c`
--> $DIR/issue-21232-partial-init-and-use.rs:259:13
|
+LL | let mut c = (1, "".to_owned());
+ | ----- move occurs because `c` has type `(i32, std::string::String)`, which does not implement the `Copy` trait
+LL | match c {
LL | c2 => {
| -- value moved here
LL | c.0 = 2; //~ ERROR assign to part of moved value
| ^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `c` has type `(i32, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `c`
--> $DIR/issue-21232-partial-init-and-use.rs:269:13
|
+LL | let mut c = (1, (1, "".to_owned()));
+ | ----- move occurs because `c` has type `(i32, (i32, std::string::String))`, which does not implement the `Copy` trait
+LL | match c {
LL | c2 => {
| -- value moved here
LL | (c.1).0 = 2; //~ ERROR assign to part of moved value
| ^^^^^^^^^^^ value partially assigned here after move
- |
- = note: move occurs because `c` has type `(i32, (i32, std::string::String))`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `c.1`
--> $DIR/issue-21232-partial-init-and-use.rs:277:13
error[E0382]: use of moved value: `range`
--> $DIR/issue-51512.rs:7:13
|
+LL | let range = 0..1;
+ | ----- move occurs because `range` has type `std::ops::Range<i32>`, which does not implement the `Copy` trait
LL | let r = range;
| ----- value moved here
LL | let x = range.start;
| ^^^^^^^^^^^ value used here after move
- |
- = note: move occurs because `range` has type `std::ops::Range<i32>`, which does not implement the `Copy` trait
error: aborting due to previous error
error[E0382]: borrow of moved value: `a.b`
--> $DIR/issue-52669.rs:15:5
|
+LL | fn bar(mut a: A) -> B {
+ | ----- move occurs because `a` has type `A`, which does not implement the `Copy` trait
+LL | a.b = B;
LL | foo(a);
| - value moved here
LL | a.b.clone()
| ^^^ value borrowed here after move
- |
- = note: move occurs because `a` has type `A`, which does not implement the `Copy` trait
error: aborting due to previous error
error[E0382]: use of moved value: `k`
--> $DIR/try-block-bad-lifetime.rs:31:26
|
+LL | let k = &mut i;
+ | - move occurs because `k` has type `&mut i32`, which does not implement the `Copy` trait
+LL | let mut j: Result<(), &mut i32> = try {
LL | Err(k) ?;
| - value moved here
...
LL | ::std::mem::drop(k); //~ ERROR use of moved value: `k`
| ^ value used here after move
- |
- = note: move occurs because `k` has type `&mut i32`, which does not implement the `Copy` trait
error[E0506]: cannot assign to `i` because it is borrowed
--> $DIR/try-block-bad-lifetime.rs:32:9
error[E0382]: borrow of moved value: `x`
--> $DIR/try-block-maybe-bad-lifetime.rs:28:24
|
+LL | let x = String::new();
+ | - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
+...
LL | ::std::mem::drop(x);
| - value moved here
LL | };
LL | println!("{}", x); //~ ERROR borrow of moved value: `x`
| ^ value borrowed here after move
- |
- = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
error[E0506]: cannot assign to `i` because it is borrowed
--> $DIR/try-block-maybe-bad-lifetime.rs:40:9