diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-04-02 13:47:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-02 13:47:28 +0200 |
| commit | 69bc687f20178076c8fb244cb80d78c2f4c45565 (patch) | |
| tree | 2e27901d184805ef405eaae64977549700542ece /src | |
| parent | 274f80e4d4c7ed62d724b8d35a620f2ef2100721 (diff) | |
| parent | 16ee042100d252d1c59c80c797a481be340151b3 (diff) | |
| download | rust-69bc687f20178076c8fb244cb80d78c2f4c45565.tar.gz rust-69bc687f20178076c8fb244cb80d78c2f4c45565.zip | |
Rollup merge of #59585 - rust-lang:shallow-borrow-fixes, r=pnkfelix
Fixes for shallow borrows * Don't promote these borrows if we're going to remove them before codegen * Correctly mark unreachable code
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/borrow_check/error_reporting.rs | 8 | ||||
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 5 | ||||
| -rw-r--r-- | src/test/mir-opt/match_false_edges.rs | 4 |
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 9bd5fce31f1..e533066e6b9 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]; // } |
