about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTobias Bucher <tobiasbucher5991@gmail.com>2016-05-30 09:53:09 +0200
committerTobias Bucher <tobiasbucher5991@gmail.com>2016-05-30 09:53:09 +0200
commitef60c7cd49d80ef3f1f6a7030d4439024359f37a (patch)
treeed5f8347d02643273305049e61305de91775b364
parentbf9c60c9a6d27762594c1c5c067194f4c9109f67 (diff)
downloadrust-ef60c7cd49d80ef3f1f6a7030d4439024359f37a.tar.gz
rust-ef60c7cd49d80ef3f1f6a7030d4439024359f37a.zip
Prevent the borrow counter from overflowing in `Ref::clone`
Fixes #33880.
-rw-r--r--src/libcore/cell.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 4929088201d..97a85f6aa43 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -618,7 +618,9 @@ impl<'b> Clone for BorrowRef<'b> {
         // Since this Ref exists, we know the borrow flag
         // is not set to WRITING.
         let borrow = self.borrow.get();
-        debug_assert!(borrow != WRITING && borrow != UNUSED);
+        debug_assert!(borrow != UNUSED);
+        // Prevent the borrow counter from overflowing.
+        assert!(borrow != WRITING);
         self.borrow.set(borrow + 1);
         BorrowRef { borrow: self.borrow }
     }