]> git.lizzy.rs Git - rust.git/commitdiff
Fixes for shallow borrows
authorMatthew Jasper <mjjasper1@gmail.com>
Sun, 31 Mar 2019 14:14:50 +0000 (15:14 +0100)
committerMatthew Jasper <mjjasper1@gmail.com>
Sun, 31 Mar 2019 14:14:50 +0000 (15:14 +0100)
* Don't promote these borrows if we're going to remove them before
  codegen
* Correctly mark unreachable code

src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/transform/qualify_consts.rs
src/test/mir-opt/match_false_edges.rs

index 95701204cab6d6205020b73ca66acced86dbf4c9..a94350f9cde005d1d808b8441862e13514682538 100644 (file)
@@ -511,14 +511,10 @@ pub(super) fn report_conflicting_borrow(
                 )
             }
 
-            (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!(),
         };
index 0b9ad85e6b1c7c3585744e6e29ea0e84535926a0..4400717fabc53a7d85e4ff17167226360f270741 100644 (file)
@@ -728,7 +728,10 @@ fn assign(&mut self, dest: &Place<'tcx>, source: ValueSource<'_, 'tcx>, location
                                    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.
index 0cbf048697aac3bbf792a9003c752747ebfd81ec..7ac36a22274f33897dfe8e2a827b7c97f373a010 100644 (file)
@@ -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];
 //  }