diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-11-27 18:13:40 +0200 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-12-03 02:29:04 +0200 |
| commit | 25416c70814eb64a8cdd709af7aba1833832bebf (patch) | |
| tree | 1849dfba5d7129492e99f22510c57e8ab133dbb8 | |
| parent | a6e24fc31f4b4bb803e10a39902107f86916133a (diff) | |
| download | rust-25416c70814eb64a8cdd709af7aba1833832bebf.tar.gz rust-25416c70814eb64a8cdd709af7aba1833832bebf.zip | |
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.
| -rw-r--r-- | src/librustc_mir/dataflow/impls/borrows.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/issue-8860.rs | 1 |
2 files changed, 7 insertions, 0 deletions
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; |
