Rollup merge of #64518 - spastorino:while-let-to-iterate-over-proj-slice, r=oli-obk
Use while let slice_pattern instead of carrying an index around r? @oli-obk
This commit is contained in:
commit
1376ccd84d
6 changed files with 24 additions and 16 deletions
|
@ -614,8 +614,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
projection,
|
||||
} = first_borrowed_place;
|
||||
|
||||
for (i, elem) in projection.iter().enumerate().rev() {
|
||||
let proj_base = &projection[..i];
|
||||
let mut cursor = &**projection;
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
match elem {
|
||||
ProjectionElem::Field(field, _) if union_ty(base, proj_base).is_some() => {
|
||||
|
@ -637,8 +638,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
projection,
|
||||
} = second_borrowed_place;
|
||||
|
||||
for (i, elem) in projection.iter().enumerate().rev() {
|
||||
let proj_base = &projection[..i];
|
||||
let mut cursor = &**projection;
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
if let ProjectionElem::Field(field, _) = elem {
|
||||
if let Some(union_ty) = union_ty(base, proj_base) {
|
||||
|
|
|
@ -1758,7 +1758,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
debug!("check_if_assigned_path_is_moved place: {:?}", place);
|
||||
|
||||
// None case => assigning to `x` does not require `x` be initialized.
|
||||
for (i, elem) in place.projection.iter().enumerate().rev() {
|
||||
let mut cursor = &*place.projection;
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
match elem {
|
||||
ProjectionElem::Index(_/*operand*/) |
|
||||
ProjectionElem::ConstantIndex { .. } |
|
||||
|
@ -1771,8 +1774,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
|
||||
// assigning to (*P) requires P to be initialized
|
||||
ProjectionElem::Deref => {
|
||||
let proj_base = &place.projection[..i];
|
||||
|
||||
self.check_if_full_path_is_moved(
|
||||
location, InitializationRequiringAction::Use,
|
||||
(PlaceRef {
|
||||
|
@ -1790,7 +1791,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
ProjectionElem::Field(..) => {
|
||||
let proj_base = &place.projection[..i];
|
||||
// if type of `P` has a dtor, then
|
||||
// assigning to `P.f` requires `P` itself
|
||||
// be already initialized
|
||||
|
|
|
@ -2417,9 +2417,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
"add_reborrow_constraint({:?}, {:?}, {:?})",
|
||||
location, borrow_region, borrowed_place
|
||||
);
|
||||
for (i, elem) in borrowed_place.projection.iter().enumerate().rev() {
|
||||
|
||||
let mut cursor = &*borrowed_place.projection;
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
debug!("add_reborrow_constraint - iteration {:?}", elem);
|
||||
let proj_base = &borrowed_place.projection[..i];
|
||||
|
||||
match elem {
|
||||
ProjectionElem::Deref => {
|
||||
|
|
|
@ -1296,8 +1296,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// Insert a Shallow borrow of the prefixes of any fake borrows.
|
||||
for place in fake_borrows
|
||||
{
|
||||
for (i, elem) in place.projection.iter().enumerate().rev() {
|
||||
let proj_base = &place.projection[..i];
|
||||
let mut cursor = &*place.projection;
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
if let ProjectionElem::Deref = elem {
|
||||
// Insert a shallow borrow after a deref. For other
|
||||
|
|
|
@ -407,8 +407,9 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
|
|||
place: &Place<'tcx>,
|
||||
is_mut_use: bool,
|
||||
) {
|
||||
for (i, elem) in place.projection.iter().enumerate().rev() {
|
||||
let proj_base = &place.projection[..i];
|
||||
let mut cursor = &*place.projection;
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
match elem {
|
||||
ProjectionElem::Field(..) => {
|
||||
|
|
|
@ -38,8 +38,9 @@ fn is_within_packed<'tcx, L>(tcx: TyCtxt<'tcx>, local_decls: &L, place: &Place<'
|
|||
where
|
||||
L: HasLocalDecls<'tcx>,
|
||||
{
|
||||
for (i, elem) in place.projection.iter().enumerate().rev() {
|
||||
let proj_base = &place.projection[..i];
|
||||
let mut cursor = &*place.projection;
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
match elem {
|
||||
// encountered a Deref, which is ABI-aligned
|
||||
|
|
Loading…
Reference in a new issue