Skip to content

Commit 79d761d

Browse files
committed
remove allow_two_phase_borrow
it's been simplified over the years, but now it's no longer useful. - document its replacement in `BorrowKind` - use that everywhere instead
1 parent ff1aaa5 commit 79d761d

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_mir_dataflow::move_paths::MoveData;
1111
use tracing::debug;
1212

1313
use crate::BorrowIndex;
14-
use crate::path_utils::allow_two_phase_borrow;
1514
use crate::place_ext::PlaceExt;
1615

1716
pub struct BorrowSet<'tcx> {
@@ -350,7 +349,7 @@ impl<'a, 'tcx> GatherBorrows<'a, 'tcx> {
350349
start_location, assigned_place, borrow_index,
351350
);
352351

353-
if !allow_two_phase_borrow(kind) {
352+
if !kind.allows_two_phase_borrow() {
354353
debug!(" -> {:?}", start_location);
355354
return;
356355
}

compiler/rustc_borrowck/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10761076
(Read(kind), BorrowKind::Mut { .. }) => {
10771077
// Reading from mere reservations of mutable-borrows is OK.
10781078
if !is_active(this.dominators(), borrow, location) {
1079-
assert!(allow_two_phase_borrow(borrow.kind));
1079+
assert!(borrow.kind.allows_two_phase_borrow());
10801080
return Control::Continue;
10811081
}
10821082

@@ -1184,7 +1184,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
11841184
}
11851185
BorrowKind::Mut { .. } => {
11861186
let wk = WriteKind::MutableBorrow(bk);
1187-
if allow_two_phase_borrow(bk) {
1187+
if bk.allows_two_phase_borrow() {
11881188
(Deep, Reservation(wk))
11891189
} else {
11901190
(Deep, Write(wk))

compiler/rustc_borrowck/src/path_utils.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
use rustc_abi::FieldIdx;
22
use rustc_data_structures::graph::dominators::Dominators;
3-
use rustc_middle::mir::{BasicBlock, Body, BorrowKind, Location, Place, PlaceRef, ProjectionElem};
3+
use rustc_middle::mir::{BasicBlock, Body, Location, Place, PlaceRef, ProjectionElem};
44
use rustc_middle::ty::TyCtxt;
55
use tracing::debug;
66

77
use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
88
use crate::{AccessDepth, BorrowIndex, places_conflict};
99

10-
/// Returns `true` if the borrow represented by `kind` is
11-
/// allowed to be split into separate Reservation and
12-
/// Activation phases.
13-
pub(super) fn allow_two_phase_borrow(kind: BorrowKind) -> bool {
14-
kind.allows_two_phase_borrow()
15-
}
16-
1710
/// Control for the path borrow checking code
1811
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
1912
pub(super) enum Control {

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
260260
}
261261
BorrowKind::Mut { .. } => {
262262
let wk = WriteKind::MutableBorrow(bk);
263-
if allow_two_phase_borrow(bk) {
263+
if bk.allows_two_phase_borrow() {
264264
(Deep, Reservation(wk))
265265
} else {
266266
(Deep, Write(wk))
@@ -378,7 +378,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
378378
// Reading from mere reservations of mutable-borrows is OK.
379379
if !is_active(this.dominators, borrow, location) {
380380
// If the borrow isn't active yet, reads don't invalidate it
381-
assert!(allow_two_phase_borrow(borrow.kind));
381+
assert!(borrow.kind.allows_two_phase_borrow());
382382
return Control::Continue;
383383
}
384384

compiler/rustc_middle/src/mir/statement.rs

+2
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ impl BorrowKind {
455455
}
456456
}
457457

458+
/// Returns whether borrows represented by this kind are allowed to be split into separate
459+
/// Reservation and Activation phases.
458460
pub fn allows_two_phase_borrow(&self) -> bool {
459461
match *self {
460462
BorrowKind::Shared

0 commit comments

Comments
 (0)