about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-07-04 21:35:38 +0100
committerDavid Wood <david@davidtw.co>2018-07-04 21:35:38 +0100
commitaeb16828945ef7d3cda88d27da96a1b475acd90a (patch)
tree33ad5d5335d127f21a6446eb63b7822f92d539da
parent7eba13f45164f42892b1430badae197ec2a77c5a (diff)
downloadrust-aeb16828945ef7d3cda88d27da96a1b475acd90a.tar.gz
rust-aeb16828945ef7d3cda88d27da96a1b475acd90a.zip
Ensure that borrows wind up unactivated.
-rw-r--r--src/librustc_mir/borrow_check/borrow_set.rs12
-rw-r--r--src/test/run-fail/issue-51345.rs18
2 files changed, 30 insertions, 0 deletions
diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs
index ce02a7dc166..a427b9dd5b7 100644
--- a/src/librustc_mir/borrow_check/borrow_set.rs
+++ b/src/librustc_mir/borrow_check/borrow_set.rs
@@ -237,6 +237,14 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
                             TwoPhaseActivation::NotActivated
                         }
                         _ => {
+                            // Double check: We should have found an activation for every pending
+                            // activation.
+                            assert_eq!(
+                                borrow_data.activation_location,
+                                TwoPhaseActivation::NotActivated,
+                                "never found an activation for this borrow!",
+                            );
+
                             self.activation_map
                                 .entry(location)
                                 .or_insert(Vec::new())
@@ -322,6 +330,10 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
             );
         };
 
+        // Consider the borrow not activated.
+        let borrow_data = &mut self.idx_vec[borrow_index];
+        borrow_data.activation_location = TwoPhaseActivation::NotActivated;
+
         // Insert `temp` into the list of pending activations. From
         // now on, we'll be on the lookout for a use of it. Note that
         // we are guaranteed that this use will come after the
diff --git a/src/test/run-fail/issue-51345.rs b/src/test/run-fail/issue-51345.rs
new file mode 100644
index 00000000000..9efd08195a1
--- /dev/null
+++ b/src/test/run-fail/issue-51345.rs
@@ -0,0 +1,18 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// error-pattern: thread 'main' panicked at 'explicit panic'
+
+#![feature(nll)]
+
+fn main() {
+    let mut vec = vec![];
+    vec.push((vec.len(), panic!()));
+}