From c1ed862bc4dc9b83985980dd367fc0e23e7b412a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 19 Aug 2017 16:33:24 -0700 Subject: [PATCH] borrowck: name the correct type in error message Closes #36407. --- .../borrowck/gather_loans/move_error.rs | 25 +++++++++---------- src/test/compile-fail/issue-12567.rs | 8 +++--- src/test/compile-fail/move-out-of-array-1.rs | 2 +- src/test/compile-fail/move-out-of-slice-1.rs | 2 +- 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 31a0312ef9699..57b92eb8f8891 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 15d9a318d29ca..30cdd07b39998 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 148dec0282331..796b13538b22a 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 f3efc68701e94..9ca9e0984e476 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 _ => {} } }