Skip to content

Commit aeb1682

Browse files
committed
Ensure that borrows wind up unactivated.
1 parent 7eba13f commit aeb1682

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/librustc_mir/borrow_check/borrow_set.rs

+12
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
237237
TwoPhaseActivation::NotActivated
238238
}
239239
_ => {
240+
// Double check: We should have found an activation for every pending
241+
// activation.
242+
assert_eq!(
243+
borrow_data.activation_location,
244+
TwoPhaseActivation::NotActivated,
245+
"never found an activation for this borrow!",
246+
);
247+
240248
self.activation_map
241249
.entry(location)
242250
.or_insert(Vec::new())
@@ -322,6 +330,10 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
322330
);
323331
};
324332

333+
// Consider the borrow not activated.
334+
let borrow_data = &mut self.idx_vec[borrow_index];
335+
borrow_data.activation_location = TwoPhaseActivation::NotActivated;
336+
325337
// Insert `temp` into the list of pending activations. From
326338
// now on, we'll be on the lookout for a use of it. Note that
327339
// we are guaranteed that this use will come after the

src/test/run-fail/issue-51345.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern: thread 'main' panicked at 'explicit panic'
12+
13+
#![feature(nll)]
14+
15+
fn main() {
16+
let mut vec = vec![];
17+
vec.push((vec.len(), panic!()));
18+
}

0 commit comments

Comments
 (0)