]> git.lizzy.rs Git - rust.git/commitdiff
Ensure separate activations only occur for assignments to locals, not projections.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Wed, 20 Dec 2017 17:15:33 +0000 (18:15 +0100)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Wed, 20 Dec 2017 17:15:33 +0000 (18:15 +0100)
Fix #46746.

src/librustc_mir/dataflow/impls/borrows.rs

index c61a57cdda0e91bfbb9964dff95eb38ae25ed8c7..a240e869c631cbe6eae592aff985a75c0e0e8c56 100644 (file)
@@ -361,7 +361,7 @@ fn statement_effect_on_borrows(&self,
                 }
             }
 
-            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 @@ fn statement_effect_on_borrows(&self,
                         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));
+                            }
+                        }
+                    }
                 }
             }