1
Fork 0

borrowck: name the correct type in error message

Closes #36407.
This commit is contained in:
Tamir Duberstein 2017-08-19 16:33:24 -07:00
parent 3d9f57a292
commit c1ed862bc4
No known key found for this signature in database
GPG key ID: 1C1E98CC8E17BB89
4 changed files with 18 additions and 19 deletions

View file

@ -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, _) |

View file

@ -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
}
}

View file

@ -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
}

View file

@ -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
_ => {}
}
}