Skip to content

Commit c1ed862

Browse files
committed
borrowck: name the correct type in error message
Closes rust-lang#36407.
1 parent 3d9f57a commit c1ed862

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,19 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
153153
}
154154

155155
Categorization::Interior(ref b, mc::InteriorElement(ik)) => {
156-
match (&b.ty.sty, ik) {
157-
(&ty::TySlice(..), _) |
158-
(_, Kind::Index) => {
159-
let mut err = struct_span_err!(bccx, move_from.span, E0508,
160-
"cannot move out of type `{}`, \
161-
a non-copy array",
162-
b.ty);
163-
err.span_label(move_from.span, "cannot move out of here");
164-
err
165-
}
166-
(_, Kind::Pattern) => {
156+
let type_name = match (&b.ty.sty, ik) {
157+
(&ty::TyArray(_, _), Kind::Index) => "array",
158+
(&ty::TySlice(_), _) => "slice",
159+
_ => {
167160
span_bug!(move_from.span, "this path should not cause illegal move");
168-
}
169-
}
161+
},
162+
};
163+
let mut err = struct_span_err!(bccx, move_from.span, E0508,
164+
"cannot move out of type `{}`, \
165+
a non-copy {}",
166+
b.ty, type_name);
167+
err.span_label(move_from.span, "cannot move out of here");
168+
err
170169
}
171170

172171
Categorization::Downcast(ref b, _) |

src/test/compile-fail/issue-12567.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) {
1515
(&[], &[]) => println!("both empty"),
1616
(&[], &[hd, ..]) | (&[hd, ..], &[])
1717
=> println!("one empty"),
18-
//~^^ ERROR: cannot move out of type `[T]`, a non-copy array
19-
//~^^^ ERROR: cannot move out of type `[T]`, a non-copy array
18+
//~^^ ERROR: cannot move out of type `[T]`, a non-copy slice
19+
//~^^^ ERROR: cannot move out of type `[T]`, a non-copy slice
2020
(&[hd1, ..], &[hd2, ..])
2121
=> println!("both nonempty"),
22-
//~^^ ERROR: cannot move out of type `[T]`, a non-copy array
23-
//~^^^ ERROR: cannot move out of type `[T]`, a non-copy array
22+
//~^^ ERROR: cannot move out of type `[T]`, a non-copy slice
23+
//~^^^ ERROR: cannot move out of type `[T]`, a non-copy slice
2424
}
2525
}
2626

src/test/compile-fail/move-out-of-array-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ fn main() {
2424
}
2525

2626
fn foo(a: [D; 4], i: usize) -> D {
27-
a[i] //~ ERROR cannot move out of type `[D; 4]`
27+
a[i] //~ ERROR cannot move out of type `[D; 4]`, a non-copy array
2828
}

src/test/compile-fail/move-out-of-slice-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct A;
1515
fn main() {
1616
let a: Box<[A]> = Box::new([A]);
1717
match a {
18-
box [a] => {}, //~ ERROR cannot move out of type `[A]`
18+
box [a] => {}, //~ ERROR cannot move out of type `[A]`, a non-copy slice
1919
_ => {}
2020
}
2121
}

0 commit comments

Comments
 (0)