match on elem first

This commit is contained in:
ouz-a 2023-09-12 10:28:37 +03:00
parent 6c03617142
commit 22b1acb455

View File

@ -115,13 +115,21 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
let body = self.builder.body;
let tcx = self.builder.tcx;
let place_ty = place_ref.ty(body, tcx).ty;
match place_ty.kind() {
match elem {
ProjectionElem::Deref => match place_ty.kind() {
ty::Ref(..) | ty::RawPtr(..) => {
return Err(MoveError::cannot_move_out_of(
self.loc,
BorrowedContent { target_place: place_ref.project_deeper(&[elem], tcx) },
BorrowedContent {
target_place: place_ref.project_deeper(&[elem], tcx),
},
));
}
_ => (),
},
ProjectionElem::Field(_, _)
| ProjectionElem::OpaqueCast(_)
| ProjectionElem::Downcast(_, _) => match place_ty.kind() {
ty::Adt(adt, _) if adt.has_dtor(tcx) && !adt.is_box() => {
return Err(MoveError::cannot_move_out_of(
self.loc,
@ -131,6 +139,12 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
ty::Adt(adt, _) if adt.is_union() => {
union_path.get_or_insert(base);
}
_ => (),
},
ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Index(_)
| ProjectionElem::Subslice { .. } => match place_ty.kind() {
ty::Slice(_) => {
return Err(MoveError::cannot_move_out_of(
self.loc,
@ -140,7 +154,6 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
},
));
}
ty::Array(..) => {
if let ProjectionElem::Index(..) = elem {
return Err(MoveError::cannot_move_out_of(
@ -149,10 +162,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
));
}
}
_ => {}
};
_ => (),
},
}
if union_path.is_none() {
// inlined from add_move_path because of a borrowck conflict with the iterator
base =