Skip to content

Commit a6520ec

Browse files
committed
Rewrite place workflow in rustc_mir/dataflow
1 parent 7b65566 commit a6520ec

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/librustc_mir/dataflow/impls/borrowed_locals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ impl<'b, 'c, 'tcx> BorrowedLocalsVisitor<'b, 'c> {
105105
PlaceBase::Local(local) => Some(local),
106106
PlaceBase::Promoted(_) | PlaceBase::Static(..) => None,
107107
};
108-
if !place.elems.is_empty() {
108+
if !place.has_no_projection() {
109109
for elem in place.elems.iter() {
110110
match elem {
111111
ProjectionElem::Deref => local = None,
112-
_ => continue,
112+
_ => {},
113113
}
114114
}
115115
}

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,12 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
221221
mir::StatementKind::Assign(ref lhs, ref rhs) => {
222222
// Make sure there are no remaining borrows for variables
223223
// that are assigned over.
224-
if let PlaceBase::Local(local) = lhs.base {
225-
// FIXME: Handle the case in which we're assigning over
226-
// a projection (`foo.bar`).
227-
self.kill_borrows_on_local(sets, &local);
224+
if lhs.has_no_projection() {
225+
if let PlaceBase::Local(local) = lhs.base {
226+
// FIXME: Handle the case in which we're assigning over
227+
// a projection (`foo.bar`).
228+
self.kill_borrows_on_local(sets, &local);
229+
}
228230
}
229231

230232
// NOTE: if/when the Assign case is revised to inspect
@@ -258,18 +260,12 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
258260

259261
// Issue #46746: Two-phase borrows handles
260262
// stmts of form `Tmp = &mut Borrow` ...
261-
if let Some(_projection) = lhs.projection() {
263+
if !lhs.has_no_projection() {
262264
// ... can assign into projections,
263265
// e.g. `box (&mut _)`. Current
264266
// conservative solution: force
265267
// immediate activation here.
266268
sets.gen(&index);
267-
} else {
268-
match lhs.base {
269-
PlaceBase::Promoted(_)
270-
| PlaceBase::Local(..)
271-
| PlaceBase::Static(..) => {} // okay
272-
}
273269
}
274270
}
275271
}
@@ -288,7 +284,9 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
288284
if let PlaceBase::Local(local) = output.base {
289285
// FIXME: Handle the case in which we're assigning over
290286
// a projection (`foo.bar`).
291-
self.kill_borrows_on_local(sets, &local);
287+
if output.has_no_projection() {
288+
self.kill_borrows_on_local(sets, &local);
289+
}
292290
}
293291
}
294292
}

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
113113
return Err(MoveError::cannot_move_out_of(self.loc, Static)),
114114
};
115115

116-
if !place.elems.is_empty() {
116+
if !place.has_no_projection() {
117117
let mir = self.builder.mir;
118118
let tcx = self.builder.tcx;
119119
let mut result_ty = place.base.ty(mir);

src/librustc_mir/dataflow/move_paths/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl<'tcx> MovePathLookup<'tcx> {
255255
PlaceBase::Promoted(_) |
256256
PlaceBase::Static(..) => LookupResult::Parent(None),
257257
};
258-
if !place.elems.is_empty() {
258+
if !place.has_no_projection() {
259259
for elem in place.elems.iter() {
260260
result = match result {
261261
LookupResult::Exact(base_path) => {

0 commit comments

Comments
 (0)