]> git.lizzy.rs Git - rust.git/commitdiff
Be ambiguous when type cannot be properly mentioned
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 2 Jan 2018 06:23:13 +0000 (22:23 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Wed, 3 Jan 2018 03:49:38 +0000 (19:49 -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
src/test/ui/borrowck/issue-41962.stderr
src/test/ui/moves-based-on-type-match-bindings.rs

index b33cd19b7a9f1b6d38fdc967dc7a579d16b643b2..99403d012394f54891cf9ce859e017a6b436c946 100644 (file)
@@ -346,6 +346,16 @@ fn new(kind: LoanPathKind<'tcx>, ty: Ty<'tcx>) -> LoanPath<'tcx> {
     }
 
     fn to_type(&self) -> Ty<'tcx> { self.ty }
+
+    fn is_downcast(&self) -> bool {
+        match self.kind {
+            LpDowncast(_, _) => true,
+            LpExtend(ref lp, _, LpInterior(_, _)) => {
+                lp.is_downcast()
+            }
+            _ => false,
+        }
+    }
 }
 
 // FIXME (pnkfelix): See discussion here
@@ -711,28 +721,26 @@ pub fn report_use_of_moved_value(&self,
         err = if use_span == move_span {
             err.span_label(
                 use_span,
-                format!("value moved{} here in previous iteration of loop{}",
-                         move_note,
-                         extra_move_label));
-
-            if need_note {
-                err.note(&format!("value moved because it has type `{}`, \
-                                   which does not implement the `Copy` trait",
-                                  moved_lp.ty)
-            }
+                format!("value moved{} here in previous iteration of loop",
+                         move_note));
             err
         } else {
             err.span_label(use_span, format!("value {} here after move", verb_participle));
-            let extra_move_label = if need_note {
-               &format!(" because it has type `{}`, which does not implement the `Copy` trait",
-                        moved_lp.ty)
-            } else {
-                ""
-            };
-            err.span_label(move_span,format!("value moved{} here{}", move_note, extra_move_label));
+            err.span_label(move_span, format!("value moved{} here", move_note));
             err
         };
 
+        if need_note {
+            err.note(&format!(
+                "move occurs because {} has type `{}`, which does not implement the `Copy` trait",
+                if moved_lp.is_downcast() {
+                    "the value".to_string()
+                } else {
+                    format!("`{}`", 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
index 544679171b4623565505205c473e3ba8e35b7fd0..016ce93a0bd0bc4b68a7108fd7cab8a73e4d8d3c 100644 (file)
@@ -12,8 +12,9 @@
 fn main() {
    let x = NoCopy;
    let f = move || { let y = x; };
-   //~^ NOTE value moved (into closure) here because it has type `NoCopy`, which does not
+   //~^ NOTE value moved (into closure) here
    let z = x;
    //~^ ERROR use of moved value: `x`
    //~| NOTE value used here after move
+   //~| NOTE move occurs because `x` has type `NoCopy`
 }
index 0929e0b57d32d4c2723896ae96f9971c0ee91247..5329dcaaaf4a263cb07f081e1f40bc1f37c293c7 100644 (file)
@@ -17,17 +17,19 @@ fn touch<A>(_a: &A) {}
 fn f00() {
     let x = "hi".to_string();
     let _y = Foo { f:x };
-    //~^ NOTE value moved here because it has type
+    //~^ NOTE value moved here
     touch(&x); //~ ERROR use of moved value: `x`
     //~^ NOTE value used here after move
+    //~| NOTE move occurs because `x` has type `std::string::String`
 }
 
 fn f05() {
     let x = "hi".to_string();
     let _y = Foo { f:(((x))) };
-    //~^ NOTE value moved here because it has type
+    //~^ NOTE value moved here
     touch(&x); //~ ERROR use of moved value: `x`
     //~^ NOTE value used here after move
+    //~| NOTE move occurs because `x` has type `std::string::String`
 }
 
 fn f10() {
index 0ac48990be4be16fa53209f112a6b078651e683d..82f5c49eeb7ae520d81ccd85cdce3e14e01794df 100644 (file)
@@ -20,18 +20,15 @@ fn add_assign(&mut self, _: Int) {
 
 fn main() {
     let mut x = Int(1);
-    x
-    //~^ error: use of moved value: `x`
-    //~| note: value used here after move
+    x   //~ error: use of moved value: `x`
+    //~^ value used here after move
     +=
-    x;
-    //~^ note: value moved here because it has type `Int`, which does not implement the `Copy`
+    x;  //~ value moved here
 
     let y = Int(2);
-    //~^ note: consider changing this to `mut y`
-    y
-    //~^ error: cannot borrow immutable local variable `y` as mutable
-    //~| note: cannot borrow mutably
+    //~^ consider changing this to `mut y`
+    y   //~ error: cannot borrow immutable local variable `y` as mutable
+        //~| cannot borrow
     +=
     Int(1);
 }
index a2b2d425f1dc9b6e2559d322f29def1089fce97d..75bf6bce04b396caf622938672dba1c5031872d9 100644 (file)
@@ -33,25 +33,28 @@ struct D {
 fn copy_after_move() {
     let a: Box<_> = box A { x: box 0, y: 1 };
     let _x = a.x;
-    //~^ 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
+    //~^ 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
 }
 
 fn move_after_move() {
     let a: Box<_> = box B { x: box 0, y: box 1 };
     let _x = a.x;
-    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
+    //~^ value moved here
     let _y = a.y; //~ ERROR use of moved
-    //~^ NOTE value used here after move
+    //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
+    //~| value used here after move
 }
 
 fn borrow_after_move() {
     let a: Box<_> = box A { x: box 0, y: 1 };
     let _x = a.x;
-    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
+    //~^ value moved here
     let _y = &a.y; //~ ERROR use of moved
-    //~^ NOTE value used here after move
+    //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
+    //~| value used here after move
 }
 
 fn move_after_borrow() {
@@ -59,7 +62,7 @@ fn move_after_borrow() {
     let _x = &a.x;
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| NOTE move out of
+    //~| move out of
 }
 
 fn copy_after_mut_borrow() {
@@ -73,54 +76,54 @@ fn move_after_mut_borrow() {
     let _x = &mut a.x;
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| NOTE move out of
+    //~| 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
-    //~^ NOTE immutable borrow occurs here (via `a.y`)
+    //~^ 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
-    //~^ NOTE mutable borrow occurs here (via `a.y`)
+    //~^ 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;
-    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
+    //~^ value moved here
     let _y = a.y; //~ ERROR use of collaterally moved
-    //~^ NOTE value used here after move
+    //~| 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;
-    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
+    //~^ value moved here
     let _y = a.y; //~ ERROR use of collaterally moved
-    //~^ NOTE value used here after move
+    //~| 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;
-    //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not
+    //~^ value moved here
     let _y = &a.y; //~ ERROR use of collaterally moved
-    //~^ NOTE value used here after move
+    //~| 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;
-    //~^ NOTE borrow of `a.x.x` occurs here
+    //~^ borrow of `a.x.x` occurs here
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| NOTE move out of
+    //~| move out of
 }
 
 fn copy_after_mut_borrow_nested() {
@@ -134,23 +137,23 @@ fn move_after_mut_borrow_nested() {
     let _x = &mut a.x.x;
     let _y = a.y;
     //~^ ERROR cannot move
-    //~| NOTE move out of
+    //~| 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;
-    //~^ NOTE mutable borrow occurs here
+    //~^ mutable borrow occurs here
     let _y = &a.y; //~ ERROR cannot borrow
-    //~^ NOTE immutable borrow occurs here
+    //~^ 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;
-    //~^ NOTE immutable borrow occurs here
+    //~^ immutable borrow occurs here
     let _y = &mut a.y; //~ ERROR cannot borrow
-    //~^ NOTE mutable borrow occurs here
+    //~^ mutable borrow occurs here
 }
 
 fn main() {
index a8e1edbdfdf1e09bf230a3d35b9787b52dd1d005..d8a4436532a0d8b3d9fa955499388f8e5cbba6b3 100644 (file)
@@ -13,6 +13,8 @@ pub fn main(){
 
     loop {
         if let Some(thing) = maybe {
+        //~^ ERROR use of partially moved value
+        //~| ERROR use of moved value
         }
     }
 }
index caa67835ee573ab06e7bb248be9d49e4f90ebaae..51e4409c81f80fb71e01baeea5c954d291dfc506 100644 (file)
@@ -4,14 +4,17 @@ error[E0382]: use of partially moved value: `maybe`
 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
+   |                     value moved here
+   |
+   = note: move occurs because the value 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
-   = note: value moved because it has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
+   |
+   = note: move occurs because the value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
 
 error: aborting due to 2 previous errors
 
index c08c1a788c1e09f7a41622b0ea834b0acd1bf6f7..1fd3d03570a69d789002cc64c4d782c28c950a03 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`
-    //~^ NOTE value used here after move
+    //~^ value used here after move
+    //~| move occurs because `x.f` has type `std::string::String`
 }
 
 fn main() {}