diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-04-10 21:03:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-10 21:03:38 +0200 |
| commit | 78fc931355e9449eae5a1370d3f078f4e780446c (patch) | |
| tree | fee58e64a06033b2b6c30364eb77ff531e32493f /compiler/rustc_mir_transform/src | |
| parent | a52eb325e6248a77c0bf8a1dcc02a1c452d2f6c4 (diff) | |
| parent | 80afd9db2e3871387ecab9c2bdeffc0f970d32d3 (diff) | |
| download | rust-78fc931355e9449eae5a1370d3f078f4e780446c.tar.gz rust-78fc931355e9449eae5a1370d3f078f4e780446c.zip | |
Rollup merge of #95857 - ouz-a:mir-opt, r=oli-obk
Allow multiple derefs to be splitted in deref_separator Previously in #95649 only a single deref within projection was supported and multiple derefs caused a bunch of issues, this PR fixes those issues. ```@oli-obk``` helped a ton again ❤️
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/deref_separator.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/deref_separator.rs b/compiler/rustc_mir_transform/src/deref_separator.rs index 79aac163550..24b626ad966 100644 --- a/compiler/rustc_mir_transform/src/deref_separator.rs +++ b/compiler/rustc_mir_transform/src/deref_separator.rs @@ -11,6 +11,8 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { for (i, stmt) in data.statements.iter_mut().enumerate() { match stmt.kind { StatementKind::Assign(box (og_place, Rvalue::Ref(region, borrow_knd, place))) => { + let mut place_local = place.local; + let mut last_len = 0; for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() { if p_elem == ProjectionElem::Deref && !p_ref.projection.is_empty() { // The type that we are derefing. @@ -23,15 +25,18 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { patch.add_statement(loc, StatementKind::StorageLive(temp)); // We are adding current p_ref's projections to our - // temp value. - let deref_place = - Place::from(p_ref.local).project_deeper(p_ref.projection, tcx); + // temp value, excluding projections we already covered. + let deref_place = Place::from(place_local) + .project_deeper(&p_ref.projection[last_len..], tcx); patch.add_assign( loc, Place::from(temp), Rvalue::Use(Operand::Move(deref_place)), ); + place_local = temp; + last_len = p_ref.projection.len(); + // We are creating a place by using our temp value's location // and copying derefed values which we need to create new statement. let temp_place = @@ -50,11 +55,6 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // Since our job with the temp is done it should be gone let loc = Location { block: block, statement_index: i + 1 }; patch.add_statement(loc, StatementKind::StorageDead(temp)); - - // As all projections are off the base projection, if there are - // multiple derefs in the middle of projection, it might cause - // unsoundness, to not let that happen we break the loop. - break; } } } |
