Skip to content

Commit 25416c7

Browse files
committed
don't track borrows for empty regions
Region inference can create borrows for an empty region if the borrow is dead. In that case, there's no reason to track the borrow, but because there's no such thing as an EndRegion(ReEmpty) these borrows used to live for the entire function. Fixes #46161.
1 parent a6e24fc commit 25416c7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

+6
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
212212
mir::StatementKind::Assign(_, ref rhs) => {
213213
if let mir::Rvalue::Ref(region, _, ref place) = *rhs {
214214
if is_unsafe_place(self.tcx, self.mir, place) { return; }
215+
if let RegionKind::ReEmpty = region {
216+
// If the borrowed value is dead, the region for it
217+
// can be empty. Don't track the borrow in that case.
218+
return
219+
}
220+
215221
let index = self.location_map.get(&location).unwrap_or_else(|| {
216222
panic!("could not find BorrowIndex for location {:?}", location);
217223
});

src/test/run-pass/issue-8860.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z borrowck=compare
1112

1213
static mut DROP: isize = 0;
1314
static mut DROP_S: isize = 0;

0 commit comments

Comments
 (0)