about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-08-22 13:36:17 +0200
committerGitHub <noreply@github.com>2017-08-22 13:36:17 +0200
commit16a189863c9ea817efd27da2afeb5e9e89ab3f43 (patch)
tree48b8dc977d4f1caef9bdc28f43ea3e15c920fab2
parent7e5578da8c76fafcb1d7ca9f0643127da76f0879 (diff)
parentc1ed862bc4dc9b83985980dd367fc0e23e7b412a (diff)
downloadrust-16a189863c9ea817efd27da2afeb5e9e89ab3f43.tar.gz
rust-16a189863c9ea817efd27da2afeb5e9e89ab3f43.zip
Rollup merge of #43993 - tamird:better-wording-error, r=arielb1
borrowck: name the correct type in error message

Closes #36407.

r? @Mark-Simulacrum
-rw-r--r--src/librustc_borrowck/borrowck/gather_loans/move_error.rs25
-rw-r--r--src/test/compile-fail/issue-12567.rs8
-rw-r--r--src/test/compile-fail/move-out-of-array-1.rs2
-rw-r--r--src/test/compile-fail/move-out-of-slice-1.rs2
4 files changed, 18 insertions, 19 deletions
diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs
index 31a0312ef96..57b92eb8f88 100644
--- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs
+++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs
@@ -153,20 +153,19 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
         }
 
         Categorization::Interior(ref b, mc::InteriorElement(ik)) => {
-            match (&b.ty.sty, ik) {
-                (&ty::TySlice(..), _) |
-                (_, Kind::Index) => {
-                    let mut err = struct_span_err!(bccx, move_from.span, E0508,
-                                                   "cannot move out of type `{}`, \
-                                                    a non-copy array",
-                                                   b.ty);
-                    err.span_label(move_from.span, "cannot move out of here");
-                    err
-                }
-                (_, Kind::Pattern) => {
+            let type_name = match (&b.ty.sty, ik) {
+                (&ty::TyArray(_, _), Kind::Index) => "array",
+                (&ty::TySlice(_), _) => "slice",
+                _ => {
                     span_bug!(move_from.span, "this path should not cause illegal move");
-                }
-            }
+                },
+            };
+            let mut err = struct_span_err!(bccx, move_from.span, E0508,
+                                           "cannot move out of type `{}`, \
+                                            a non-copy {}",
+                                           b.ty, type_name);
+            err.span_label(move_from.span, "cannot move out of here");
+            err
         }
 
         Categorization::Downcast(ref b, _) |
diff --git a/src/test/compile-fail/issue-12567.rs b/src/test/compile-fail/issue-12567.rs
index 15d9a318d29..30cdd07b399 100644
--- a/src/test/compile-fail/issue-12567.rs
+++ b/src/test/compile-fail/issue-12567.rs
@@ -15,12 +15,12 @@ fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) {
         (&[], &[]) => println!("both empty"),
         (&[], &[hd, ..]) | (&[hd, ..], &[])
             => println!("one empty"),
-        //~^^ ERROR: cannot move out of type `[T]`, a non-copy array
-        //~^^^ ERROR: cannot move out of type `[T]`, a non-copy array
+        //~^^ ERROR: cannot move out of type `[T]`, a non-copy slice
+        //~^^^ ERROR: cannot move out of type `[T]`, a non-copy slice
         (&[hd1, ..], &[hd2, ..])
             => println!("both nonempty"),
-        //~^^ ERROR: cannot move out of type `[T]`, a non-copy array
-        //~^^^ ERROR: cannot move out of type `[T]`, a non-copy array
+        //~^^ ERROR: cannot move out of type `[T]`, a non-copy slice
+        //~^^^ ERROR: cannot move out of type `[T]`, a non-copy slice
     }
 }
 
diff --git a/src/test/compile-fail/move-out-of-array-1.rs b/src/test/compile-fail/move-out-of-array-1.rs
index 148dec02823..796b13538b2 100644
--- a/src/test/compile-fail/move-out-of-array-1.rs
+++ b/src/test/compile-fail/move-out-of-array-1.rs
@@ -24,5 +24,5 @@ fn main() {
 }
 
 fn foo(a: [D; 4], i: usize) -> D {
-    a[i] //~ ERROR cannot move out of type `[D; 4]`
+    a[i] //~ ERROR cannot move out of type `[D; 4]`, a non-copy array
 }
diff --git a/src/test/compile-fail/move-out-of-slice-1.rs b/src/test/compile-fail/move-out-of-slice-1.rs
index f3efc68701e..9ca9e0984e4 100644
--- a/src/test/compile-fail/move-out-of-slice-1.rs
+++ b/src/test/compile-fail/move-out-of-slice-1.rs
@@ -15,7 +15,7 @@ struct A;
 fn main() {
     let a: Box<[A]> = Box::new([A]);
     match a {
-        box [a] => {}, //~ ERROR cannot move out of type `[A]`
+        box [a] => {}, //~ ERROR cannot move out of type `[A]`, a non-copy slice
         _ => {}
     }
 }