Skip to content

Commit 5e8eecc

Browse files
committed
io: use stabilized wrapping_add_signed
1 parent ce36a29 commit 5e8eecc

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

hl/src/io.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ pub enum SeekFrom {
1818
Current(i16),
1919
}
2020

21-
// TODO: use wrapping_add_signed when stabilized
22-
// https://github.com/rust-lang/rust/issues/87840
23-
// https://github.com/rust-lang/rust/blob/21b0325c68421b00c6c91055ac330bd5ffe1ea6b/library/core/src/num/uint_macros.rs#L1205
24-
fn wrapping_add_signed(ptr: u16, offset: i16) -> u16 {
25-
ptr.wrapping_add(offset as u16)
26-
}
27-
2821
impl SeekFrom {
2922
/// Calculate the next value of `ptr` for the given seek method.
3023
#[doc(hidden)]
@@ -41,7 +34,7 @@ impl SeekFrom {
4134
if offset > 0 || offset.unsigned_abs() > tail.wrapping_sub(head) {
4235
Err(Error::UnexpectedEof)
4336
} else {
44-
Ok(wrapping_add_signed(tail, offset))
37+
Ok(tail.wrapping_add_signed(offset))
4538
}
4639
}
4740
SeekFrom::Current(offset) => {
@@ -52,7 +45,7 @@ impl SeekFrom {
5245
{
5346
Err(Error::UnexpectedEof)
5447
} else {
55-
Ok(wrapping_add_signed(ptr, offset))
48+
Ok(ptr.wrapping_add_signed(offset))
5649
}
5750
}
5851
}

tls/src/io.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,6 @@ pub struct TlsReader<'buf, 'ptr> {
312312
wrap: usize,
313313
}
314314

315-
// TODO: use wrapping_add_signed when stabilized
316-
// https://github.com/rust-lang/rust/issues/87840
317-
// https://github.com/rust-lang/rust/blob/21b0325c68421b00c6c91055ac330bd5ffe1ea6b/library/core/src/num/uint_macros.rs#L1205
318-
fn wrapping_add_signed(ptr: u16, offset: i16) -> u16 {
319-
ptr.wrapping_add(offset as u16)
320-
}
321-
322315
impl<'buf, 'ptr> Seek for TlsReader<'buf, 'ptr> {
323316
fn seek<Infallible>(&mut self, pos: SeekFrom) -> Result<(), HlError<Infallible>> {
324317
match pos {
@@ -356,7 +349,7 @@ impl<'buf, 'ptr> Seek for TlsReader<'buf, 'ptr> {
356349
if offset < min_val || offset > max_val {
357350
Err(HlError::UnexpectedEof)
358351
} else {
359-
self.inner.ptr = wrapping_add_signed(self.inner.ptr, offset);
352+
self.inner.ptr = self.inner.ptr.wrapping_add_signed(offset);
360353
Ok(())
361354
}
362355
}

0 commit comments

Comments
 (0)