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 ```
This commit is contained in:
commit
01e979f7b1
4 changed files with 14 additions and 12 deletions
|
@ -93,9 +93,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||||
tcx.cannot_move_out_of(span, "borrowed_content", origin),
|
tcx.cannot_move_out_of(span, "borrowed_content", origin),
|
||||||
IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } =>
|
IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } =>
|
||||||
tcx.cannot_move_out_of_interior_of_drop(span, ty, origin),
|
tcx.cannot_move_out_of_interior_of_drop(span, ty, origin),
|
||||||
IllegalMoveOriginKind::InteriorOfSlice { elem_ty: ty, is_index } =>
|
IllegalMoveOriginKind::InteriorOfSliceOrArray { ty, is_index } =>
|
||||||
tcx.cannot_move_out_of_interior_noncopy(span, ty, is_index, origin),
|
|
||||||
IllegalMoveOriginKind::InteriorOfArray { elem_ty: ty, is_index } =>
|
|
||||||
tcx.cannot_move_out_of_interior_noncopy(span, ty, is_index, origin),
|
tcx.cannot_move_out_of_interior_noncopy(span, ty, is_index, origin),
|
||||||
};
|
};
|
||||||
err.emit();
|
err.emit();
|
||||||
|
|
|
@ -137,21 +137,21 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
|
||||||
// move out of union - always move the entire union
|
// move out of union - always move the entire union
|
||||||
ty::TyAdt(adt, _) if adt.is_union() =>
|
ty::TyAdt(adt, _) if adt.is_union() =>
|
||||||
return Err(MoveError::UnionMove { path: base }),
|
return Err(MoveError::UnionMove { path: base }),
|
||||||
ty::TySlice(elem_ty) =>
|
ty::TySlice(_) =>
|
||||||
return Err(MoveError::cannot_move_out_of(
|
return Err(MoveError::cannot_move_out_of(
|
||||||
mir.source_info(self.loc).span,
|
mir.source_info(self.loc).span,
|
||||||
InteriorOfSlice {
|
InteriorOfSliceOrArray {
|
||||||
elem_ty, is_index: match proj.elem {
|
ty: lv_ty, is_index: match proj.elem {
|
||||||
ProjectionElem::Index(..) => true,
|
ProjectionElem::Index(..) => true,
|
||||||
_ => false
|
_ => false
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
ty::TyArray(elem_ty, _num_elems) => match proj.elem {
|
ty::TyArray(..) => match proj.elem {
|
||||||
ProjectionElem::Index(..) =>
|
ProjectionElem::Index(..) =>
|
||||||
return Err(MoveError::cannot_move_out_of(
|
return Err(MoveError::cannot_move_out_of(
|
||||||
mir.source_info(self.loc).span,
|
mir.source_info(self.loc).span,
|
||||||
InteriorOfArray {
|
InteriorOfSliceOrArray {
|
||||||
elem_ty, is_index: true
|
ty: lv_ty, is_index: true
|
||||||
})),
|
})),
|
||||||
_ => {
|
_ => {
|
||||||
// FIXME: still badly broken
|
// FIXME: still badly broken
|
||||||
|
|
|
@ -239,8 +239,7 @@ pub(crate) enum IllegalMoveOriginKind<'tcx> {
|
||||||
Static,
|
Static,
|
||||||
BorrowedContent,
|
BorrowedContent,
|
||||||
InteriorOfTypeWithDestructor { container_ty: ty::Ty<'tcx> },
|
InteriorOfTypeWithDestructor { container_ty: ty::Ty<'tcx> },
|
||||||
InteriorOfSlice { elem_ty: ty::Ty<'tcx>, is_index: bool, },
|
InteriorOfSliceOrArray { ty: ty::Ty<'tcx>, is_index: bool, },
|
||||||
InteriorOfArray { elem_ty: ty::Ty<'tcx>, is_index: bool, },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -8,9 +8,14 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
// revisions: ast mir
|
||||||
|
//[mir]compile-flags: -Zborrowck-mir
|
||||||
|
|
||||||
struct NonCopy;
|
struct NonCopy;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let array = [NonCopy; 1];
|
let array = [NonCopy; 1];
|
||||||
let _value = array[0]; //~ ERROR E0508
|
let _value = array[0]; //[ast]~ ERROR E0508
|
||||||
|
//[mir]~^ ERROR (Ast) [E0508]
|
||||||
|
//[mir]~| ERROR (Mir) [E0508]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue