Skip to content

Commit 01e979f

Browse files
Rollup merge of #45967 - matthewjasper:array-move-types, r=arielb1
MIR-borrowck: don't ICE for cannot move from array error Closes #45694 compile-fail test E0508 now gives ```text error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Ast) --> .\src\test\compile-fail\E0508.rs:18:18 | 18 | let _value = array[0]; //[ast]~ ERROR E0508 | ^^^^^^^^ | | | cannot move out of here | help: consider using a reference instead: `&array[0]` error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Mir) --> .\src\test\compile-fail\E0508.rs:18:18 | 18 | let _value = array[0]; //[ast]~ ERROR E0508 | ^^^^^^^^ cannot move out of here error: aborting due to 2 previous errors ```
2 parents 529bb32 + a6824f1 commit 01e979f

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/librustc_mir/borrow_check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
9393
tcx.cannot_move_out_of(span, "borrowed_content", origin),
9494
IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } =>
9595
tcx.cannot_move_out_of_interior_of_drop(span, ty, origin),
96-
IllegalMoveOriginKind::InteriorOfSlice { elem_ty: ty, is_index } =>
97-
tcx.cannot_move_out_of_interior_noncopy(span, ty, is_index, origin),
98-
IllegalMoveOriginKind::InteriorOfArray { elem_ty: ty, is_index } =>
96+
IllegalMoveOriginKind::InteriorOfSliceOrArray { ty, is_index } =>
9997
tcx.cannot_move_out_of_interior_noncopy(span, ty, is_index, origin),
10098
};
10199
err.emit();

src/librustc_mir/dataflow/move_paths/builder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,21 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
137137
// move out of union - always move the entire union
138138
ty::TyAdt(adt, _) if adt.is_union() =>
139139
return Err(MoveError::UnionMove { path: base }),
140-
ty::TySlice(elem_ty) =>
140+
ty::TySlice(_) =>
141141
return Err(MoveError::cannot_move_out_of(
142142
mir.source_info(self.loc).span,
143-
InteriorOfSlice {
144-
elem_ty, is_index: match proj.elem {
143+
InteriorOfSliceOrArray {
144+
ty: lv_ty, is_index: match proj.elem {
145145
ProjectionElem::Index(..) => true,
146146
_ => false
147147
},
148148
})),
149-
ty::TyArray(elem_ty, _num_elems) => match proj.elem {
149+
ty::TyArray(..) => match proj.elem {
150150
ProjectionElem::Index(..) =>
151151
return Err(MoveError::cannot_move_out_of(
152152
mir.source_info(self.loc).span,
153-
InteriorOfArray {
154-
elem_ty, is_index: true
153+
InteriorOfSliceOrArray {
154+
ty: lv_ty, is_index: true
155155
})),
156156
_ => {
157157
// FIXME: still badly broken

src/librustc_mir/dataflow/move_paths/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ pub(crate) enum IllegalMoveOriginKind<'tcx> {
239239
Static,
240240
BorrowedContent,
241241
InteriorOfTypeWithDestructor { container_ty: ty::Ty<'tcx> },
242-
InteriorOfSlice { elem_ty: ty::Ty<'tcx>, is_index: bool, },
243-
InteriorOfArray { elem_ty: ty::Ty<'tcx>, is_index: bool, },
242+
InteriorOfSliceOrArray { ty: ty::Ty<'tcx>, is_index: bool, },
244243
}
245244

246245
#[derive(Debug)]

src/test/compile-fail/E0508.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Zborrowck-mir
13+
1114
struct NonCopy;
1215

1316
fn main() {
1417
let array = [NonCopy; 1];
15-
let _value = array[0]; //~ ERROR E0508
18+
let _value = array[0]; //[ast]~ ERROR E0508
19+
//[mir]~^ ERROR (Ast) [E0508]
20+
//[mir]~| ERROR (Mir) [E0508]
1621
}

0 commit comments

Comments
 (0)