Skip to content

Commit 6148ec9

Browse files
authored
Rollup merge of #142620 - a1phyr:borrowed_buf_remove_branch, r=jhpratt
Remove a panicking branch in `BorrowedCursor::advance`
2 parents a47b364 + e3c21dd commit 6148ec9

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)