]> git.lizzy.rs Git - rust.git/commitdiff
Move reason for move to label
authorEsteban Küber <esteban@kuber.com.ar>
Wed, 6 Sep 2017 06:36:34 +0000 (23:36 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 2 Jan 2018 05:55:46 +0000 (21:55 -0800)
src/librustc_borrowck/borrowck/mod.rs
src/test/compile-fail/issue-24357.rs
src/test/compile-fail/moves-based-on-type-distribute-copy-over-paren.rs
src/test/ui/augmented-assignments.rs
src/test/ui/borrowck/borrowck-box-insensitivity.rs
src/test/ui/borrowck/issue-41962.rs [new file with mode: 0644]
src/test/ui/borrowck/issue-41962.stderr [new file with mode: 0644]
src/test/ui/moves-based-on-type-match-bindings.rs

index b124872ba12ca70eb8ccf51090c77844795552b4..4b72b6987084ee5c987f7020749209c52aa12d08 100644 (file)
@@ -705,28 +705,28 @@ pub fn report_use_of_moved_value(&self,
                 }, " (into closure)"),
         };
 
+        let extra_move_label = if need_note {
+            format!(" because it has type `{}`, which does not implement the `Copy` trait",
+                    moved_lp.ty)
+        } else {
+            String::new()
+        };
         // Annotate the use and the move in the span. Watch out for
         // the case where the use and the move are the same. This
         // means the use is in a loop.
         err = if use_span == move_span {
             err.span_label(
                 use_span,
-                format!("value moved{} here in previous iteration of loop",
-                         move_note));
+                format!("value moved{} here in previous iteration of loop{}",
+                         move_note,
+                         extra_move_label));
             err
         } else {
             err.span_label(use_span, format!("value {} here after move", verb_participle))
-               .span_label(move_span, format!("value moved{} here", move_note));
+               .span_label(move_span, format!("value moved{} here{}", move_note, extra_move_label));
             err
         };
 
-        if need_note {
-            err.note(&format!("move occurs because `{}` has type `{}`, \
-                               which does not implement the `Copy` trait",
-                              self.loan_path_to_string(moved_lp),
-                              moved_lp.ty));
-        }
-
         // Note: we used to suggest adding a `ref binding` or calling
         // `clone` but those suggestions have been removed because
         // they are often not what you actually want to do, and were
