Auto merge of #33960 - tbu-:pr_ref_clone_overflow, r=Aatch

Prevent the borrow counter from overflowing in `Ref::clone`

Fixes #33880.
This commit is contained in:
bors 2016-05-30 23:09:00 -07:00
commit 298730e703

View File

@ -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 }
}