Skip to content

Commit 92e4c39

Browse files
committed
Rename BorrowFlag type to BorrowCounter
It's actually used as a counter so update the name to reflect that.
1 parent 98e5674 commit 92e4c39

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

library/core/src/cell.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl<T, const N: usize> Cell<[T; N]> {
719719
#[rustc_diagnostic_item = "RefCell"]
720720
#[stable(feature = "rust1", since = "1.0.0")]
721721
pub struct RefCell<T: ?Sized> {
722-
borrow: Cell<BorrowFlag>,
722+
borrow: Cell<BorrowCounter>,
723723
// Stores the location of the earliest currently active borrow.
724724
// This gets updated whenever we go from having zero borrows
725725
// to having a single borrow. When a borrow occurs, this gets included
@@ -792,22 +792,22 @@ fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
792792
//
793793
// `Ref` and `RefMut` are both two words in size, and so there will likely never
794794
// be enough `Ref`s or `RefMut`s in existence to overflow half of the `usize`
795-
// range. Thus, a `BorrowFlag` will probably never overflow or underflow.
795+
// range. Thus, a `BorrowCounter` will probably never overflow or underflow.
796796
// However, this is not a guarantee, as a pathological program could repeatedly
797797
// create and then mem::forget `Ref`s or `RefMut`s. Thus, all code must
798798
// explicitly check for overflow and underflow in order to avoid unsafety, or at
799799
// least behave correctly in the event that overflow or underflow happens (e.g.,
800800
// see BorrowRef::new).
801-
type BorrowFlag = isize;
802-
const UNUSED: BorrowFlag = 0;
801+
type BorrowCounter = isize;
802+
const UNUSED: BorrowCounter = 0;
803803

804804
#[inline(always)]
805-
fn is_writing(x: BorrowFlag) -> bool {
805+
fn is_writing(x: BorrowCounter) -> bool {
806806
x < UNUSED
807807
}
808808

809809
#[inline(always)]
810-
fn is_reading(x: BorrowFlag) -> bool {
810+
fn is_reading(x: BorrowCounter) -> bool {
811811
x > UNUSED
812812
}
813813

@@ -1387,12 +1387,12 @@ impl<T> From<T> for RefCell<T> {
13871387
impl<T: CoerceUnsized<U>, U> CoerceUnsized<RefCell<U>> for RefCell<T> {}
13881388

13891389
struct BorrowRef<'b> {
1390-
borrow: &'b Cell<BorrowFlag>,
1390+
borrow: &'b Cell<BorrowCounter>,
13911391
}
13921392

13931393
impl<'b> BorrowRef<'b> {
13941394
#[inline]
1395-
fn new(borrow: &'b Cell<BorrowFlag>) -> Option<BorrowRef<'b>> {
1395+
fn new(borrow: &'b Cell<BorrowCounter>) -> Option<BorrowRef<'b>> {
13961396
let b = borrow.get().wrapping_add(1);
13971397
if !is_reading(b) {
13981398
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
@@ -1433,7 +1433,7 @@ impl Clone for BorrowRef<'_> {
14331433
debug_assert!(is_reading(borrow));
14341434
// Prevent the borrow counter from overflowing into
14351435
// a writing borrow.
1436-
assert!(borrow != BorrowFlag::MAX);
1436+
assert!(borrow != BorrowCounter::MAX);
14371437
self.borrow.set(borrow + 1);
14381438
BorrowRef { borrow: self.borrow }
14391439
}
@@ -1781,7 +1781,7 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
17811781
}
17821782

17831783
struct BorrowRefMut<'b> {
1784-
borrow: &'b Cell<BorrowFlag>,
1784+
borrow: &'b Cell<BorrowCounter>,
17851785
}
17861786

17871787
impl Drop for BorrowRefMut<'_> {
@@ -1795,7 +1795,7 @@ impl Drop for BorrowRefMut<'_> {
17951795

17961796
impl<'b> BorrowRefMut<'b> {
17971797
#[inline]
1798-
fn new(borrow: &'b Cell<BorrowFlag>) -> Option<BorrowRefMut<'b>> {
1798+
fn new(borrow: &'b Cell<BorrowCounter>) -> Option<BorrowRefMut<'b>> {
17991799
// NOTE: Unlike BorrowRefMut::clone, new is called to create the initial
18001800
// mutable reference, and so there must currently be no existing
18011801
// references. Thus, while clone increments the mutable refcount, here
@@ -1819,7 +1819,7 @@ impl<'b> BorrowRefMut<'b> {
18191819
let borrow = self.borrow.get();
18201820
debug_assert!(is_writing(borrow));
18211821
// Prevent the borrow counter from underflowing.
1822-
assert!(borrow != BorrowFlag::MIN);
1822+
assert!(borrow != BorrowCounter::MIN);
18231823
self.borrow.set(borrow - 1);
18241824
BorrowRefMut { borrow: self.borrow }
18251825
}

0 commit comments

Comments
 (0)