Skip to content

Commit e3c21dd

Browse files
committed
Remove a panicking branch in BorrowedCursor::advance
1 parent 55d4364 commit e3c21dd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/core/src/io/borrowed_buf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ impl<'a> BorrowedCursor<'a> {
281281
/// Panics if there are less than `n` bytes initialized.
282282
#[inline]
283283
pub fn advance(&mut self, n: usize) -> &mut Self {
284-
let filled = self.buf.filled.strict_add(n);
285-
assert!(filled <= self.buf.init);
284+
// The substraction cannot underflow by invariant of this type.
285+
assert!(n <= self.buf.init - self.buf.filled);
286286

287-
self.buf.filled = filled;
287+
self.buf.filled += n;
288288
self
289289
}
290290

0 commit comments

Comments
 (0)