about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-20 18:15:33 +0100
committerFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-20 18:15:33 +0100
commita0e1d509aba0ec14f6e95e1bf720563784ae6771 (patch)
tree1f331215b5708c180fbec1c842c54af1e893d893
parentb39c4bc12358078f77ddd01288b24252f757f37d (diff)
downloadrust-a0e1d509aba0ec14f6e95e1bf720563784ae6771.tar.gz
rust-a0e1d509aba0ec14f6e95e1bf720563784ae6771.zip
Ensure separate activations only occur for assignments to locals, not projections.
Fix #46746.
-rw-r--r--src/librustc_mir/dataflow/impls/borrows.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs
index c61a57cdda0..a240e869c63 100644
--- a/src/librustc_mir/dataflow/impls/borrows.rs
+++ b/src/librustc_mir/dataflow/impls/borrows.rs
@@ -361,7 +361,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
                 }
             }
 
-            mir::StatementKind::Assign(_, ref rhs) => {
+            mir::StatementKind::Assign(ref lhs, ref rhs) => {
                 // NOTE: if/when the Assign case is revised to inspect
                 // the assigned_place here, make sure to also
                 // re-consider the current implementations of the
@@ -382,6 +382,22 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
                         panic!("could not find BorrowIndexs for region {:?}", region);
                     }).contains(&index));
                     sets.gen(&ReserveOrActivateIndex::reserved(*index));
+
+                    if is_activations {
+                        // Issue #46746: Two-phase borrows handles
+                        // stmts of form `Tmp = &mut Borrow` ...
+                        match lhs {
+                            Place::Local(..) => {} // okay
+                            Place::Static(..) => unreachable!(), // (filtered by is_unsafe_place)
+                            Place::Projection(..) => {
+                                // ... can assign into projections,
+                                // e.g. `box (&mut _)`. Current
+                                // conservative solution: force
+                                // immediate activation here.
+                                sets.gen(&ReserveOrActivateIndex::active(*index));
+                            }
+                        }
+                    }
                 }
             }