Skip to content

Commit a64591b

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 175d41b commit a64591b

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
@@ -1073,7 +1073,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10731073
(Read(kind), BorrowKind::Mut { .. }) => {
10741074
// Reading from mere reservations of mutable-borrows is OK.
10751075
if !is_active(this.dominators(), borrow, location) {
1076-
assert!(allow_two_phase_borrow(borrow.kind));
1076+
assert!(borrow.kind.allows_two_phase_borrow());
10771077
return Control::Continue;
10781078
}
10791079

@@ -1181,7 +1181,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
11811181
}
11821182
BorrowKind::Mut { .. } => {
11831183
let wk = WriteKind::MutableBorrow(bk);
1184-
if allow_two_phase_borrow(bk) {
1184+
if bk.allows_two_phase_borrow() {
11851185
(Deep, Reservation(wk))
11861186
} else {
11871187
(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
@@ -261,7 +261,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
261261
}
262262
BorrowKind::Mut { .. } => {
263263
let wk = WriteKind::MutableBorrow(bk);
264-
if allow_two_phase_borrow(bk) {
264+
if bk.allows_two_phase_borrow() {
265265
(Deep, Reservation(wk))
266266
} else {
267267
(Deep, Write(wk))
@@ -379,7 +379,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
379379
// Reading from mere reservations of mutable-borrows is OK.
380380
if !is_active(this.dominators, borrow, location) {
381381
// If the borrow isn't active yet, reads don't invalidate it
382-
assert!(allow_two_phase_borrow(borrow.kind));
382+
assert!(borrow.kind.allows_two_phase_borrow());
383383
return Control::Continue;
384384
}
385385

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)