summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-03-31 15:14:50 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2019-03-31 15:14:50 +0100
commit16ee042100d252d1c59c80c797a481be340151b3 (patch)
tree12d45a157ac3ae578922877e284e9d8133b79c95
parentcee58fdc12bea8cc373366bd84fc786277729b1c (diff)
downloadrust-shallow-borrow-fixes.tar.gz
Fixes for shallow borrowsshallow-borrow-fixes
* Don't promote these borrows if we're going to remove them before codegen * Correctly mark unreachable code
-rw-r--r--src/librustc_mir/borrow_check/error_reporting.rs8
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs5
-rw-r--r--src/test/mir-opt/match_false_edges.rs4
3 files changed, 8 insertions, 9 deletions
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs
index 95701204cab..a94350f9cde 100644
--- a/src/librustc_mir/borrow_check/error_reporting.rs
+++ b/src/librustc_mir/borrow_check/error_reporting.rs
@@ -511,14 +511,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
)
}
- (BorrowKind::Shallow, _, _, BorrowKind::Unique, _, _)
- | (BorrowKind::Shallow, _, _, BorrowKind::Mut { .. }, _, _) => {
- // Shallow borrows are uses from the user's point of view.
- self.report_use_while_mutably_borrowed(context, (place, span), issued_borrow);
- return;
- }
(BorrowKind::Shared, _, _, BorrowKind::Shared, _, _)
| (BorrowKind::Shared, _, _, BorrowKind::Shallow, _, _)
+ | (BorrowKind::Shallow, _, _, BorrowKind::Mut { .. }, _, _)
+ | (BorrowKind::Shallow, _, _, BorrowKind::Unique, _, _)
| (BorrowKind::Shallow, _, _, BorrowKind::Shared, _, _)
| (BorrowKind::Shallow, _, _, BorrowKind::Shallow, _, _) => unreachable!(),
};
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index 0b9ad85e6b1..4400717fabc 100644
--- a/src/librustc_mir/transform/qualify_consts.rs
+++ b/src/librustc_mir/transform/qualify_consts.rs
@@ -728,7 +728,10 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
interior mutability, create a static instead");
}
}
- } else {
+ } else if let BorrowKind::Mut { .. } | BorrowKind::Shared = kind {
+ // Don't promote BorrowKind::Shallow borrows, as they don't
+ // reach codegen.
+
// We might have a candidate for promotion.
let candidate = Candidate::Ref(location);
// We can only promote interior borrows of promotable temps.
diff --git a/src/test/mir-opt/match_false_edges.rs b/src/test/mir-opt/match_false_edges.rs
index 0cbf048697a..7ac36a22274 100644
--- a/src/test/mir-opt/match_false_edges.rs
+++ b/src/test/mir-opt/match_false_edges.rs
@@ -70,8 +70,8 @@ fn main() {
// }
// bb8: { // binding1 and guard
// StorageLive(_6);
-// _6 = &(((promoted[1]: std::option::Option<i32>) as Some).0: i32);
-// _4 = &shallow (promoted[0]: std::option::Option<i32>);
+// _6 = &(((promoted[0]: std::option::Option<i32>) as Some).0: i32);
+// _4 = &shallow _2;
// StorageLive(_7);
// _7 = const guard() -> [return: bb9, unwind: bb1];
// }