@@ -719,7 +719,7 @@ impl<T, const N: usize> Cell<[T; N]> {
719
719
#[ rustc_diagnostic_item = "RefCell" ]
720
720
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
721
721
pub struct RefCell < T : ?Sized > {
722
- borrow : Cell < BorrowFlag > ,
722
+ borrow : Cell < BorrowCounter > ,
723
723
// Stores the location of the earliest currently active borrow.
724
724
// This gets updated whenever we go from having zero borrows
725
725
// to having a single borrow. When a borrow occurs, this gets included
@@ -792,22 +792,22 @@ fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
792
792
//
793
793
// `Ref` and `RefMut` are both two words in size, and so there will likely never
794
794
// 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.
796
796
// However, this is not a guarantee, as a pathological program could repeatedly
797
797
// create and then mem::forget `Ref`s or `RefMut`s. Thus, all code must
798
798
// explicitly check for overflow and underflow in order to avoid unsafety, or at
799
799
// least behave correctly in the event that overflow or underflow happens (e.g.,
800
800
// see BorrowRef::new).
801
- type BorrowFlag = isize ;
802
- const UNUSED : BorrowFlag = 0 ;
801
+ type BorrowCounter = isize ;
802
+ const UNUSED : BorrowCounter = 0 ;
803
803
804
804
#[ inline( always) ]
805
- fn is_writing ( x : BorrowFlag ) -> bool {
805
+ fn is_writing ( x : BorrowCounter ) -> bool {
806
806
x < UNUSED
807
807
}
808
808
809
809
#[ inline( always) ]
810
- fn is_reading ( x : BorrowFlag ) -> bool {
810
+ fn is_reading ( x : BorrowCounter ) -> bool {
811
811
x > UNUSED
812
812
}
813
813
@@ -1387,12 +1387,12 @@ impl<T> From<T> for RefCell<T> {
1387
1387
impl < T : CoerceUnsized < U > , U > CoerceUnsized < RefCell < U > > for RefCell < T > { }
1388
1388
1389
1389
struct BorrowRef < ' b > {
1390
- borrow : & ' b Cell < BorrowFlag > ,
1390
+ borrow : & ' b Cell < BorrowCounter > ,
1391
1391
}
1392
1392
1393
1393
impl < ' b > BorrowRef < ' b > {
1394
1394
#[ inline]
1395
- fn new ( borrow : & ' b Cell < BorrowFlag > ) -> Option < BorrowRef < ' b > > {
1395
+ fn new ( borrow : & ' b Cell < BorrowCounter > ) -> Option < BorrowRef < ' b > > {
1396
1396
let b = borrow. get ( ) . wrapping_add ( 1 ) ;
1397
1397
if !is_reading ( b) {
1398
1398
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
@@ -1433,7 +1433,7 @@ impl Clone for BorrowRef<'_> {
1433
1433
debug_assert ! ( is_reading( borrow) ) ;
1434
1434
// Prevent the borrow counter from overflowing into
1435
1435
// a writing borrow.
1436
- assert ! ( borrow != BorrowFlag :: MAX ) ;
1436
+ assert ! ( borrow != BorrowCounter :: MAX ) ;
1437
1437
self . borrow . set ( borrow + 1 ) ;
1438
1438
BorrowRef { borrow : self . borrow }
1439
1439
}
@@ -1781,7 +1781,7 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
1781
1781
}
1782
1782
1783
1783
struct BorrowRefMut < ' b > {
1784
- borrow : & ' b Cell < BorrowFlag > ,
1784
+ borrow : & ' b Cell < BorrowCounter > ,
1785
1785
}
1786
1786
1787
1787
impl Drop for BorrowRefMut < ' _ > {
@@ -1795,7 +1795,7 @@ impl Drop for BorrowRefMut<'_> {
1795
1795
1796
1796
impl < ' b > BorrowRefMut < ' b > {
1797
1797
#[ inline]
1798
- fn new ( borrow : & ' b Cell < BorrowFlag > ) -> Option < BorrowRefMut < ' b > > {
1798
+ fn new ( borrow : & ' b Cell < BorrowCounter > ) -> Option < BorrowRefMut < ' b > > {
1799
1799
// NOTE: Unlike BorrowRefMut::clone, new is called to create the initial
1800
1800
// mutable reference, and so there must currently be no existing
1801
1801
// references. Thus, while clone increments the mutable refcount, here
@@ -1819,7 +1819,7 @@ impl<'b> BorrowRefMut<'b> {
1819
1819
let borrow = self . borrow . get ( ) ;
1820
1820
debug_assert ! ( is_writing( borrow) ) ;
1821
1821
// Prevent the borrow counter from underflowing.
1822
- assert ! ( borrow != BorrowFlag :: MIN ) ;
1822
+ assert ! ( borrow != BorrowCounter :: MIN ) ;
1823
1823
self . borrow . set ( borrow - 1 ) ;
1824
1824
BorrowRefMut { borrow : self . borrow }
1825
1825
}
0 commit comments