From 25416c70814eb64a8cdd709af7aba1833832bebf Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Mon, 27 Nov 2017 18:13:40 +0200 Subject: [PATCH] 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. --- src/librustc_mir/dataflow/impls/borrows.rs | 6 ++++++ src/test/run-pass/issue-8860.rs | 1 + 2 files changed, 7 insertions(+) diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index c87e91b5e63..19ab45dda95 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -212,6 +212,12 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> { mir::StatementKind::Assign(_, ref rhs) => { if let mir::Rvalue::Ref(region, _, ref place) = *rhs { if is_unsafe_place(self.tcx, self.mir, place) { return; } + if let RegionKind::ReEmpty = region { + // If the borrowed value is dead, the region for it + // can be empty. Don't track the borrow in that case. + return + } + let index = self.location_map.get(&location).unwrap_or_else(|| { panic!("could not find BorrowIndex for location {:?}", location); }); diff --git a/src/test/run-pass/issue-8860.rs b/src/test/run-pass/issue-8860.rs index ff562aac161..127f9e355c7 100644 --- a/src/test/run-pass/issue-8860.rs +++ b/src/test/run-pass/issue-8860.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: -Z borrowck=compare static mut DROP: isize = 0; static mut DROP_S: isize = 0;