@@ -1391,7 +1391,7 @@ pub fn append_autoderefd_loan_path_to_string(&self,
             LpDowncast(ref lp_base, variant_def_id) => {
                 out.push('(');
                 self.append_autoderefd_loan_path_to_string(&lp_base, out);
-                out.push(':');
+                out.push_str(DOWNCAST_PRINTED_OPERATOR);
                 out.push_str(&self.tcx.item_path_str(variant_def_id));
                 out.push(')');
             }
index 5d6b989fc968ac8c818b96d70eb5041716a878e1..544679171b4623565505205c473e3ba8e35b7fd0 100644 (file)
@@ -12,9 +12,8 @@
 fn main() {
    let x = NoCopy;
    let f = move || { let y = x; };
-   //~^ value moved (into closure) here
+   //~^ NOTE value moved (into closure) here because it has type `NoCopy`, which does not
    let z = x;
    //~^ ERROR use of moved value: `x`
-   //~| value used here after move
-   //~| move occurs because `x` has type `NoCopy`
+   //~| NOTE value used here after move
 }
index 02c09aa7d69a261e1f36a03d12318ff2a5cccf7e..0929e0b57d32d4c2723896ae96f9971c0ee91247 100644 (file)
@@ -17,17 +17,17 @@ fn touch<A>(_a: &A) {}
 fn f00() {
     let x = "hi".to_string();
     let _y = Foo { f:x };
-    //~^ value moved here
+    //~^ NOTE value moved here because it has type
     touch(&x); //~ ERROR use of moved value: `x`
-    //~^ value used here after move
-    //~| move occurs because `x` has type `std::string::String`
+    //~^ NOTE value used here after move
 }
 
 fn f05() {
     let x = "hi".to_string();
     let _y = Foo { f:(((x))) };
-    //~^ value moved here
+    //~^ NOTE value moved here because it has type
     touch(&x); //~ ERROR use of moved value: `x`
+    //~^ NOTE value used here after move
 }
 
 fn f10() {
index 82f5c49eeb7ae520d81ccd85cdce3e14e01794df..0ac48990be4be16fa53209f112a6b078651e683d 100644 (file)
@@ -20,15 +20,18 @@ fn add_assign(&mut self, _: Int) {
 
 fn main() {
     let mut x = Int(1);
-    x   //~ error: use of moved value: `x`
-    //~^ value used here after move
+    x
+    //~^ error: use of moved value: `x`
+    //~| note: value used here after move
     +=
-    x;  //~ value moved here
+    x;
+    //~^ note: value moved here because it has type `Int`, which does not implement the `Copy`
 
     let y = Int(2);
-    //~^ consider changing this to `mut y`
-    y   //~ error: cannot borrow immutable local variable `y` as mutable
-        //~| cannot borrow
+    //~^ note: consider changing this to `mut y`
+    y
+    //~^ error: cannot borrow immutable local variable `y` as mutable
+    //~| note: cannot borrow mutably
     +=
     Int(1);
 }
index 75bf6bce04b396caf622938672dba1c5031872d9..a2b2d425f1dc9b6e2559d322f29def1089fce97d 100644 (file)
@@ -33,28 +33,25 @@ struct D {
 fn copy_after_move() {
     let a: Box<_> = box A { x: box 0, y: 1 };
     let _x = a.x;
-    //~^ value moved here
-    let _y = a.y; //~ ERROR use of moved
-    //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
-    //~| value used here after move
+    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
+    let _y = a.y; //~ ERROR use of moved value
+    //~^ NOTE value used here after move
 }
 
 fn move_after_move() {
     let a: Box<_> = box B { x: box 0, y: box 1 };
     let _x = a.x;
-    //~^ value moved here
+    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
     let _y = a.y; //~ ERROR use of moved
-    //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
-    //~| value used here after move
+    //~^ NOTE value used here after move
 }
 
 fn borrow_after_move() {
     let a: Box<_> = box A { x: box 0, y: 1 };
     let _x = a.x;
-    //~^ value moved here
+    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
     let _y = &a.y; //~ ERROR use of moved
-    //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
-    //~| value used here after move
+    //~^ NOTE value used here after move
 }
 
 fn move_after_borrow() {
@@ -62,7 +59,7 @@ fn move_after_borrow() {
     let _x = &a.x;
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| move out of
+    //~| NOTE move out of
 }
 
 fn copy_after_mut_borrow() {
@@ -76,54 +73,54 @@ fn move_after_mut_borrow() {
     let _x = &mut a.x;
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| move out of
+    //~| NOTE move out of
 }
 
 fn borrow_after_mut_borrow() {
     let mut a: Box<_> = box A { x: box 0, y: 1 };
     let _x = &mut a.x;
     let _y = &a.y; //~ ERROR cannot borrow
-    //~^ immutable borrow occurs here (via `a.y`)
+    //~^ NOTE immutable borrow occurs here (via `a.y`)
 }
 
 fn mut_borrow_after_borrow() {
     let mut a: Box<_> = box A { x: box 0, y: 1 };
     let _x = &a.x;
     let _y = &mut a.y; //~ ERROR cannot borrow
-    //~^ mutable borrow occurs here (via `a.y`)
+    //~^ NOTE mutable borrow occurs here (via `a.y`)
 }
 
 fn copy_after_move_nested() {
     let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
     let _x = a.x.x;
-    //~^ value moved here
+    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
     let _y = a.y; //~ ERROR use of collaterally moved
-    //~| value used here after move
+    //~^ NOTE value used here after move
 }
 
 fn move_after_move_nested() {
     let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
     let _x = a.x.x;
-    //~^ value moved here
+    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
     let _y = a.y; //~ ERROR use of collaterally moved
-    //~| value used here after move
+    //~^ NOTE value used here after move
 }
 
 fn borrow_after_move_nested() {
     let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
     let _x = a.x.x;
-    //~^ value moved here
+    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
     let _y = &a.y; //~ ERROR use of collaterally moved
-    //~| value used here after move
+    //~^ NOTE value used here after move
 }
 
 fn move_after_borrow_nested() {
     let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
     let _x = &a.x.x;
-    //~^ borrow of `a.x.x` occurs here
+    //~^ NOTE borrow of `a.x.x` occurs here
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| move out of
+    //~| NOTE move out of
 }
 
 fn copy_after_mut_borrow_nested() {
@@ -137,23 +134,23 @@ fn move_after_mut_borrow_nested() {
     let _x = &mut a.x.x;
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| move out of
+    //~| NOTE move out of
 }
 
 fn borrow_after_mut_borrow_nested() {
     let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
     let _x = &mut a.x.x;
-    //~^ mutable borrow occurs here
+    //~^ NOTE mutable borrow occurs here
     let _y = &a.y; //~ ERROR cannot borrow
-    //~^ immutable borrow occurs here
+    //~^ NOTE immutable borrow occurs here
 }
 
 fn mut_borrow_after_borrow_nested() {
     let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
     let _x = &a.x.x;
-    //~^ immutable borrow occurs here
+    //~^ NOTE immutable borrow occurs here
     let _y = &mut a.y; //~ ERROR cannot borrow
-    //~^ mutable borrow occurs here
+    //~^ NOTE mutable borrow occurs here
 }
 
 fn main() {
diff --git a/src/test/ui/borrowck/issue-41962.rs b/src/test/ui/borrowck/issue-41962.rs
new file mode 100644 (file)
index 0000000..a8e1edb
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main(){
+    let maybe = Some(vec![true, true]);
+
+    loop {
+        if let Some(thing) = maybe {
+        }
+    }
+}
diff --git a/src/test/ui/borrowck/issue-41962.stderr b/src/test/ui/borrowck/issue-41962.stderr
new file mode 100644 (file)
index 0000000..4ee1179
--- /dev/null
@@ -0,0 +1,16 @@
+error[E0382]: use of partially moved value: `maybe`
+  --> $DIR/issue-41962.rs:15:30
+   |
+15 |         if let Some(thing) = maybe {
+   |                     -----    ^^^^^ value used here after move
+   |                     |
+   |                     value moved here because it has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
+
+error[E0382]: use of moved value: `(maybe as std::prelude::v1::Some).0`
+  --> $DIR/issue-41962.rs:15:21
+   |
+15 |         if let Some(thing) = maybe {
+   |                     ^^^^^ value moved here in previous iteration of loop because it has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
+
+error: aborting due to 2 previous errors
+
index 1fd3d03570a69d789002cc64c4d782c28c950a03..c08c1a788c1e09f7a41622b0ea834b0acd1bf6f7 100644 (file)
@@ -21,11 +21,11 @@ fn f10() {
 
     let y = match x {
         Foo {f} => {}
+        //~^ NOTE value moved here because it has type `std::string::String`, which does not
     };
 
     touch(&x); //~ ERROR use of partially moved value: `x`
-    //~^ value used here after move
-    //~| move occurs because `x.f` has type `std::string::String`
+    //~^ NOTE value used here after move
 }
 
 fn main() {}