Skip to content

Commit 69bc687

Browse files
authored
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
2 parents 274f80e + 16ee042 commit 69bc687

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
511511
)
512512
}
513513

514-
(BorrowKind::Shallow, _, _, BorrowKind::Unique, _, _)
515-
| (BorrowKind::Shallow, _, _, BorrowKind::Mut { .. }, _, _) => {
516-
// Shallow borrows are uses from the user's point of view.
517-
self.report_use_while_mutably_borrowed(context, (place, span), issued_borrow);
518-
return;
519-
}
520514
(BorrowKind::Shared, _, _, BorrowKind::Shared, _, _)
521515
| (BorrowKind::Shared, _, _, BorrowKind::Shallow, _, _)
516+
| (BorrowKind::Shallow, _, _, BorrowKind::Mut { .. }, _, _)
517+
| (BorrowKind::Shallow, _, _, BorrowKind::Unique, _, _)
522518
| (BorrowKind::Shallow, _, _, BorrowKind::Shared, _, _)
523519
| (BorrowKind::Shallow, _, _, BorrowKind::Shallow, _, _) => unreachable!(),
524520
};

src/librustc_mir/transform/qualify_consts.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,10 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
728728
interior mutability, create a static instead");
729729
}
730730
}
731-
} else {
731+
} else if let BorrowKind::Mut { .. } | BorrowKind::Shared = kind {
732+
// Don't promote BorrowKind::Shallow borrows, as they don't
733+
// reach codegen.
734+
732735
// We might have a candidate for promotion.
733736
let candidate = Candidate::Ref(location);
734737
// We can only promote interior borrows of promotable temps.

src/test/mir-opt/match_false_edges.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ fn main() {
7070
// }
7171
// bb8: { // binding1 and guard
7272
// StorageLive(_6);
73-
// _6 = &(((promoted[1]: std::option::Option<i32>) as Some).0: i32);
74-
// _4 = &shallow (promoted[0]: std::option::Option<i32>);
73+
// _6 = &(((promoted[0]: std::option::Option<i32>) as Some).0: i32);
74+
// _4 = &shallow _2;
7575
// StorageLive(_7);
7676
// _7 = const guard() -> [return: bb9, unwind: bb1];
7777
// }

0 commit comments

Comments
 (0)