Skip to content

Commit

Permalink
borrowck: name the correct type in error message
Browse files Browse the repository at this point in the history
Closes #36407.
  • Loading branch information
tamird committed Aug 20, 2017
1 parent 3d9f57a commit c1ed862
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
25 changes: 12 additions & 13 deletions src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Expand Up @@ -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, _) |
Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/issue-12567.rs
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/move-out-of-array-1.rs
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/move-out-of-slice-1.rs
Expand Up @@ -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
_ => {}
}
}

0 comments on commit c1ed862

Please sign in to comment.